@react-aria/selection 3.6.0 → 3.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.js CHANGED
@@ -1,9 +1,24 @@
1
+ import { useLongPress, usePress } from "@react-aria/interactions";
1
2
  import { useLocale, useCollator } from "@react-aria/i18n";
2
- import { focusWithoutScrolling, isMac, mergeProps, useEvent } from "@react-aria/utils";
3
+ import { focusWithoutScrolling, mergeProps, useEvent, isAppleDevice, isMac } from "@react-aria/utils";
3
4
  import { focusSafely, getFocusableTreeWalker } from "@react-aria/focus";
4
5
  import { useEffect, useRef, useMemo } from "react";
5
6
  import _babelRuntimeHelpersEsmExtends from "@babel/runtime/helpers/esm/extends";
6
7
 
8
+ function $d9657c365c2f735bcaf048eee8599a4a$export$isNonContiguousSelectionModifier(e) {
9
+ // Ctrl + Arrow Up/Arrow Down has a system wide meaning on macOS, so use Alt instead.
10
+ // On Windows and Ubuntu, Alt + Space has a system wide meaning.
11
+ return isAppleDevice() ? e.altKey : e.ctrlKey;
12
+ }
13
+
14
+ function $d9657c365c2f735bcaf048eee8599a4a$export$isCtrlKeyPressed(e) {
15
+ if (isMac()) {
16
+ return e.metaKey;
17
+ }
18
+
19
+ return e.ctrlKey;
20
+ }
21
+
7
22
  /**
8
23
  * Handles typeahead interactions with collections.
9
24
  */
@@ -81,14 +96,6 @@ function $c78d7fa5f7d5832f9b4f97b33a679865$var$getStringForKey(key) {
81
96
  return '';
82
97
  }
83
98
 
84
- function $a9b9aa71af07c56ab1d89ca45381f4b$var$isCtrlKeyPressed(e) {
85
- if (isMac()) {
86
- return e.metaKey;
87
- }
88
-
89
- return e.ctrlKey;
90
- }
91
-
92
99
  /**
93
100
  * Handles interactions with selectable collections.
94
101
  */
@@ -101,7 +108,7 @@ export function useSelectableCollection(options) {
101
108
  shouldFocusWrap = false,
102
109
  disallowEmptySelection = false,
103
110
  disallowSelectAll = false,
104
- selectOnFocus = false,
111
+ selectOnFocus = manager.selectionBehavior === 'replace',
105
112
  disallowTypeAhead = false,
106
113
  shouldUseVirtualFocus,
107
114
  allowsTabNavigation = false,
@@ -117,12 +124,11 @@ export function useSelectableCollection(options) {
117
124
  // Prevent option + tab from doing anything since it doesn't move focus to the cells, only buttons/checkboxes
118
125
  if (e.altKey && e.key === 'Tab') {
119
126
  e.preventDefault();
120
- } // Let child element (e.g. menu button) handle the event if the Alt key is pressed.
121
- // Keyboard events bubble through portals. Don't handle keyboard events
127
+ } // Keyboard events bubble through portals. Don't handle keyboard events
122
128
  // for elements outside the collection (e.g. menus).
123
129
 
124
130
 
125
- if (e.altKey || !ref.current.contains(e.target)) {
131
+ if (!ref.current.contains(e.target)) {
126
132
  return;
127
133
  }
128
134
 
@@ -132,7 +138,7 @@ export function useSelectableCollection(options) {
132
138
 
133
139
  if (e.shiftKey && manager.selectionMode === 'multiple') {
134
140
  manager.extendSelection(key);
135
- } else if (selectOnFocus) {
141
+ } else if (selectOnFocus && !$d9657c365c2f735bcaf048eee8599a4a$export$isNonContiguousSelectionModifier(e)) {
136
142
  manager.replaceSelection(key);
137
143
  }
138
144
  }
@@ -196,10 +202,10 @@ export function useSelectableCollection(options) {
196
202
  case 'Home':
197
203
  if (delegate.getFirstKey) {
198
204
  e.preventDefault();
199
- let firstKey = delegate.getFirstKey(manager.focusedKey, $a9b9aa71af07c56ab1d89ca45381f4b$var$isCtrlKeyPressed(e));
205
+ let firstKey = delegate.getFirstKey(manager.focusedKey, $d9657c365c2f735bcaf048eee8599a4a$export$isCtrlKeyPressed(e));
200
206
  manager.setFocusedKey(firstKey);
201
207
 
202
- if ($a9b9aa71af07c56ab1d89ca45381f4b$var$isCtrlKeyPressed(e) && e.shiftKey && manager.selectionMode === 'multiple') {
208
+ if ($d9657c365c2f735bcaf048eee8599a4a$export$isCtrlKeyPressed(e) && e.shiftKey && manager.selectionMode === 'multiple') {
203
209
  manager.extendSelection(firstKey);
204
210
  } else if (selectOnFocus) {
205
211
  manager.replaceSelection(firstKey);
@@ -211,10 +217,10 @@ export function useSelectableCollection(options) {
211
217
  case 'End':
212
218
  if (delegate.getLastKey) {
213
219
  e.preventDefault();
214
- let lastKey = delegate.getLastKey(manager.focusedKey, $a9b9aa71af07c56ab1d89ca45381f4b$var$isCtrlKeyPressed(e));
220
+ let lastKey = delegate.getLastKey(manager.focusedKey, $d9657c365c2f735bcaf048eee8599a4a$export$isCtrlKeyPressed(e));
215
221
  manager.setFocusedKey(lastKey);
216
222
 
217
- if ($a9b9aa71af07c56ab1d89ca45381f4b$var$isCtrlKeyPressed(e) && e.shiftKey && manager.selectionMode === 'multiple') {
223
+ if ($d9657c365c2f735bcaf048eee8599a4a$export$isCtrlKeyPressed(e) && e.shiftKey && manager.selectionMode === 'multiple') {
218
224
  manager.extendSelection(lastKey);
219
225
  } else if (selectOnFocus) {
220
226
  manager.replaceSelection(lastKey);
@@ -242,7 +248,7 @@ export function useSelectableCollection(options) {
242
248
  break;
243
249
 
244
250
  case 'a':
245
- if ($a9b9aa71af07c56ab1d89ca45381f4b$var$isCtrlKeyPressed(e) && manager.selectionMode === 'multiple' && disallowSelectAll !== true) {
251
+ if ($d9657c365c2f735bcaf048eee8599a4a$export$isCtrlKeyPressed(e) && manager.selectionMode === 'multiple' && disallowSelectAll !== true) {
246
252
  e.preventDefault();
247
253
  manager.selectAll();
248
254
  }
@@ -325,19 +331,29 @@ export function useSelectableCollection(options) {
325
331
  manager.setFocused(true);
326
332
 
327
333
  if (manager.focusedKey == null) {
328
- // If the user hasn't yet interacted with the collection, there will be no focusedKey set.
334
+ let navigateToFirstKey = key => {
335
+ if (key != null) {
336
+ manager.setFocusedKey(key);
337
+
338
+ if (selectOnFocus) {
339
+ manager.replaceSelection(key);
340
+ }
341
+ }
342
+ }; // If the user hasn't yet interacted with the collection, there will be no focusedKey set.
329
343
  // Attempt to detect whether the user is tabbing forward or backward into the collection
330
344
  // and either focus the first or last item accordingly.
345
+
346
+
331
347
  let relatedTarget = e.relatedTarget;
332
348
 
333
349
  if (relatedTarget && e.currentTarget.compareDocumentPosition(relatedTarget) & Node.DOCUMENT_POSITION_FOLLOWING) {
334
350
  var _manager$lastSelected;
335
351
 
336
- manager.setFocusedKey((_manager$lastSelected = manager.lastSelectedKey) != null ? _manager$lastSelected : delegate.getLastKey());
352
+ navigateToFirstKey((_manager$lastSelected = manager.lastSelectedKey) != null ? _manager$lastSelected : delegate.getLastKey());
337
353
  } else {
338
354
  var _manager$firstSelecte;
339
355
 
340
- manager.setFocusedKey((_manager$firstSelecte = manager.firstSelectedKey) != null ? _manager$firstSelecte : delegate.getFirstKey());
356
+ navigateToFirstKey((_manager$firstSelecte = manager.firstSelectedKey) != null ? _manager$firstSelecte : delegate.getFirstKey());
341
357
  }
342
358
  } else if (!isVirtualized) {
343
359
  // Restore the scroll position to what it was before.
@@ -515,10 +531,35 @@ export function useSelectableItem(options) {
515
531
  shouldSelectOnPressUp,
516
532
  isVirtualized,
517
533
  shouldUseVirtualFocus,
518
- focus
534
+ focus,
535
+ isDisabled,
536
+ onAction
519
537
  } = options;
520
538
 
521
- let onSelect = e => manager.select(key, e); // Focus the associated DOM node when this item becomes the focusedKey
539
+ let onSelect = e => {
540
+ if (e.pointerType === 'keyboard' && $d9657c365c2f735bcaf048eee8599a4a$export$isNonContiguousSelectionModifier(e)) {
541
+ manager.toggleSelection(key);
542
+ } else {
543
+ if (manager.selectionMode === 'none') {
544
+ return;
545
+ }
546
+
547
+ if (manager.selectionMode === 'single') {
548
+ if (manager.isSelected(key) && !manager.disallowEmptySelection) {
549
+ manager.toggleSelection(key);
550
+ } else {
551
+ manager.replaceSelection(key);
552
+ }
553
+ } else if (e && e.shiftKey) {
554
+ manager.extendSelection(key);
555
+ } else if (manager.selectionBehavior === 'toggle' || e && ($d9657c365c2f735bcaf048eee8599a4a$export$isCtrlKeyPressed(e) || e.pointerType === 'touch' || e.pointerType === 'virtual')) {
556
+ // 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
557
+ manager.toggleSelection(key);
558
+ } else {
559
+ manager.replaceSelection(key);
560
+ }
561
+ }
562
+ }; // Focus the associated DOM node when this item becomes the focusedKey
522
563
 
523
564
 
524
565
  let isFocused = key === manager.focusedKey;
@@ -547,7 +588,12 @@ export function useSelectableItem(options) {
547
588
  }
548
589
 
549
590
  };
550
- } // By default, selection occurs on pointer down. This can be strange if selecting an
591
+ }
592
+
593
+ let modality = useRef(null);
594
+ let hasPrimaryAction = onAction && manager.selectionMode === 'none';
595
+ let hasSecondaryAction = onAction && manager.selectionMode !== 'none' && manager.selectionBehavior === 'replace';
596
+ let allowsSelection = !isDisabled && manager.canSelectItem(key); // By default, selection occurs on pointer down. This can be strange if selecting an
551
597
  // item causes the UI to disappear immediately (e.g. menus).
552
598
  // If shouldSelectOnPressUp is true, we use onPressUp instead of onPressStart.
553
599
  // onPress requires a pointer down event on the same element as pointer up. For menus,
@@ -555,30 +601,43 @@ export function useSelectableItem(options) {
555
601
  // the pointer up on the menu item rather than requiring a separate press.
556
602
  // For keyboard events, selection still occurs on key down.
557
603
 
604
+ let itemPressProps = {};
558
605
 
559
606
  if (shouldSelectOnPressUp) {
560
- itemProps.onPressStart = e => {
607
+ itemPressProps.onPressStart = e => {
608
+ modality.current = e.pointerType;
609
+
561
610
  if (e.pointerType === 'keyboard') {
562
611
  onSelect(e);
563
612
  }
564
613
  };
565
614
 
566
- itemProps.onPressUp = e => {
615
+ itemPressProps.onPressUp = e => {
567
616
  if (e.pointerType !== 'keyboard') {
568
617
  onSelect(e);
569
618
  }
570
619
  };
620
+
621
+ itemPressProps.onPress = hasPrimaryAction ? () => onAction() : null;
571
622
  } else {
572
623
  // On touch, it feels strange to select on touch down, so we special case this.
573
- itemProps.onPressStart = e => {
574
- if (e.pointerType !== 'touch') {
624
+ itemPressProps.onPressStart = e => {
625
+ modality.current = e.pointerType;
626
+
627
+ if (e.pointerType !== 'touch' && e.pointerType !== 'virtual') {
575
628
  onSelect(e);
576
629
  }
577
630
  };
578
631
 
579
- itemProps.onPress = e => {
580
- if (e.pointerType === 'touch') {
581
- onSelect(e);
632
+ itemPressProps.onPress = e => {
633
+ if (e.pointerType === 'touch' || e.pointerType === 'virtual' || hasPrimaryAction) {
634
+ // Single tap on touch with selectionBehavior = 'replace' performs an action, i.e. navigation.
635
+ // Also perform action on press up when selectionMode = 'none'.
636
+ if (hasPrimaryAction || hasSecondaryAction) {
637
+ onAction();
638
+ } else {
639
+ onSelect(e);
640
+ }
582
641
  }
583
642
  };
584
643
  }
@@ -587,8 +646,48 @@ export function useSelectableItem(options) {
587
646
  itemProps['data-key'] = key;
588
647
  }
589
648
 
649
+ itemPressProps.preventFocusOnPress = shouldUseVirtualFocus;
650
+ let {
651
+ pressProps,
652
+ isPressed
653
+ } = usePress(itemPressProps); // Double clicking with a mouse with selectionBehavior = 'replace' performs an action.
654
+
655
+ let onDoubleClick = hasSecondaryAction ? e => {
656
+ if (modality.current === 'mouse') {
657
+ e.stopPropagation();
658
+ e.preventDefault();
659
+ onAction();
660
+ }
661
+ } : undefined; // Long pressing an item with touch when selectionBehavior = 'replace' switches the selection behavior
662
+ // to 'toggle'. This changes the single tap behavior from performing an action (i.e. navigating) to
663
+ // selecting, and may toggle the appearance of a UI affordance like checkboxes on each item.
664
+ // TODO: what about when drag and drop is also enabled??
665
+
666
+ let {
667
+ longPressProps
668
+ } = useLongPress({
669
+ isDisabled: !hasSecondaryAction,
670
+
671
+ onLongPress(e) {
672
+ if (e.pointerType === 'touch') {
673
+ onSelect(e);
674
+ manager.setSelectionBehavior('toggle');
675
+ }
676
+ }
677
+
678
+ }); // Pressing the Enter key with selectionBehavior = 'replace' performs an action (i.e. navigation).
679
+
680
+ let onKeyUp = hasSecondaryAction ? e => {
681
+ if (e.key === 'Enter') {
682
+ onAction();
683
+ }
684
+ } : undefined;
590
685
  return {
591
- itemProps
686
+ itemProps: mergeProps(itemProps, allowsSelection || hasPrimaryAction ? pressProps : {}, hasSecondaryAction ? longPressProps : {}, {
687
+ onK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AAxB,CAAxB;AAeA,SAAO;AACLsI,IAAAA,SAAS,EAAE1D;AADN,GAAP;AAGD","sources":["./packages/@react-aria/selection/src/useTypeSelect.ts","./packages/@react-aria/selection/src/useSelectableCollection.ts","./packages/@react-aria/selection/src/useSelectableItem.ts","./packages/@react-aria/selection/src/ListKeyboardDelegate.ts","./packages/@react-aria/selection/src/useSelectableList.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {HTMLAttributes, Key, KeyboardEvent, useRef} from 'react';\nimport {KeyboardDelegate} from '@react-types/shared';\nimport {MultipleSelectionManager} from '@react-stately/selection';\n\ninterface TypeSelectOptions {\n /**\n * A delegate that returns collection item keys with respect to visual layout.\n */\n keyboardDelegate: KeyboardDelegate,\n /**\n * An interface for reading and updating multiple selection state.\n */\n selectionManager: MultipleSelectionManager,\n /**\n * Called when an item is focused by typing.\n */\n onTypeSelect?: (key: Key) => void\n}\n\ninterface TypeSelectAria {\n /**\n * Props to be spread on the owner of the options.\n */\n typeSelectProps: HTMLAttributes<HTMLElement>\n}\n\n/**\n * Handles typeahead interactions with collections.\n */\nexport function useTypeSelect(options: TypeSelectOptions): TypeSelectAria {\n let {keyboardDelegate, selectionManager, onTypeSelect} = options;\n let state = useRef({\n search: '',\n timeout: null\n }).current;\n\n let onKeyDown = (e: KeyboardEvent) => {\n let character = getStringForKey(e.key);\n if (!character || e.ctrlKey || e.metaKey) {\n return;\n }\n\n // Do not propagate the Spacebar event if it's meant to be part of the search.\n // When we time out, the search term becomes empty, hence the check on length.\n // Trimming is to account for the case of pressing the Spacebar more than once,\n // which should cycle through the selection/deselection of the focused item.\n if (character === ' ' && state.search.trim().length > 0) {\n e.preventDefault();\n if (!('continuePropagation' in e)) {\n e.stopPropagation();\n }\n }\n\n state.search += character;\n\n // Use the delegate to find a key to focus.\n // Prioritize items after the currently focused item, falling back to searching the whole list.\n let key = keyboardDelegate.getKeyForSearch(state.search, selectionManager.focusedKey);\n\n // If no key found, search from the top.\n if (key == null) {\n key = keyboardDelegate.getKeyForSearch(state.search);\n }\n\n if (key != null) {\n selectionManager.setFocusedKey(key);\n if (onTypeSelect) {\n onTypeSelect(key);\n }\n }\n\n clearTimeout(state.timeout);\n state.timeout = setTimeout(() => {\n state.search = '';\n }, 500);\n };\n\n return {\n typeSelectProps: {\n // Using a capturing listener to catch the keydown event before\n // other hooks in order to handle the Spacebar event.\n onKeyDownCapture: keyboardDelegate.getKeyForSearch ? onKeyDown : null\n }\n };\n}\n\nfunction getStringForKey(key: string) {\n // If the key is of length 1, it is an ASCII value.\n // Otherwise, if there are no ASCII characters in the key name,\n // it is a Unicode character.\n // See https://www.w3.org/TR/uievents-key/\n if (key.length === 1 || !/^[A-Z]/i.test(key)) {\n return key;\n }\n\n return '';\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {FocusEvent, HTMLAttributes, Key, KeyboardEvent, RefObject, useEffect, useRef} from 'react';\nimport {focusSafely, getFocusableTreeWalker} from '@react-aria/focus';\nimport {FocusStrategy, KeyboardDelegate} from '@react-types/shared';\nimport {focusWithoutScrolling, isMac, mergeProps, useEvent} from '@react-aria/utils';\nimport {MultipleSelectionManager} from '@react-stately/selection';\nimport {useLocale} from '@react-aria/i18n';\nimport {useTypeSelect} from './useTypeSelect';\n\nfunction isCtrlKeyPressed(e: KeyboardEvent) {\n if (isMac()) {\n return e.metaKey;\n }\n\n return e.ctrlKey;\n}\n\ninterface SelectableCollectionOptions {\n /**\n * An interface for reading and updating multiple selection state.\n */\n selectionManager: MultipleSelectionManager,\n /**\n * A delegate object that implements behavior for keyboard focus movement.\n */\n keyboardDelegate: KeyboardDelegate,\n /**\n * The ref attached to the element representing the collection.\n */\n ref: RefObject<HTMLElement>,\n /**\n * Whether the collection or one of its items should be automatically focused upon render.\n * @default false\n */\n autoFocus?: boolean | FocusStrategy,\n /**\n * Whether focus should wrap around when the end/start is reached.\n * @default false\n */\n shouldFocusWrap?: boolean,\n /**\n * Whether the collection allows empty selection.\n * @default false\n */\n disallowEmptySelection?: boolean,\n /**\n * Whether the collection allows the user to select all items via keyboard shortcut.\n * @default false\n */\n disallowSelectAll?: boolean,\n /**\n * Whether selection should occur automatically on focus.\n * @default false\n */\n selectOnFocus?: boolean,\n /**\n * Whether typeahead is disabled.\n * @default false\n */\n disallowTypeAhead?: boolean,\n /**\n * Whether the collection items should use virtual focus instead of being focused directly.\n */\n shouldUseVirtualFocus?: boolean,\n /**\n * Whether navigation through tab key is enabled.\n */\n allowsTabNavigation?: boolean,\n /**\n * Whether the collection items are contained in a virtual scroller.\n */\n isVirtualized?: boolean,\n /**\n * The ref attached to the scrollable body. Used to provide automatic scrolling on item focus for non-virtualized collections.\n * If not provided, defaults to the collection ref.\n */\n scrollRef?: RefObject<HTMLElement>\n}\n\ninterface SelectableCollectionAria {\n /** Props for the collection element. */\n collectionProps: HTMLAttributes<HTMLElement>\n}\n\n/**\n * Handles interactions with selectable collections.\n */\nexport function useSelectableCollection(options: SelectableCollectionOptions): SelectableCollectionAria {\n let {\n selectionManager: manager,\n keyboardDelegate: delegate,\n ref,\n autoFocus = false,\n shouldFocusWrap = false,\n disallowEmptySelection = false,\n disallowSelectAll = false,\n selectOnFocus = false,\n disallowTypeAhead = false,\n shouldUseVirtualFocus,\n allowsTabNavigation = false,\n isVirtualized,\n // If no scrollRef is provided, assume the collection ref is the scrollable region\n scrollRef = ref\n } = options;\n let {direction} = useLocale();\n\n let onKeyDown = (e: KeyboardEvent) => {\n // Prevent option + tab from doing anything since it doesn't move focus to the cells, only buttons/checkboxes\n if (e.altKey && e.key === 'Tab') {\n e.preventDefault();\n }\n\n // Let child element (e.g. menu button) handle the event if the Alt key is pressed.\n // Keyboard events bubble through portals. Don't handle keyboard events\n // for elements outside the collection (e.g. menus).\n if (e.altKey || !ref.current.contains(e.target as HTMLElement)) {\n return;\n }\n\n const navigateToKey = (key: Key | undefined, childFocus?: FocusStrategy) => {\n if (key != null) {\n manager.setFocusedKey(key, childFocus);\n\n if (e.shiftKey && manager.selectionMode === 'multiple') {\n manager.extendSelection(key);\n } else if (selectOnFocus) {\n manager.replaceSelection(key);\n }\n }\n };\n\n switch (e.key) {\n case 'ArrowDown': {\n if (delegate.getKeyBelow) {\n e.preventDefault();\n let nextKey = manager.focusedKey != null\n ? delegate.getKeyBelow(manager.focusedKey)\n : delegate.getFirstKey?.();\n if (nextKey == null && shouldFocusWrap) {\n nextKey = delegate.getFirstKey?.(manager.focusedKey);\n }\n navigateToKey(nextKey);\n }\n break;\n }\n case 'ArrowUp': {\n if (delegate.getKeyAbove) {\n e.preventDefault();\n let nextKey = manager.focusedKey != null\n ? delegate.getKeyAbove(manager.focusedKey)\n : delegate.getLastKey?.();\n if (nextKey == null && shouldFocusWrap) {\n nextKey = delegate.getLastKey?.(manager.focusedKey);\n }\n navigateToKey(nextKey);\n }\n break;\n }\n case 'ArrowLeft': {\n if (delegate.getKeyLeftOf) {\n e.preventDefault();\n let nextKey = delegate.getKeyLeftOf(manager.focusedKey);\n navigateToKey(nextKey, direction === 'rtl' ? 'first' : 'last');\n }\n break;\n }\n case 'ArrowRight': {\n if (delegate.getKeyRightOf) {\n e.preventDefault();\n let nextKey = delegate.getKeyRightOf(manager.focusedKey);\n navigateToKey(nextKey, direction === 'rtl' ? 'last' : 'first');\n }\n break;\n }\n case 'Home':\n if (delegate.getFirstKey) {\n e.preventDefault();\n let firstKey = delegate.getFirstKey(manager.focusedKey, isCtrlKeyPressed(e));\n manager.setFocusedKey(firstKey);\n if (isCtrlKeyPressed(e) && e.shiftKey && manager.selectionMode === 'multiple') {\n manager.extendSelection(firstKey);\n } else if (selectOnFocus) {\n manager.replaceSelection(firstKey);\n }\n }\n break;\n case 'End':\n if (delegate.getLastKey) {\n e.preventDefault();\n let lastKey = delegate.getLastKey(manager.focusedKey, isCtrlKeyPressed(e));\n manager.setFocusedKey(lastKey);\n if (isCtrlKeyPressed(e) && e.shiftKey && manager.selectionMode === 'multiple') {\n manager.extendSelection(lastKey);\n } else if (selectOnFocus) {\n manager.replaceSelection(lastKey);\n }\n }\n break;\n case 'PageDown':\n if (delegate.getKeyPageBelow) {\n e.preventDefault();\n let nextKey = delegate.getKeyPageBelow(manager.focusedKey);\n navigateToKey(nextKey);\n }\n break;\n case 'PageUp':\n if (delegate.getKeyPageAbove) {\n e.preventDefault();\n let nextKey = delegate.getKeyPageAbove(manager.focusedKey);\n navigateToKey(nextKey);\n }\n break;\n case 'a':\n if (isCtrlKeyPressed(e) && manager.selectionMode === 'multiple' && disallowSelectAll !== true) {\n e.preventDefault();\n manager.selectAll();\n }\n break;\n case 'Escape':\n e.preventDefault();\n if (!disallowEmptySelection) {\n manager.clearSelection();\n }\n break;\n case 'Tab': {\n if (!allowsTabNavigation) {\n // There may be elements that are \"tabbable\" inside a collection (e.g. in a grid cell).\n // However, collections should be treated as a single tab stop, with arrow key navigation internally.\n // We don't control the rendering of these, so we can't override the tabIndex to prevent tabbing.\n // Instead, we handle the Tab key, and move focus manually to the first/last tabbable element\n // in the collection, so that the browser default behavior will apply starting from that element\n // rather than the currently focused one.\n if (e.shiftKey) {\n ref.current.focus();\n } else {\n let walker = getFocusableTreeWalker(ref.current, {tabbable: true});\n let next: HTMLElement;\n let last: HTMLElement;\n do {\n last = walker.lastChild() as HTMLElement;\n if (last) {\n next = last;\n }\n } while (last);\n\n if (next && !next.contains(document.activeElement)) {\n focusWithoutScrolling(next);\n }\n }\n break;\n }\n }\n }\n };\n\n // Store the scroll position so we can restore it later.\n let scrollPos = useRef({top: 0, left: 0});\n useEvent(scrollRef, 'scroll', isVirtualized ? null : () => {\n scrollPos.current = {\n top: scrollRef.current.scrollTop,\n left: scrollRef.current.scrollLeft\n };\n });\n\n let onFocus = (e: FocusEvent) => {\n if (manager.isFocused) {\n // If a focus event bubbled through a portal, reset focus state.\n if (!e.currentTarget.contains(e.target)) {\n manager.setFocused(false);\n }\n\n return;\n }\n\n // Focus events can bubble through portals. Ignore these events.\n if (!e.currentTarget.contains(e.target)) {\n return;\n }\n\n manager.setFocused(true);\n\n if (manager.focusedKey == null) {\n // If the user hasn't yet interacted with the collection, there will be no focusedKey set.\n // Attempt to detect whether the user is tabbing forward or backward into the collection\n // and either focus the first or last item accordingly.\n let relatedTarget = e.relatedTarget as Element;\n if (relatedTarget && (e.currentTarget.compareDocumentPosition(relatedTarget) & Node.DOCUMENT_POSITION_FOLLOWING)) {\n manager.setFocusedKey(manager.lastSelectedKey ?? delegate.getLastKey());\n } else {\n manager.setFocusedKey(manager.firstSelectedKey ?? delegate.getFirstKey());\n }\n } else if (!isVirtualized) {\n // Restore the scroll position to what it was before.\n scrollRef.current.scrollTop = scrollPos.current.top;\n scrollRef.current.scrollLeft = scrollPos.current.left;\n\n // Refocus and scroll the focused item into view if it exists within the scrollable region.\n let element = scrollRef.current.querySelector(`[data-key=\"${manager.focusedKey}\"]`) as HTMLElement;\n if (element) {\n // This prevents a flash of focus on the first/last element in the collection\n focusWithoutScrolling(element);\n scrollIntoView(scrollRef.current, element);\n }\n }\n };\n\n let onBlur = (e) => {\n // Don't set blurred and then focused again if moving focus within the collection.\n if (!e.currentTarget.contains(e.relatedTarget as HTMLElement)) {\n manager.setFocused(false);\n }\n };\n\n const autoFocusRef = useRef(autoFocus);\n useEffect(() => {\n if (autoFocusRef.current) {\n let focusedKey = null;\n\n // Check focus strategy to determine which item to focus\n if (autoFocus === 'first') {\n focusedKey = delegate.getFirstKey();\n } if (autoFocus === 'last') {\n focusedKey = delegate.getLastKey();\n }\n\n // If there are any selected keys, make the first one the new focus target\n let selectedKeys = manager.selectedKeys;\n if (selectedKeys.size) {\n focusedKey = selectedKeys.values().next().value;\n }\n\n manager.setFocused(true);\n manager.setFocusedKey(focusedKey);\n\n // If no default focus key is selected, focus the collection itself.\n if (focusedKey == null && !shouldUseVirtualFocus) {\n focusSafely(ref.current);\n }\n }\n autoFocusRef.current = false;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n // If not virtualized, scroll the focused element into view when the focusedKey changes.\n // When virtualized, Virtualizer handles this internally.\n useEffect(() => {\n if (!isVirtualized && manager.focusedKey && scrollRef?.current) {\n let element = scrollRef.current.querySelector(`[data-key=\"${manager.focusedKey}\"]`) as HTMLElement;\n if (element) {\n scrollIntoView(scrollRef.current, element);\n }\n }\n }, [isVirtualized, scrollRef, manager.focusedKey]);\n\n let handlers = {\n onKeyDown,\n onFocus,\n onBlur,\n onMouseDown(e) {\n // Ignore events that bubbled through portals.\n if (e.currentTarget.contains(e.target)) {\n // Prevent focus going to the collection when clicking on the scrollbar.\n e.preventDefault();\n }\n }\n };\n\n let {typeSelectProps} = useTypeSelect({\n keyboardDelegate: delegate,\n selectionManager: manager\n });\n\n if (!disallowTypeAhead) {\n handlers = mergeProps(typeSelectProps, handlers);\n }\n\n // If nothing is focused within the collection, make the collection itself tabbable.\n // This will be marshalled to either the first or last item depending on where focus came from.\n // If using virtual focus, don't set a tabIndex at all so that VoiceOver on iOS 14 doesn't try\n // to move real DOM focus to the element anyway.\n let tabIndex: number;\n if (!shouldUseVirtualFocus) {\n tabIndex = manager.focusedKey == null ? 0 : -1;\n }\n\n return {\n collectionProps: {\n ...handlers,\n tabIndex\n }\n };\n}\n\n/**\n * Scrolls `scrollView` so that `element` is visible.\n * Similar to `element.scrollIntoView({block: 'nearest'})` (not supported in Edge),\n * but doesn't affect parents above `scrollView`.\n */\nfunction scrollIntoView(scrollView: HTMLElement, element: HTMLElement) {\n let offsetX = relativeOffset(scrollView, element, 'left');\n let offsetY = relativeOffset(scrollView, element, 'top');\n let width = element.offsetWidth;\n let height = element.offsetHeight;\n let x = scrollView.scrollLeft;\n let y = scrollView.scrollTop;\n let maxX = x + scrollView.offsetWidth;\n let maxY = y + scrollView.offsetHeight;\n\n if (offsetX <= x) {\n x = offsetX;\n } else if (offsetX + width > maxX) {\n x += offsetX + width - maxX;\n }\n if (offsetY <= y) {\n y = offsetY;\n } else if (offsetY + height > maxY) {\n y += offsetY + height - maxY;\n }\n\n scrollView.scrollLeft = x;\n scrollView.scrollTop = y;\n}\n\n/**\n * Computes the offset left or top from child to ancestor by accumulating\n * offsetLeft or offsetTop through intervening offsetParents.\n */\nfunction relativeOffset(ancestor: HTMLElement, child: HTMLElement, axis: 'left'|'top') {\n const prop = axis === 'left' ? 'offsetLeft' : 'offsetTop';\n let sum = 0;\n while (child.offsetParent) {\n sum += child[prop];\n if (child.offsetParent === ancestor) {\n // Stop once we have found the ancestor we are interested in.\n break;\n } else if (child.offsetParent.contains(ancestor)) {\n // If the ancestor is not `position:relative`, then we stop at\n // _its_ offset parent, and we subtract off _its_ offset, so that\n // we end up with the proper offset from child to ancestor.\n sum -= ancestor[prop];\n break;\n }\n child = child.offsetParent as HTMLElement;\n }\n return sum;\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {focusSafely} from '@react-aria/focus';\nimport {HTMLAttributes, Key, RefObject, useEffect} from 'react';\nimport {MultipleSelectionManager} from '@react-stately/selection';\nimport {PressEvent} from '@react-types/shared';\nimport {PressProps} from '@react-aria/interactions';\n\ninterface SelectableItemOptions {\n /**\n * An interface for reading and updating multiple selection state.\n */\n selectionManager: MultipleSelectionManager,\n /**\n * A unique key for the item.\n */\n key: Key,\n /**\n * Ref to the item.\n */\n ref: RefObject<HTMLElement>,\n /**\n * By default, selection occurs on pointer down. This can be strange if selecting an\n * item causes the UI to disappear immediately (e.g. menus).\n */\n shouldSelectOnPressUp?: boolean,\n /**\n * Whether the option is contained in a virtual scroller.\n */\n isVirtualized?: boolean,\n /**\n * Function to focus the item.\n */\n focus?: () => void,\n /**\n * Whether the option should use virtual focus instead of being focused directly.\n */\n shouldUseVirtualFocus?: boolean\n}\n\ninterface SelectableItemAria {\n /**\n * Props to be spread on the item root node.\n */\n itemProps: HTMLAttributes<HTMLElement> & PressProps\n}\n\n/**\n * Handles interactions with an item in a selectable collection.\n */\nexport function useSelectableItem(options: SelectableItemOptions): SelectableItemAria {\n let {\n selectionManager: manager,\n key,\n ref,\n shouldSelectOnPressUp,\n isVirtualized,\n shouldUseVirtualFocus,\n focus\n } = options;\n\n let onSelect = (e: PressEvent | PointerEvent) => manager.select(key, e);\n\n // Focus the associated DOM node when this item becomes the focusedKey\n let isFocused = key === manager.focusedKey;\n useEffect(() => {\n if (isFocused && manager.isFocused && !shouldUseVirtualFocus && document.activeElement !== ref.current) {\n if (focus) {\n focus();\n } else {\n focusSafely(ref.current);\n }\n }\n }, [ref, isFocused, manager.focusedKey, manager.childFocusStrategy, manager.isFocused, shouldUseVirtualFocus]);\n\n // Set tabIndex to 0 if the element is focused, or -1 otherwise so that only the last focused\n // item is tabbable. If using virtual focus, don't set a tabIndex at all so that VoiceOver\n // on iOS 14 doesn't try to move real DOM focus to the item anyway.\n let itemProps: SelectableItemAria['itemProps'] = {};\n if (!shouldUseVirtualFocus) {\n itemProps = {\n tabIndex: isFocused ? 0 : -1,\n onFocus(e) {\n if (e.target === ref.current) {\n manager.setFocusedKey(key);\n }\n }\n };\n }\n\n // By default, selection occurs on pointer down. This can be strange if selecting an\n // item causes the UI to disappear immediately (e.g. menus).\n // If shouldSelectOnPressUp is true, we use onPressUp instead of onPressStart.\n // onPress requires a pointer down event on the same element as pointer up. For menus,\n // we want to be able to have the pointer down on the trigger that opens the menu and\n // the pointer up on the menu item rather than requiring a separate press.\n // For keyboard events, selection still occurs on key down.\n if (shouldSelectOnPressUp) {\n itemProps.onPressStart = (e) => {\n if (e.pointerType === 'keyboard') {\n onSelect(e);\n }\n };\n\n itemProps.onPressUp = (e) => {\n if (e.pointerType !== 'keyboard') {\n onSelect(e);\n }\n };\n } else {\n // On touch, it feels strange to select on touch down, so we special case this.\n itemProps.onPressStart = (e) => {\n if (e.pointerType !== 'touch') {\n onSelect(e);\n }\n };\n\n itemProps.onPress = (e) => {\n if (e.pointerType === 'touch') {\n onSelect(e);\n }\n };\n }\n\n if (!isVirtualized) {\n itemProps['data-key'] = key;\n }\n\n return {\n itemProps\n };\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, KeyboardDelegate, Node} from '@react-types/shared';\nimport {Key, RefObject} from 'react';\n\nexport class ListKeyboardDelegate<T> implements KeyboardDelegate {\n private collection: Collection<Node<T>>;\n private disabledKeys: Set<Key>;\n private ref: RefObject<HTMLElement>;\n private collator: Intl.Collator;\n\n constructor(collection: Collection<Node<T>>, disabledKeys: Set<Key>, ref: RefObject<HTMLElement>, collator?: Intl.Collator) {\n this.collection = collection;\n this.disabledKeys = disabledKeys;\n this.ref = ref;\n this.collator = collator;\n }\n\n getKeyBelow(key: Key) {\n key = this.collection.getKeyAfter(key);\n while (key != null) {\n let item = this.collection.getItem(key);\n if (item.type === 'item' && !this.disabledKeys.has(key)) {\n return key;\n }\n\n key = this.collection.getKeyAfter(key);\n }\n }\n\n getKeyAbove(key: Key) {\n key = this.collection.getKeyBefore(key);\n while (key != null) {\n let item = this.collection.getItem(key);\n if (item.type === 'item' && !this.disabledKeys.has(key)) {\n return key;\n }\n\n key = this.collection.getKeyBefore(key);\n }\n }\n\n getFirstKey() {\n let key = this.collection.getFirstKey();\n while (key != null) {\n let item = this.collection.getItem(key);\n if (item.type === 'item' && !this.disabledKeys.has(key)) {\n return key;\n }\n\n key = this.collection.getKeyAfter(key);\n }\n }\n\n getLastKey() {\n let key = this.collection.getLastKey();\n while (key != null) {\n let item = this.collection.getItem(key);\n if (item.type === 'item' && !this.disabledKeys.has(key)) {\n return key;\n }\n\n key = this.collection.getKeyBefore(key);\n }\n }\n\n private getItem(key: Key): HTMLElement {\n return this.ref.current.querySelector(`[data-key=\"${key}\"]`);\n }\n\n getKeyPageAbove(key: Key) {\n let menu = this.ref.current;\n let item = this.getItem(key);\n if (!item) {\n return null;\n }\n\n let pageY = Math.max(0, item.offsetTop + item.offsetHeight - menu.offsetHeight);\n\n while (item && item.offsetTop > pageY) {\n key = this.getKeyAbove(key);\n item = this.getItem(key);\n }\n\n return key;\n }\n\n getKeyPageBelow(key: Key) {\n let menu = this.ref.current;\n let item = this.getItem(key);\n if (!item) {\n return null;\n }\n\n let pageY = Math.min(menu.scrollHeight, item.offsetTop - item.offsetHeight + menu.offsetHeight);\n\n while (item && item.offsetTop < pageY) {\n key = this.getKeyBelow(key);\n item = this.getItem(key);\n }\n\n return key;\n }\n\n getKeyForSearch(search: string, fromKey?: Key) {\n if (!this.collator) {\n return null;\n }\n\n let collection = this.collection;\n let key = fromKey || this.getFirstKey();\n while (key != null) {\n let item = collection.getItem(key);\n let substring = item.textValue.slice(0, search.length);\n if (item.textValue && this.collator.compare(substring, search) === 0) {\n return key;\n }\n\n key = this.getKeyBelow(key);\n }\n\n return null;\n }\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, FocusStrategy, KeyboardDelegate, Node} from '@react-types/shared';\nimport {HTMLAttributes, Key, RefObject, useMemo} from 'react';\nimport {ListKeyboardDelegate} from './ListKeyboardDelegate';\nimport {MultipleSelectionManager} from '@react-stately/selection';\nimport {useCollator} from '@react-aria/i18n';\nimport {useSelectableCollection} from './useSelectableCollection';\n\ninterface SelectableListOptions {\n /**\n * An interface for reading and updating multiple selection state.\n */\n selectionManager: MultipleSelectionManager,\n /**\n * State of the collection.\n */\n collection: Collection<Node<unknown>>,\n /**\n * The item keys that are disabled. These items cannot be selected, focused, or otherwise interacted with.\n */\n disabledKeys: Set<Key>,\n /**\n * A ref to the item.\n */\n ref?: RefObject<HTMLElement>,\n /**\n * A delegate that returns collection item keys with respect to visual layout.\n */\n keyboardDelegate?: KeyboardDelegate,\n /**\n * Whether the collection or one of its items should be automatically focused upon render.\n * @default false\n */\n autoFocus?: boolean | FocusStrategy,\n /**\n * Whether focus should wrap around when the end/start is reached.\n * @default false\n */\n shouldFocusWrap?: boolean,\n /**\n * Whether the option is contained in a virtual scroller.\n */\n isVirtualized?: boolean,\n /**\n * Whether the collection allows empty selection.\n * @default false\n */\n disallowEmptySelection?: boolean,\n /**\n * Whether selection should occur automatically on focus.\n * @default false\n */\n selectOnFocus?: boolean,\n /**\n * Whether typeahead is disabled.\n * @default false\n */\n disallowTypeAhead?: boolean,\n /**\n * Whether the collection items should use virtual focus instead of being focused directly.\n */\n shouldUseVirtualFocus?: boolean,\n /**\n * Whether navigation through tab key is enabled.\n */\n allowsTabNavigation?: boolean\n}\n\ninterface SelectableListAria {\n /**\n * Props for the option element.\n */\n listProps: HTMLAttributes<HTMLElement>\n}\n\n/**\n * Handles interactions with a selectable list.\n */\nexport function useSelectableList(props: SelectableListOptions): SelectableListAria {\n let {\n selectionManager,\n collection,\n disabledKeys,\n ref,\n keyboardDelegate,\n autoFocus,\n shouldFocusWrap,\n isVirtualized,\n disallowEmptySelection,\n selectOnFocus = false,\n disallowTypeAhead,\n shouldUseVirtualFocus,\n allowsTabNavigation\n } = props;\n\n // By default, a KeyboardDelegate is provided which uses the DOM to query layout information (e.g. for page up/page down).\n // When virtualized, the layout object will be passed in as a prop and override this.\n let collator = useCollator({usage: 'search', sensitivity: 'base'});\n let delegate = useMemo(() => keyboardDelegate || new ListKeyboardDelegate(collection, disabledKeys, ref, collator), [keyboardDelegate, collection, disabledKeys, ref, collator]);\n\n let {collectionProps} = useSelectableCollection({\n ref,\n selectionManager,\n keyboardDelegate: delegate,\n autoFocus,\n shouldFocusWrap,\n disallowEmptySelection,\n selectOnFocus,\n disallowTypeAhead,\n shouldUseVirtualFocus,\n allowsTabNavigation,\n isVirtualized,\n scrollRef: ref\n });\n\n return {\n listProps: collectionProps\n };\n}\n"],"names":["useTypeSelect","options","keyboardDelegate","selectionManager","onTypeSelect","state","useRef","search","timeout","current","onKeyDown","e","character","getStringForKey","key","ctrlKey","metaKey","trim","length","preventDefault","stopPropagation","getKeyForSearch","focusedKey","setFocusedKey","clearTimeout","setTimeout","typeSelectProps","onKeyDownCapture","test","isCtrlKeyPressed","isMac","useSelectableCollection","manager","delegate","ref","autoFocus","shouldFocusWrap","disallowEmptySelection","disallowSelectAll","selectOnFocus","disallowTypeAhead","shouldUseVirtualFocus","allowsTabNavigation","isVirtualized","scrollRef","direction","useLocale","altKey","contains","target","navigateToKey","childFocus","shiftKey","selectionMode","extendSelection","replaceSelection","getKeyBelow","nextKey","getFirstKey","getKeyAbove","getLastKey","getKeyLeftOf","getKeyRightOf","firstKey","lastKey","getKeyPageBelow","getKeyPageAbove","selectAll","clearSelection","focus","walker","getFocusableTreeWalker","tabbable","next","last","lastChild","document","activeElement","focusWithoutScrolling","scrollPos","top","left","useEvent","scrollTop","scrollLeft","onFocus","isFocused","currentTarget","setFocused","relatedTarget","compareDocumentPosition","Node","DOCUMENT_POSITION_FOLLOWING","lastSelectedKey","firstSelectedKey","element","querySelector","scrollIntoView","onBlur","autoFocusRef","useEffect","selectedKeys","size","values","value","focusSafely","handlers","onMouseDown","mergeProps","tabIndex","collectionProps","scrollView","offsetX","relativeOffset","offsetY","width","offsetWidth","height","offsetHeight","x","y","maxX","maxY","ancestor","child","axis","prop","sum","offsetParent","useSelectableItem","shouldSelectOnPressUp","onSelect","select","childFocusStrategy","itemProps","onPressStart","pointerType","onPressUp","onPress","ListKeyboardDelegate","constructor","collection","disabledKeys","collator","getKeyAfter","item","getItem","type","has","getKeyBefore","menu","pageY","Math","max","offsetTop","min","scrollHeight","fromKey","substring","textValue","slice","compare","useSelectableList","props","useCollator","usage","sensitivity","useMemo","listProps"],"version":3,"file":"module.js.map"}
1
+ {"mappings":";;;;;;;AAqBO,SAASA,yEAAT,CAA0CC,CAA1C,EAAoD;AACzD;AACA;AACA,SAAOC,aAAa,KAAKD,CAAC,CAACE,MAAP,GAAgBF,CAAC,CAACG,OAAtC;AACD;;AAEM,SAASC,yDAAT,CAA0BJ,CAA1B,EAAoC;AACzC,MAAIK,KAAK,EAAT,EAAa;AACX,WAAOL,CAAC,CAACM,OAAT;AACD;;AAED,SAAON,CAAC,CAACG,OAAT;AACD;;ACKD;;;OAGO,SAASI,aAAT,CAAuBC,OAAvB,EAAmE;AACxE,MAAI;AAACC,IAAAA,gBAAD;AAAmBC,IAAAA,gBAAnB;AAAqCC,IAA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BAAwB;AAC9C7E,IAAAA,GAD8C;AAE9C1B,IAAAA,gBAF8C;AAG9CD,IAAAA,gBAAgB,EAAE0B,QAH4B;AAI9CE,IAAAA,SAJ8C;AAK9CC,IAAAA,eAL8C;AAM9CC,IAAAA,sBAN8C;AAO9CE,IAAAA,aAP8C;AAQ9CE,IAAAA,iBAR8C;AAS9CC,IAAAA,qBAT8C;AAU9CC,IAAAA,mBAV8C;AAW9CC,IAAAA,aAX8C;AAY9CC,IAAAA,SAAS,EAAEX;AAZmC,GAAxB,CAAxB;AAeA,SAAO;AACL2J,IAAAA,SAAS,EAAE9E;AADN,GAAP;AAGD","sources":["./packages/@react-aria/selection/src/utils.ts","./packages/@react-aria/selection/src/useTypeSelect.ts","./packages/@react-aria/selection/src/useSelectableCollection.ts","./packages/@react-aria/selection/src/useSelectableItem.ts","./packages/@react-aria/selection/src/ListKeyboardDelegate.ts","./packages/@react-aria/selection/src/useSelectableList.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {isAppleDevice} from '@react-aria/utils';\nimport {isMac} from '@react-aria/utils';\n\ninterface Event {\n altKey: boolean,\n ctrlKey: boolean,\n metaKey: boolean\n}\n\nexport function isNonContiguousSelectionModifier(e: Event) {\n // Ctrl + Arrow Up/Arrow Down has a system wide meaning on macOS, so use Alt instead.\n // On Windows and Ubuntu, Alt + Space has a system wide meaning.\n return isAppleDevice() ? e.altKey : e.ctrlKey;\n}\n\nexport function isCtrlKeyPressed(e: Event) {\n if (isMac()) {\n return e.metaKey;\n }\n\n return e.ctrlKey;\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {HTMLAttributes, Key, KeyboardEvent, useRef} from 'react';\nimport {KeyboardDelegate} from '@react-types/shared';\nimport {MultipleSelectionManager} from '@react-stately/selection';\n\ninterface TypeSelectOptions {\n /**\n * A delegate that returns collection item keys with respect to visual layout.\n */\n keyboardDelegate: KeyboardDelegate,\n /**\n * An interface for reading and updating multiple selection state.\n */\n selectionManager: MultipleSelectionManager,\n /**\n * Called when an item is focused by typing.\n */\n onTypeSelect?: (key: Key) => void\n}\n\ninterface TypeSelectAria {\n /**\n * Props to be spread on the owner of the options.\n */\n typeSelectProps: HTMLAttributes<HTMLElement>\n}\n\n/**\n * Handles typeahead interactions with collections.\n */\nexport function useTypeSelect(options: TypeSelectOptions): TypeSelectAria {\n let {keyboardDelegate, selectionManager, onTypeSelect} = options;\n let state = useRef({\n search: '',\n timeout: null\n }).current;\n\n let onKeyDown = (e: KeyboardEvent) => {\n let character = getStringForKey(e.key);\n if (!character || e.ctrlKey || e.metaKey) {\n return;\n }\n\n // Do not propagate the Spacebar event if it's meant to be part of the search.\n // When we time out, the search term becomes empty, hence the check on length.\n // Trimming is to account for the case of pressing the Spacebar more than once,\n // which should cycle through the selection/deselection of the focused item.\n if (character === ' ' && state.search.trim().length > 0) {\n e.preventDefault();\n if (!('continuePropagation' in e)) {\n e.stopPropagation();\n }\n }\n\n state.search += character;\n\n // Use the delegate to find a key to focus.\n // Prioritize items after the currently focused item, falling back to searching the whole list.\n let key = keyboardDelegate.getKeyForSearch(state.search, selectionManager.focusedKey);\n\n // If no key found, search from the top.\n if (key == null) {\n key = keyboardDelegate.getKeyForSearch(state.search);\n }\n\n if (key != null) {\n selectionManager.setFocusedKey(key);\n if (onTypeSelect) {\n onTypeSelect(key);\n }\n }\n\n clearTimeout(state.timeout);\n state.timeout = setTimeout(() => {\n state.search = '';\n }, 500);\n };\n\n return {\n typeSelectProps: {\n // Using a capturing listener to catch the keydown event before\n // other hooks in order to handle the Spacebar event.\n onKeyDownCapture: keyboardDelegate.getKeyForSearch ? onKeyDown : null\n }\n };\n}\n\nfunction getStringForKey(key: string) {\n // If the key is of length 1, it is an ASCII value.\n // Otherwise, if there are no ASCII characters in the key name,\n // it is a Unicode character.\n // See https://www.w3.org/TR/uievents-key/\n if (key.length === 1 || !/^[A-Z]/i.test(key)) {\n return key;\n }\n\n return '';\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {FocusEvent, HTMLAttributes, Key, KeyboardEvent, RefObject, useEffect, useRef} from 'react';\nimport {focusSafely, getFocusableTreeWalker} from '@react-aria/focus';\nimport {FocusStrategy, KeyboardDelegate} from '@react-types/shared';\nimport {focusWithoutScrolling, mergeProps, useEvent} from '@react-aria/utils';\nimport {isCtrlKeyPressed, isNonContiguousSelectionModifier} from './utils';\nimport {MultipleSelectionManager} from '@react-stately/selection';\nimport {useLocale} from '@react-aria/i18n';\nimport {useTypeSelect} from './useTypeSelect';\n\ninterface SelectableCollectionOptions {\n /**\n * An interface for reading and updating multiple selection state.\n */\n selectionManager: MultipleSelectionManager,\n /**\n * A delegate object that implements behavior for keyboard focus movement.\n */\n keyboardDelegate: KeyboardDelegate,\n /**\n * The ref attached to the element representing the collection.\n */\n ref: RefObject<HTMLElement>,\n /**\n * Whether the collection or one of its items should be automatically focused upon render.\n * @default false\n */\n autoFocus?: boolean | FocusStrategy,\n /**\n * Whether focus should wrap around when the end/start is reached.\n * @default false\n */\n shouldFocusWrap?: boolean,\n /**\n * Whether the collection allows empty selection.\n * @default false\n */\n disallowEmptySelection?: boolean,\n /**\n * Whether the collection allows the user to select all items via keyboard shortcut.\n * @default false\n */\n disallowSelectAll?: boolean,\n /**\n * Whether selection should occur automatically on focus.\n * @default false\n */\n selectOnFocus?: boolean,\n /**\n * Whether typeahead is disabled.\n * @default false\n */\n disallowTypeAhead?: boolean,\n /**\n * Whether the collection items should use virtual focus instead of being focused directly.\n */\n shouldUseVirtualFocus?: boolean,\n /**\n * Whether navigation through tab key is enabled.\n */\n allowsTabNavigation?: boolean,\n /**\n * Whether the collection items are contained in a virtual scroller.\n */\n isVirtualized?: boolean,\n /**\n * The ref attached to the scrollable body. Used to provide automatic scrolling on item focus for non-virtualized collections.\n * If not provided, defaults to the collection ref.\n */\n scrollRef?: RefObject<HTMLElement>\n}\n\ninterface SelectableCollectionAria {\n /** Props for the collection element. */\n collectionProps: HTMLAttributes<HTMLElement>\n}\n\n/**\n * Handles interactions with selectable collections.\n */\nexport function useSelectableCollection(options: SelectableCollectionOptions): SelectableCollectionAria {\n let {\n selectionManager: manager,\n keyboardDelegate: delegate,\n ref,\n autoFocus = false,\n shouldFocusWrap = false,\n disallowEmptySelection = false,\n disallowSelectAll = false,\n selectOnFocus = manager.selectionBehavior === 'replace',\n disallowTypeAhead = false,\n shouldUseVirtualFocus,\n allowsTabNavigation = false,\n isVirtualized,\n // If no scrollRef is provided, assume the collection ref is the scrollable region\n scrollRef = ref\n } = options;\n let {direction} = useLocale();\n\n\n let onKeyDown = (e: KeyboardEvent) => {\n // Prevent option + tab from doing anything since it doesn't move focus to the cells, only buttons/checkboxes\n if (e.altKey && e.key === 'Tab') {\n e.preventDefault();\n }\n\n // Keyboard events bubble through portals. Don't handle keyboard events\n // for elements outside the collection (e.g. menus).\n if (!ref.current.contains(e.target as HTMLElement)) {\n return;\n }\n\n const navigateToKey = (key: Key | undefined, childFocus?: FocusStrategy) => {\n if (key != null) {\n manager.setFocusedKey(key, childFocus);\n\n if (e.shiftKey && manager.selectionMode === 'multiple') {\n manager.extendSelection(key);\n } else if (selectOnFocus && !isNonContiguousSelectionModifier(e)) {\n manager.replaceSelection(key);\n }\n }\n };\n\n switch (e.key) {\n case 'ArrowDown': {\n if (delegate.getKeyBelow) {\n e.preventDefault();\n let nextKey = manager.focusedKey != null\n ? delegate.getKeyBelow(manager.focusedKey)\n : delegate.getFirstKey?.();\n if (nextKey == null && shouldFocusWrap) {\n nextKey = delegate.getFirstKey?.(manager.focusedKey);\n }\n navigateToKey(nextKey);\n }\n break;\n }\n case 'ArrowUp': {\n if (delegate.getKeyAbove) {\n e.preventDefault();\n let nextKey = manager.focusedKey != null\n ? delegate.getKeyAbove(manager.focusedKey)\n : delegate.getLastKey?.();\n if (nextKey == null && shouldFocusWrap) {\n nextKey = delegate.getLastKey?.(manager.focusedKey);\n }\n navigateToKey(nextKey);\n }\n break;\n }\n case 'ArrowLeft': {\n if (delegate.getKeyLeftOf) {\n e.preventDefault();\n let nextKey = delegate.getKeyLeftOf(manager.focusedKey);\n navigateToKey(nextKey, direction === 'rtl' ? 'first' : 'last');\n }\n break;\n }\n case 'ArrowRight': {\n if (delegate.getKeyRightOf) {\n e.preventDefault();\n let nextKey = delegate.getKeyRightOf(manager.focusedKey);\n navigateToKey(nextKey, direction === 'rtl' ? 'last' : 'first');\n }\n break;\n }\n case 'Home':\n if (delegate.getFirstKey) {\n e.preventDefault();\n let firstKey = delegate.getFirstKey(manager.focusedKey, isCtrlKeyPressed(e));\n manager.setFocusedKey(firstKey);\n if (isCtrlKeyPressed(e) && e.shiftKey && manager.selectionMode === 'multiple') {\n manager.extendSelection(firstKey);\n } else if (selectOnFocus) {\n manager.replaceSelection(firstKey);\n }\n }\n break;\n case 'End':\n if (delegate.getLastKey) {\n e.preventDefault();\n let lastKey = delegate.getLastKey(manager.focusedKey, isCtrlKeyPressed(e));\n manager.setFocusedKey(lastKey);\n if (isCtrlKeyPressed(e) && e.shiftKey && manager.selectionMode === 'multiple') {\n manager.extendSelection(lastKey);\n } else if (selectOnFocus) {\n manager.replaceSelection(lastKey);\n }\n }\n break;\n case 'PageDown':\n if (delegate.getKeyPageBelow) {\n e.preventDefault();\n let nextKey = delegate.getKeyPageBelow(manager.focusedKey);\n navigateToKey(nextKey);\n }\n break;\n case 'PageUp':\n if (delegate.getKeyPageAbove) {\n e.preventDefault();\n let nextKey = delegate.getKeyPageAbove(manager.focusedKey);\n navigateToKey(nextKey);\n }\n break;\n case 'a':\n if (isCtrlKeyPressed(e) && manager.selectionMode === 'multiple' && disallowSelectAll !== true) {\n e.preventDefault();\n manager.selectAll();\n }\n break;\n case 'Escape':\n e.preventDefault();\n if (!disallowEmptySelection) {\n manager.clearSelection();\n }\n break;\n case 'Tab': {\n if (!allowsTabNavigation) {\n // There may be elements that are \"tabbable\" inside a collection (e.g. in a grid cell).\n // However, collections should be treated as a single tab stop, with arrow key navigation internally.\n // We don't control the rendering of these, so we can't override the tabIndex to prevent tabbing.\n // Instead, we handle the Tab key, and move focus manually to the first/last tabbable element\n // in the collection, so that the browser default behavior will apply starting from that element\n // rather than the currently focused one.\n if (e.shiftKey) {\n ref.current.focus();\n } else {\n let walker = getFocusableTreeWalker(ref.current, {tabbable: true});\n let next: HTMLElement;\n let last: HTMLElement;\n do {\n last = walker.lastChild() as HTMLElement;\n if (last) {\n next = last;\n }\n } while (last);\n\n if (next && !next.contains(document.activeElement)) {\n focusWithoutScrolling(next);\n }\n }\n break;\n }\n }\n }\n };\n\n // Store the scroll position so we can restore it later.\n let scrollPos = useRef({top: 0, left: 0});\n useEvent(scrollRef, 'scroll', isVirtualized ? null : () => {\n scrollPos.current = {\n top: scrollRef.current.scrollTop,\n left: scrollRef.current.scrollLeft\n };\n });\n\n let onFocus = (e: FocusEvent) => {\n if (manager.isFocused) {\n // If a focus event bubbled through a portal, reset focus state.\n if (!e.currentTarget.contains(e.target)) {\n manager.setFocused(false);\n }\n\n return;\n }\n\n // Focus events can bubble through portals. Ignore these events.\n if (!e.currentTarget.contains(e.target)) {\n return;\n }\n\n manager.setFocused(true);\n\n if (manager.focusedKey == null) {\n let navigateToFirstKey = (key: Key | undefined) => {\n if (key != null) {\n manager.setFocusedKey(key);\n if (selectOnFocus) {\n manager.replaceSelection(key);\n }\n }\n };\n // If the user hasn't yet interacted with the collection, there will be no focusedKey set.\n // Attempt to detect whether the user is tabbing forward or backward into the collection\n // and either focus the first or last item accordingly.\n let relatedTarget = e.relatedTarget as Element;\n if (relatedTarget && (e.currentTarget.compareDocumentPosition(relatedTarget) & Node.DOCUMENT_POSITION_FOLLOWING)) {\n navigateToFirstKey(manager.lastSelectedKey ?? delegate.getLastKey());\n } else {\n navigateToFirstKey(manager.firstSelectedKey ?? delegate.getFirstKey());\n }\n } else if (!isVirtualized) {\n // Restore the scroll position to what it was before.\n scrollRef.current.scrollTop = scrollPos.current.top;\n scrollRef.current.scrollLeft = scrollPos.current.left;\n\n // Refocus and scroll the focused item into view if it exists within the scrollable region.\n let element = scrollRef.current.querySelector(`[data-key=\"${manager.focusedKey}\"]`) as HTMLElement;\n if (element) {\n // This prevents a flash of focus on the first/last element in the collection\n focusWithoutScrolling(element);\n scrollIntoView(scrollRef.current, element);\n }\n }\n };\n\n let onBlur = (e) => {\n // Don't set blurred and then focused again if moving focus within the collection.\n if (!e.currentTarget.contains(e.relatedTarget as HTMLElement)) {\n manager.setFocused(false);\n }\n };\n\n const autoFocusRef = useRef(autoFocus);\n useEffect(() => {\n if (autoFocusRef.current) {\n let focusedKey = null;\n\n // Check focus strategy to determine which item to focus\n if (autoFocus === 'first') {\n focusedKey = delegate.getFirstKey();\n } if (autoFocus === 'last') {\n focusedKey = delegate.getLastKey();\n }\n\n // If there are any selected keys, make the first one the new focus target\n let selectedKeys = manager.selectedKeys;\n if (selectedKeys.size) {\n focusedKey = selectedKeys.values().next().value;\n }\n\n manager.setFocused(true);\n manager.setFocusedKey(focusedKey);\n\n // If no default focus key is selected, focus the collection itself.\n if (focusedKey == null && !shouldUseVirtualFocus) {\n focusSafely(ref.current);\n }\n }\n autoFocusRef.current = false;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n // If not virtualized, scroll the focused element into view when the focusedKey changes.\n // When virtualized, Virtualizer handles this internally.\n useEffect(() => {\n if (!isVirtualized && manager.focusedKey && scrollRef?.current) {\n let element = scrollRef.current.querySelector(`[data-key=\"${manager.focusedKey}\"]`) as HTMLElement;\n if (element) {\n scrollIntoView(scrollRef.current, element);\n }\n }\n }, [isVirtualized, scrollRef, manager.focusedKey]);\n\n let handlers = {\n onKeyDown,\n onFocus,\n onBlur,\n onMouseDown(e) {\n // Ignore events that bubbled through portals.\n if (e.currentTarget.contains(e.target)) {\n // Prevent focus going to the collection when clicking on the scrollbar.\n e.preventDefault();\n }\n }\n };\n\n let {typeSelectProps} = useTypeSelect({\n keyboardDelegate: delegate,\n selectionManager: manager\n });\n\n if (!disallowTypeAhead) {\n handlers = mergeProps(typeSelectProps, handlers);\n }\n\n // If nothing is focused within the collection, make the collection itself tabbable.\n // This will be marshalled to either the first or last item depending on where focus came from.\n // If using virtual focus, don't set a tabIndex at all so that VoiceOver on iOS 14 doesn't try\n // to move real DOM focus to the element anyway.\n let tabIndex: number;\n if (!shouldUseVirtualFocus) {\n tabIndex = manager.focusedKey == null ? 0 : -1;\n }\n\n return {\n collectionProps: {\n ...handlers,\n tabIndex\n }\n };\n}\n\n/**\n * Scrolls `scrollView` so that `element` is visible.\n * Similar to `element.scrollIntoView({block: 'nearest'})` (not supported in Edge),\n * but doesn't affect parents above `scrollView`.\n */\nfunction scrollIntoView(scrollView: HTMLElement, element: HTMLElement) {\n let offsetX = relativeOffset(scrollView, element, 'left');\n let offsetY = relativeOffset(scrollView, element, 'top');\n let width = element.offsetWidth;\n let height = element.offsetHeight;\n let x = scrollView.scrollLeft;\n let y = scrollView.scrollTop;\n let maxX = x + scrollView.offsetWidth;\n let maxY = y + scrollView.offsetHeight;\n\n if (offsetX <= x) {\n x = offsetX;\n } else if (offsetX + width > maxX) {\n x += offsetX + width - maxX;\n }\n if (offsetY <= y) {\n y = offsetY;\n } else if (offsetY + height > maxY) {\n y += offsetY + height - maxY;\n }\n\n scrollView.scrollLeft = x;\n scrollView.scrollTop = y;\n}\n\n/**\n * Computes the offset left or top from child to ancestor by accumulating\n * offsetLeft or offsetTop through intervening offsetParents.\n */\nfunction relativeOffset(ancestor: HTMLElement, child: HTMLElement, axis: 'left'|'top') {\n const prop = axis === 'left' ? 'offsetLeft' : 'offsetTop';\n let sum = 0;\n while (child.offsetParent) {\n sum += child[prop];\n if (child.offsetParent === ancestor) {\n // Stop once we have found the ancestor we are interested in.\n break;\n } else if (child.offsetParent.contains(ancestor)) {\n // If the ancestor is not `position:relative`, then we stop at\n // _its_ offset parent, and we subtract off _its_ offset, so that\n // we end up with the proper offset from child to ancestor.\n sum -= ancestor[prop];\n break;\n }\n child = child.offsetParent as HTMLElement;\n }\n return sum;\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {focusSafely} from '@react-aria/focus';\nimport {HTMLAttributes, Key, RefObject, useEffect, useRef} from 'react';\nimport {isCtrlKeyPressed, isNonContiguousSelectionModifier} from './utils';\nimport {LongPressEvent, PressEvent} from '@react-types/shared';\nimport {mergeProps} from '@react-aria/utils';\nimport {MultipleSelectionManager} from '@react-stately/selection';\nimport {PressProps, useLongPress, usePress} from '@react-aria/interactions';\n\ninterface SelectableItemOptions {\n /**\n * An interface for reading and updating multiple selection state.\n */\n selectionManager: MultipleSelectionManager,\n /**\n * A unique key for the item.\n */\n key: Key,\n /**\n * Ref to the item.\n */\n ref: RefObject<HTMLElement>,\n /**\n * By default, selection occurs on pointer down. This can be strange if selecting an\n * item causes the UI to disappear immediately (e.g. menus).\n */\n shouldSelectOnPressUp?: boolean,\n /**\n * Whether the option is contained in a virtual scroller.\n */\n isVirtualized?: boolean,\n /**\n * Function to focus the item.\n */\n focus?: () => void,\n /**\n * Whether the option should use virtual focus instead of being focused directly.\n */\n shouldUseVirtualFocus?: boolean,\n /** Whether the item is disabled. */\n isDisabled?: boolean,\n /**\n * Handler that is called when a user performs an action on the cell. The exact user event depends on\n * the collection's `selectionBehavior` prop and the interaction modality.\n */\n onAction?: () => void\n}\n\ninterface SelectableItemAria {\n /**\n * Props to be spread on the item root node.\n */\n itemProps: HTMLAttributes<HTMLElement>,\n /** Whether the item is currently in a pressed state. */\n isPressed: boolean\n}\n\n/**\n * Handles interactions with an item in a selectable collection.\n */\nexport function useSelectableItem(options: SelectableItemOptions): SelectableItemAria {\n let {\n selectionManager: manager,\n key,\n ref,\n shouldSelectOnPressUp,\n isVirtualized,\n shouldUseVirtualFocus,\n focus,\n isDisabled,\n onAction\n } = options;\n\n let onSelect = (e: PressEvent | LongPressEvent | PointerEvent) => {\n if (e.pointerType === 'keyboard' && isNonContiguousSelectionModifier(e)) {\n manager.toggleSelection(key);\n } else {\n if (manager.selectionMode === 'none') {\n return;\n }\n\n if (manager.selectionMode === 'single') {\n if (manager.isSelected(key) && !manager.disallowEmptySelection) {\n manager.toggleSelection(key);\n } else {\n manager.replaceSelection(key);\n }\n } else if (e && e.shiftKey) {\n manager.extendSelection(key);\n } else if (manager.selectionBehavior === 'toggle' || (e && (isCtrlKeyPressed(e) || e.pointerType === 'touch' || e.pointerType === 'virtual'))) {\n // 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\n manager.toggleSelection(key);\n } else {\n manager.replaceSelection(key);\n }\n }\n };\n\n // Focus the associated DOM node when this item becomes the focusedKey\n let isFocused = key === manager.focusedKey;\n useEffect(() => {\n if (isFocused && manager.isFocused && !shouldUseVirtualFocus && document.activeElement !== ref.current) {\n if (focus) {\n focus();\n } else {\n focusSafely(ref.current);\n }\n }\n }, [ref, isFocused, manager.focusedKey, manager.childFocusStrategy, manager.isFocused, shouldUseVirtualFocus]);\n\n // Set tabIndex to 0 if the element is focused, or -1 otherwise so that only the last focused\n // item is tabbable. If using virtual focus, don't set a tabIndex at all so that VoiceOver\n // on iOS 14 doesn't try to move real DOM focus to the item anyway.\n let itemProps: SelectableItemAria['itemProps'] = {};\n if (!shouldUseVirtualFocus) {\n itemProps = {\n tabIndex: isFocused ? 0 : -1,\n onFocus(e) {\n if (e.target === ref.current) {\n manager.setFocusedKey(key);\n }\n }\n };\n }\n\n let modality = useRef(null);\n let hasPrimaryAction = onAction && manager.selectionMode === 'none';\n let hasSecondaryAction = onAction && manager.selectionMode !== 'none' && manager.selectionBehavior === 'replace';\n let allowsSelection = !isDisabled && manager.canSelectItem(key);\n\n // By default, selection occurs on pointer down. This can be strange if selecting an\n // item causes the UI to disappear immediately (e.g. menus).\n // If shouldSelectOnPressUp is true, we use onPressUp instead of onPressStart.\n // onPress requires a pointer down event on the same element as pointer up. For menus,\n // we want to be able to have the pointer down on the trigger that opens the menu and\n // the pointer up on the menu item rather than requiring a separate press.\n // For keyboard events, selection still occurs on key down.\n let itemPressProps: PressProps = {};\n if (shouldSelectOnPressUp) {\n itemPressProps.onPressStart = (e) => {\n modality.current = e.pointerType;\n if (e.pointerType === 'keyboard') {\n onSelect(e);\n }\n };\n\n itemPressProps.onPressUp = (e) => {\n if (e.pointerType !== 'keyboard') {\n onSelect(e);\n }\n };\n\n itemPressProps.onPress = hasPrimaryAction ? () => onAction() : null;\n } else {\n // On touch, it feels strange to select on touch down, so we special case this.\n itemPressProps.onPressStart = (e) => {\n modality.current = e.pointerType;\n if (e.pointerType !== 'touch' && e.pointerType !== 'virtual') {\n onSelect(e);\n }\n };\n\n itemPressProps.onPress = (e) => {\n if (e.pointerType === 'touch' || e.pointerType === 'virtual' || hasPrimaryAction) {\n // Single tap on touch with selectionBehavior = 'replace' performs an action, i.e. navigation.\n // Also perform action on press up when selectionMode = 'none'.\n if (hasPrimaryAction || hasSecondaryAction) {\n onAction();\n } else {\n onSelect(e);\n }\n }\n };\n }\n\n if (!isVirtualized) {\n itemProps['data-key'] = key;\n }\n\n itemPressProps.preventFocusOnPress = shouldUseVirtualFocus;\n let {pressProps, isPressed} = usePress(itemPressProps);\n\n // Double clicking with a mouse with selectionBehavior = 'replace' performs an action.\n let onDoubleClick = hasSecondaryAction ? (e) => {\n if (modality.current === 'mouse') {\n e.stopPropagation();\n e.preventDefault();\n onAction();\n }\n } : undefined;\n\n // Long pressing an item with touch when selectionBehavior = 'replace' switches the selection behavior\n // to 'toggle'. This changes the single tap behavior from performing an action (i.e. navigating) to\n // selecting, and may toggle the appearance of a UI affordance like checkboxes on each item.\n // TODO: what about when drag and drop is also enabled??\n let {longPressProps} = useLongPress({\n isDisabled: !hasSecondaryAction,\n onLongPress(e) {\n if (e.pointerType === 'touch') {\n onSelect(e);\n manager.setSelectionBehavior('toggle');\n }\n }\n });\n\n // Pressing the Enter key with selectionBehavior = 'replace' performs an action (i.e. navigation).\n let onKeyUp = hasSecondaryAction ? (e: KeyboardEvent) => {\n if (e.key === 'Enter') {\n onAction();\n }\n } : undefined;\n\n return {\n itemProps: mergeProps(\n itemProps,\n allowsSelection || hasPrimaryAction ? pressProps : {},\n hasSecondaryAction ? longPressProps : {},\n {onKeyUp, onDoubleClick}\n ),\n isPressed\n };\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, KeyboardDelegate, Node} from '@react-types/shared';\nimport {Key, RefObject} from 'react';\n\nexport class ListKeyboardDelegate<T> implements KeyboardDelegate {\n private collection: Collection<Node<T>>;\n private disabledKeys: Set<Key>;\n private ref: RefObject<HTMLElement>;\n private collator: Intl.Collator;\n\n constructor(collection: Collection<Node<T>>, disabledKeys: Set<Key>, ref: RefObject<HTMLElement>, collator?: Intl.Collator) {\n this.collection = collection;\n this.disabledKeys = disabledKeys;\n this.ref = ref;\n this.collator = collator;\n }\n\n getKeyBelow(key: Key) {\n key = this.collection.getKeyAfter(key);\n while (key != null) {\n let item = this.collection.getItem(key);\n if (item.type === 'item' && !this.disabledKeys.has(key)) {\n return key;\n }\n\n key = this.collection.getKeyAfter(key);\n }\n }\n\n getKeyAbove(key: Key) {\n key = this.collection.getKeyBefore(key);\n while (key != null) {\n let item = this.collection.getItem(key);\n if (item.type === 'item' && !this.disabledKeys.has(key)) {\n return key;\n }\n\n key = this.collection.getKeyBefore(key);\n }\n }\n\n getFirstKey() {\n let key = this.collection.getFirstKey();\n while (key != null) {\n let item = this.collection.getItem(key);\n if (item.type === 'item' && !this.disabledKeys.has(key)) {\n return key;\n }\n\n key = this.collection.getKeyAfter(key);\n }\n }\n\n getLastKey() {\n let key = this.collection.getLastKey();\n while (key != null) {\n let item = this.collection.getItem(key);\n if (item.type === 'item' && !this.disabledKeys.has(key)) {\n return key;\n }\n\n key = this.collection.getKeyBefore(key);\n }\n }\n\n private getItem(key: Key): HTMLElement {\n return this.ref.current.querySelector(`[data-key=\"${key}\"]`);\n }\n\n getKeyPageAbove(key: Key) {\n let menu = this.ref.current;\n let item = this.getItem(key);\n if (!item) {\n return null;\n }\n\n let pageY = Math.max(0, item.offsetTop + item.offsetHeight - menu.offsetHeight);\n\n while (item && item.offsetTop > pageY) {\n key = this.getKeyAbove(key);\n item = this.getItem(key);\n }\n\n return key;\n }\n\n getKeyPageBelow(key: Key) {\n let menu = this.ref.current;\n let item = this.getItem(key);\n if (!item) {\n return null;\n }\n\n let pageY = Math.min(menu.scrollHeight, item.offsetTop - item.offsetHeight + menu.offsetHeight);\n\n while (item && item.offsetTop < pageY) {\n key = this.getKeyBelow(key);\n item = this.getItem(key);\n }\n\n return key;\n }\n\n getKeyForSearch(search: string, fromKey?: Key) {\n if (!this.collator) {\n return null;\n }\n\n let collection = this.collection;\n let key = fromKey || this.getFirstKey();\n while (key != null) {\n let item = collection.getItem(key);\n let substring = item.textValue.slice(0, search.length);\n if (item.textValue && this.collator.compare(substring, search) === 0) {\n return key;\n }\n\n key = this.getKeyBelow(key);\n }\n\n return null;\n }\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, FocusStrategy, KeyboardDelegate, Node} from '@react-types/shared';\nimport {HTMLAttributes, Key, RefObject, useMemo} from 'react';\nimport {ListKeyboardDelegate} from './ListKeyboardDelegate';\nimport {MultipleSelectionManager} from '@react-stately/selection';\nimport {useCollator} from '@react-aria/i18n';\nimport {useSelectableCollection} from './useSelectableCollection';\n\ninterface SelectableListOptions {\n /**\n * An interface for reading and updating multiple selection state.\n */\n selectionManager: MultipleSelectionManager,\n /**\n * State of the collection.\n */\n collection: Collection<Node<unknown>>,\n /**\n * The item keys that are disabled. These items cannot be selected, focused, or otherwise interacted with.\n */\n disabledKeys: Set<Key>,\n /**\n * A ref to the item.\n */\n ref?: RefObject<HTMLElement>,\n /**\n * A delegate that returns collection item keys with respect to visual layout.\n */\n keyboardDelegate?: KeyboardDelegate,\n /**\n * Whether the collection or one of its items should be automatically focused upon render.\n * @default false\n */\n autoFocus?: boolean | FocusStrategy,\n /**\n * Whether focus should wrap around when the end/start is reached.\n * @default false\n */\n shouldFocusWrap?: boolean,\n /**\n * Whether the option is contained in a virtual scroller.\n */\n isVirtualized?: boolean,\n /**\n * Whether the collection allows empty selection.\n * @default false\n */\n disallowEmptySelection?: boolean,\n /**\n * Whether selection should occur automatically on focus.\n * @default false\n */\n selectOnFocus?: boolean,\n /**\n * Whether typeahead is disabled.\n * @default false\n */\n disallowTypeAhead?: boolean,\n /**\n * Whether the collection items should use virtual focus instead of being focused directly.\n */\n shouldUseVirtualFocus?: boolean,\n /**\n * Whether navigation through tab key is enabled.\n */\n allowsTabNavigation?: boolean\n}\n\ninterface SelectableListAria {\n /**\n * Props for the option element.\n */\n listProps: HTMLAttributes<HTMLElement>\n}\n\n/**\n * Handles interactions with a selectable list.\n */\nexport function useSelectableList(props: SelectableListOptions): SelectableListAria {\n let {\n selectionManager,\n collection,\n disabledKeys,\n ref,\n keyboardDelegate,\n autoFocus,\n shouldFocusWrap,\n isVirtualized,\n disallowEmptySelection,\n selectOnFocus = false,\n disallowTypeAhead,\n shouldUseVirtualFocus,\n allowsTabNavigation\n } = props;\n\n // By default, a KeyboardDelegate is provided which uses the DOM to query layout information (e.g. for page up/page down).\n // When virtualized, the layout object will be passed in as a prop and override this.\n let collator = useCollator({usage: 'search', sensitivity: 'base'});\n let delegate = useMemo(() => keyboardDelegate || new ListKeyboardDelegate(collection, disabledKeys, ref, collator), [keyboardDelegate, collection, disabledKeys, ref, collator]);\n\n let {collectionProps} = useSelectableCollection({\n ref,\n selectionManager,\n keyboardDelegate: delegate,\n autoFocus,\n shouldFocusWrap,\n disallowEmptySelection,\n selectOnFocus,\n disallowTypeAhead,\n shouldUseVirtualFocus,\n allowsTabNavigation,\n isVirtualized,\n scrollRef: ref\n });\n\n return {\n listProps: collectionProps\n };\n}\n"],"names":["isNonContiguousSelectionModifier","e","isAppleDevice","altKey","ctrlKey","isCtrlKeyPressed","isMac","metaKey","useTypeSelect","options","keyboardDelegate","selectionManager","onTypeSelect","state","useRef","search","timeout","current","onKeyDown","character","getStringForKey","key","trim","length","preventDefault","stopPropagation","getKeyForSearch","focusedKey","setFocusedKey","clearTimeout","setTimeout","typeSelectProps","onKeyDownCapture","test","useSelectableCollection","manager","delegate","ref","autoFocus","shouldFocusWrap","disallowEmptySelection","disallowSelectAll","selectOnFocus","selectionBehavior","disallowTypeAhead","shouldUseVirtualFocus","allowsTabNavigation","isVirtualized","scrollRef","direction","useLocale","contains","target","navigateToKey","childFocus","shiftKey","selectionMode","extendSelection","replaceSelection","getKeyBelow","nextKey","getFirstKey","getKeyAbove","getLastKey","getKeyLeftOf","getKeyRightOf","firstKey","lastKey","getKeyPageBelow","getKeyPageAbove","selectAll","clearSelection","focus","walker","getFocusableTreeWalker","tabbable","next","last","lastChild","document","activeElement","focusWithoutScrolling","scrollPos","top","left","useEvent","scrollTop","scrollLeft","onFocus","isFocused","currentTarget","setFocused","navigateToFirstKey","relatedTarget","compareDocumentPosition","Node","DOCUMENT_POSITION_FOLLOWING","lastSelectedKey","firstSelectedKey","element","querySelector","scrollIntoView","onBlur","autoFocusRef","useEffect","selectedKeys","size","values","value","focusSafely","handlers","onMouseDown","mergeProps","tabIndex","collectionProps","scrollView","offsetX","relativeOffset","offsetY","width","offsetWidth","height","offsetHeight","x","y","maxX","maxY","ancestor","child","axis","prop","sum","offsetParent","useSelectableItem","shouldSelectOnPressUp","isDisabled","onAction","onSelect","pointerType","toggleSelection","isSelected","childFocusStrategy","itemProps","modality","hasPrimaryAction","hasSecondaryAction","allowsSelection","canSelectItem","itemPressProps","onPressStart","onPressUp","onPress","preventFocusOnPress","pressProps","isPressed","usePress","onDoubleClick","undefined","longPressProps","useLongPress","onLongPress","setSelectionBehavior","onKeyUp","ListKeyboardDelegate","constructor","collection","disabledKeys","collator","getKeyAfter","item","getItem","type","has","getKeyBefore","menu","pageY","Math","max","offsetTop","min","scrollHeight","fromKey","substring","textValue","slice","compare","useSelectableList","props","useCollator","usage","sensitivity","useMemo","listProps"],"version":3,"file":"module.js.map"}
package/dist/types.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { HTMLAttributes, Key, RefObject } from "react";
2
2
  import { KeyboardDelegate, FocusStrategy, Collection, Node } from "@react-types/shared";
3
3
  import { MultipleSelectionManager } from "@react-stately/selection";
4
- import { PressProps } from "@react-aria/interactions";
5
4
  interface TypeSelectOptions {
6
5
  /**
7
6
  * A delegate that returns collection item keys with respect to visual layout.
@@ -125,12 +124,21 @@ interface SelectableItemOptions {
125
124
  * Whether the option should use virtual focus instead of being focused directly.
126
125
  */
127
126
  shouldUseVirtualFocus?: boolean;
127
+ /** Whether the item is disabled. */
128
+ isDisabled?: boolean;
129
+ /**
130
+ * Handler that is called when a user performs an action on the cell. The exact user event depends on
131
+ * the collection's `selectionBehavior` prop and the interaction modality.
132
+ */
133
+ onAction?: () => void;
128
134
  }
129
135
  interface SelectableItemAria {
130
136
  /**
131
137
  * Props to be spread on the item root node.
132
138
  */
133
- itemProps: HTMLAttributes<HTMLElement> & PressProps;
139
+ itemProps: HTMLAttributes<HTMLElement>;
140
+ /** Whether the item is currently in a pressed state. */
141
+ isPressed: boolean;
134
142
  }
135
143
  /**
136
144
  * Handles interactions with an item in a selectable collection.
@@ -1 +1 @@
1
- {"mappings":"A;A;A;A;AAgBA;IACE;A;OAEG;IACH,gBAAgB,EAAE,gBAAgB,CAAC;IACnC;A;OAEG;IACH,gBAAgB,EAAE,wBAAwB,CAAC;IAC3C;A;OAEG;IACH,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,CAAA;CAClC;AAED;IACE;A;OAEG;IACH,eAAe,EAAE,eAAe,WAAW,CAAC,CAAA;CA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AAO,CAAC;IACxB;A;A;OAGG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;A;OAEG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC;A;OAEG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAA;CAC9B;AAED;IACE;A;OAEG;IACH,SAAS,EAAE,eAAe,WAAW,CAAC,CAAA;CACvC;AAED;A;GAEG;AACH,kCAAkC,KAAK,EAAE,qBAAqB,GAAG,kBAAkB,CAwClF","sources":["./packages/@react-aria/selection/src/packages/@react-aria/selection/src/useTypeSelect.ts","./packages/@react-aria/selection/src/packages/@react-aria/selection/src/useSelectableCollection.ts","./packages/@react-aria/selection/src/packages/@react-aria/selection/src/useSelectableItem.ts","./packages/@react-aria/selection/src/packages/@react-aria/selection/src/ListKeyboardDelegate.ts","./packages/@react-aria/selection/src/packages/@react-aria/selection/src/useSelectableList.ts","./packages/@react-aria/selection/src/packages/@react-aria/selection/src/index.ts"],"sourcesContent":[null,null,null,null,null,null],"names":[],"version":3,"file":"types.d.ts.map"}
1
+ {"mappings":"A;A;A;ACgBA;IACE;A;OAEG;IACH,gBAAgB,EAAE,gBAAgB,CAAC;IACnC;A;OAEG;IACH,gBAAgB,EAAE,wBAAwB,CAAC;IAC3C;A;OAEG;IACH,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,CAAA;CAClC;AAED;IACE;A;OAEG;IACH,eAAe,EAAE,eAAe,WAAW,CAAC,CAAA;CAC7C;AAED;A;GAEG;AACH,8BAA8B,OAAO,EAAE,iBAAiB,GAAG,cAAc,CAuDxE;AC3ED;IACE;A;OAEG;IACH,gBAAgB,EAAE,wBAAwB,CAAC;IAC3C;A;OAEG;IACH,gBAAgB,EAAE,gBAAgB,CAAC;IACnC;A;OAEG;IACH,GAAG,EAAE,UAAU,WAAW,CAAC,CAAC;IAC5B;A;A;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,GAAG,aAAa,CAAC;IACpC;A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AO,CAAA;CAC9B;AAED;IACE;A;OAEG;IACH,SAAS,EAAE,eAAe,WAAW,CAAC,CAAA;CACvC;AAED;A;GAEG;AACH,kCAAkC,KAAK,EAAE,qBAAqB,GAAG,kBAAkB,CAwClF","sources":["./packages/@react-aria/selection/src/packages/@react-aria/selection/src/utils.ts","./packages/@react-aria/selection/src/packages/@react-aria/selection/src/useTypeSelect.ts","./packages/@react-aria/selection/src/packages/@react-aria/selection/src/useSelectableCollection.ts","./packages/@react-aria/selection/src/packages/@react-aria/selection/src/useSelectableItem.ts","./packages/@react-aria/selection/src/packages/@react-aria/selection/src/ListKeyboardDelegate.ts","./packages/@react-aria/selection/src/packages/@react-aria/selection/src/useSelectableList.ts","./packages/@react-aria/selection/src/packages/@react-aria/selection/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null],"names":[],"version":3,"file":"types.d.ts.map"}