react-aria 3.49.0 → 3.50.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.
Files changed (244) hide show
  1. package/dist/private/autocomplete/useAutocomplete.cjs +16 -7
  2. package/dist/private/autocomplete/useAutocomplete.cjs.map +1 -1
  3. package/dist/private/autocomplete/useAutocomplete.js +16 -7
  4. package/dist/private/autocomplete/useAutocomplete.js.map +1 -1
  5. package/dist/private/autocomplete/useAutocomplete.mjs +16 -7
  6. package/dist/private/autocomplete/useAutocomplete.mjs.map +1 -1
  7. package/dist/private/breadcrumbs/useBreadcrumbs.cjs.map +1 -1
  8. package/dist/private/breadcrumbs/useBreadcrumbs.js.map +1 -1
  9. package/dist/private/breadcrumbs/useBreadcrumbs.mjs.map +1 -1
  10. package/dist/private/calendar/useCalendarBase.cjs.map +1 -1
  11. package/dist/private/calendar/useCalendarBase.js.map +1 -1
  12. package/dist/private/calendar/useCalendarBase.mjs.map +1 -1
  13. package/dist/private/calendar/useCalendarCell.cjs.map +1 -1
  14. package/dist/private/calendar/useCalendarCell.js.map +1 -1
  15. package/dist/private/calendar/useCalendarCell.mjs.map +1 -1
  16. package/dist/private/calendar/useCalendarYearPicker.cjs +4 -4
  17. package/dist/private/calendar/useCalendarYearPicker.cjs.map +1 -1
  18. package/dist/private/calendar/useCalendarYearPicker.js +4 -4
  19. package/dist/private/calendar/useCalendarYearPicker.js.map +1 -1
  20. package/dist/private/calendar/useCalendarYearPicker.mjs +4 -4
  21. package/dist/private/calendar/useCalendarYearPicker.mjs.map +1 -1
  22. package/dist/private/calendar/utils.cjs.map +1 -1
  23. package/dist/private/calendar/utils.js.map +1 -1
  24. package/dist/private/calendar/utils.mjs.map +1 -1
  25. package/dist/private/color/useColorArea.cjs.map +1 -1
  26. package/dist/private/color/useColorArea.js.map +1 -1
  27. package/dist/private/color/useColorArea.mjs.map +1 -1
  28. package/dist/private/color/useColorSwatch.cjs.map +1 -1
  29. package/dist/private/color/useColorSwatch.js.map +1 -1
  30. package/dist/private/color/useColorSwatch.mjs.map +1 -1
  31. package/dist/private/combobox/useComboBox.cjs +2 -0
  32. package/dist/private/combobox/useComboBox.cjs.map +1 -1
  33. package/dist/private/combobox/useComboBox.js +2 -0
  34. package/dist/private/combobox/useComboBox.js.map +1 -1
  35. package/dist/private/combobox/useComboBox.mjs +2 -0
  36. package/dist/private/combobox/useComboBox.mjs.map +1 -1
  37. package/dist/private/datepicker/useDateField.cjs.map +1 -1
  38. package/dist/private/datepicker/useDateField.js.map +1 -1
  39. package/dist/private/datepicker/useDateField.mjs.map +1 -1
  40. package/dist/private/datepicker/useDatePicker.cjs.map +1 -1
  41. package/dist/private/datepicker/useDatePicker.js.map +1 -1
  42. package/dist/private/datepicker/useDatePicker.mjs.map +1 -1
  43. package/dist/private/datepicker/useDateRangePicker.cjs.map +1 -1
  44. package/dist/private/datepicker/useDateRangePicker.js.map +1 -1
  45. package/dist/private/datepicker/useDateRangePicker.mjs.map +1 -1
  46. package/dist/private/datepicker/useDisplayNames.cjs +1 -2
  47. package/dist/private/datepicker/useDisplayNames.cjs.map +1 -1
  48. package/dist/private/datepicker/useDisplayNames.js +1 -2
  49. package/dist/private/datepicker/useDisplayNames.js.map +1 -1
  50. package/dist/private/datepicker/useDisplayNames.mjs +1 -2
  51. package/dist/private/datepicker/useDisplayNames.mjs.map +1 -1
  52. package/dist/private/dnd/DragManager.cjs +4 -1
  53. package/dist/private/dnd/DragManager.cjs.map +1 -1
  54. package/dist/private/dnd/DragManager.js +4 -1
  55. package/dist/private/dnd/DragManager.js.map +1 -1
  56. package/dist/private/dnd/DragManager.mjs +4 -1
  57. package/dist/private/dnd/DragManager.mjs.map +1 -1
  58. package/dist/private/dnd/useDrag.cjs.map +1 -1
  59. package/dist/private/dnd/useDrag.js.map +1 -1
  60. package/dist/private/dnd/useDrag.mjs.map +1 -1
  61. package/dist/private/dnd/useDraggableItem.cjs.map +1 -1
  62. package/dist/private/dnd/useDraggableItem.js.map +1 -1
  63. package/dist/private/dnd/useDraggableItem.mjs.map +1 -1
  64. package/dist/private/dnd/useDropIndicator.cjs.map +1 -1
  65. package/dist/private/dnd/useDropIndicator.js.map +1 -1
  66. package/dist/private/dnd/useDropIndicator.mjs.map +1 -1
  67. package/dist/private/dnd/useVirtualDrop.cjs.map +1 -1
  68. package/dist/private/dnd/useVirtualDrop.js.map +1 -1
  69. package/dist/private/dnd/useVirtualDrop.mjs.map +1 -1
  70. package/dist/private/dnd/utils.cjs +13 -3
  71. package/dist/private/dnd/utils.cjs.map +1 -1
  72. package/dist/private/dnd/utils.js +13 -3
  73. package/dist/private/dnd/utils.js.map +1 -1
  74. package/dist/private/dnd/utils.mjs +13 -3
  75. package/dist/private/dnd/utils.mjs.map +1 -1
  76. package/dist/private/form/useFormValidation.cjs +1 -1
  77. package/dist/private/form/useFormValidation.cjs.map +1 -1
  78. package/dist/private/form/useFormValidation.js +1 -1
  79. package/dist/private/form/useFormValidation.js.map +1 -1
  80. package/dist/private/form/useFormValidation.mjs +1 -1
  81. package/dist/private/form/useFormValidation.mjs.map +1 -1
  82. package/dist/private/grid/useGridSelectionAnnouncement.cjs.map +1 -1
  83. package/dist/private/grid/useGridSelectionAnnouncement.js.map +1 -1
  84. package/dist/private/grid/useGridSelectionAnnouncement.mjs.map +1 -1
  85. package/dist/private/grid/useGridSelectionCheckbox.cjs.map +1 -1
  86. package/dist/private/grid/useGridSelectionCheckbox.js.map +1 -1
  87. package/dist/private/grid/useGridSelectionCheckbox.mjs.map +1 -1
  88. package/dist/private/grid/useHighlightSelectionDescription.cjs.map +1 -1
  89. package/dist/private/grid/useHighlightSelectionDescription.js.map +1 -1
  90. package/dist/private/grid/useHighlightSelectionDescription.mjs.map +1 -1
  91. package/dist/private/gridlist/useGridList.cjs +2 -1
  92. package/dist/private/gridlist/useGridList.cjs.map +1 -1
  93. package/dist/private/gridlist/useGridList.js +2 -1
  94. package/dist/private/gridlist/useGridList.js.map +1 -1
  95. package/dist/private/gridlist/useGridList.mjs +2 -1
  96. package/dist/private/gridlist/useGridList.mjs.map +1 -1
  97. package/dist/private/gridlist/useGridListItem.cjs +62 -21
  98. package/dist/private/gridlist/useGridListItem.cjs.map +1 -1
  99. package/dist/private/gridlist/useGridListItem.js +63 -22
  100. package/dist/private/gridlist/useGridListItem.js.map +1 -1
  101. package/dist/private/gridlist/useGridListItem.mjs +62 -21
  102. package/dist/private/gridlist/useGridListItem.mjs.map +1 -1
  103. package/dist/private/interactions/createEventHandler.cjs +3 -0
  104. package/dist/private/interactions/createEventHandler.cjs.map +1 -1
  105. package/dist/private/interactions/createEventHandler.js +3 -0
  106. package/dist/private/interactions/createEventHandler.js.map +1 -1
  107. package/dist/private/interactions/createEventHandler.mjs +3 -0
  108. package/dist/private/interactions/createEventHandler.mjs.map +1 -1
  109. package/dist/private/interactions/useFocusVisible.cjs +16 -5
  110. package/dist/private/interactions/useFocusVisible.cjs.map +1 -1
  111. package/dist/private/interactions/useFocusVisible.js +16 -5
  112. package/dist/private/interactions/useFocusVisible.js.map +1 -1
  113. package/dist/private/interactions/useFocusVisible.mjs +16 -5
  114. package/dist/private/interactions/useFocusVisible.mjs.map +1 -1
  115. package/dist/private/menu/useMenu.cjs.map +1 -1
  116. package/dist/private/menu/useMenu.js.map +1 -1
  117. package/dist/private/menu/useMenu.mjs.map +1 -1
  118. package/dist/private/menu/useMenuItem.cjs +1 -1
  119. package/dist/private/menu/useMenuItem.cjs.map +1 -1
  120. package/dist/private/menu/useMenuItem.js +1 -1
  121. package/dist/private/menu/useMenuItem.js.map +1 -1
  122. package/dist/private/menu/useMenuItem.mjs +1 -1
  123. package/dist/private/menu/useMenuItem.mjs.map +1 -1
  124. package/dist/private/menu/useMenuTrigger.cjs.map +1 -1
  125. package/dist/private/menu/useMenuTrigger.js.map +1 -1
  126. package/dist/private/menu/useMenuTrigger.mjs.map +1 -1
  127. package/dist/private/menu/utils.cjs.map +1 -1
  128. package/dist/private/menu/utils.js.map +1 -1
  129. package/dist/private/menu/utils.mjs.map +1 -1
  130. package/dist/private/numberfield/useNumberField.cjs.map +1 -1
  131. package/dist/private/numberfield/useNumberField.js.map +1 -1
  132. package/dist/private/numberfield/useNumberField.mjs.map +1 -1
  133. package/dist/private/overlays/DismissButton.cjs.map +1 -1
  134. package/dist/private/overlays/DismissButton.js.map +1 -1
  135. package/dist/private/overlays/DismissButton.mjs.map +1 -1
  136. package/dist/private/overlays/calculatePosition.cjs +7 -7
  137. package/dist/private/overlays/calculatePosition.cjs.map +1 -1
  138. package/dist/private/overlays/calculatePosition.js +7 -7
  139. package/dist/private/overlays/calculatePosition.js.map +1 -1
  140. package/dist/private/overlays/calculatePosition.mjs +7 -7
  141. package/dist/private/overlays/calculatePosition.mjs.map +1 -1
  142. package/dist/private/overlays/useOverlayPosition.cjs +3 -2
  143. package/dist/private/overlays/useOverlayPosition.cjs.map +1 -1
  144. package/dist/private/overlays/useOverlayPosition.js +3 -2
  145. package/dist/private/overlays/useOverlayPosition.js.map +1 -1
  146. package/dist/private/overlays/useOverlayPosition.mjs +3 -2
  147. package/dist/private/overlays/useOverlayPosition.mjs.map +1 -1
  148. package/dist/private/searchfield/useSearchField.cjs.map +1 -1
  149. package/dist/private/searchfield/useSearchField.js.map +1 -1
  150. package/dist/private/searchfield/useSearchField.mjs.map +1 -1
  151. package/dist/private/select/useSelect.cjs +1 -2
  152. package/dist/private/select/useSelect.cjs.map +1 -1
  153. package/dist/private/select/useSelect.js +1 -2
  154. package/dist/private/select/useSelect.js.map +1 -1
  155. package/dist/private/select/useSelect.mjs +1 -2
  156. package/dist/private/select/useSelect.mjs.map +1 -1
  157. package/dist/private/selection/ListKeyboardDelegate.cjs +31 -3
  158. package/dist/private/selection/ListKeyboardDelegate.cjs.map +1 -1
  159. package/dist/private/selection/ListKeyboardDelegate.js +31 -3
  160. package/dist/private/selection/ListKeyboardDelegate.js.map +1 -1
  161. package/dist/private/selection/ListKeyboardDelegate.mjs +31 -3
  162. package/dist/private/selection/ListKeyboardDelegate.mjs.map +1 -1
  163. package/dist/private/selection/useSelectableCollection.cjs +20 -14
  164. package/dist/private/selection/useSelectableCollection.cjs.map +1 -1
  165. package/dist/private/selection/useSelectableCollection.js +26 -19
  166. package/dist/private/selection/useSelectableCollection.js.map +1 -1
  167. package/dist/private/selection/useSelectableCollection.mjs +20 -14
  168. package/dist/private/selection/useSelectableCollection.mjs.map +1 -1
  169. package/dist/private/selection/useTypeSelect.cjs +50 -18
  170. package/dist/private/selection/useTypeSelect.cjs.map +1 -1
  171. package/dist/private/selection/useTypeSelect.js +51 -19
  172. package/dist/private/selection/useTypeSelect.js.map +1 -1
  173. package/dist/private/selection/useTypeSelect.mjs +51 -19
  174. package/dist/private/selection/useTypeSelect.mjs.map +1 -1
  175. package/dist/private/spinbutton/useSpinButton.cjs.map +1 -1
  176. package/dist/private/spinbutton/useSpinButton.js.map +1 -1
  177. package/dist/private/spinbutton/useSpinButton.mjs.map +1 -1
  178. package/dist/private/steplist/useStepList.cjs.map +1 -1
  179. package/dist/private/steplist/useStepList.js.map +1 -1
  180. package/dist/private/steplist/useStepList.mjs.map +1 -1
  181. package/dist/private/table/useTable.cjs.map +1 -1
  182. package/dist/private/table/useTable.js.map +1 -1
  183. package/dist/private/table/useTable.mjs.map +1 -1
  184. package/dist/private/table/useTableColumnHeader.cjs.map +1 -1
  185. package/dist/private/table/useTableColumnHeader.js.map +1 -1
  186. package/dist/private/table/useTableColumnHeader.mjs.map +1 -1
  187. package/dist/private/table/useTableColumnResize.cjs.map +1 -1
  188. package/dist/private/table/useTableColumnResize.js.map +1 -1
  189. package/dist/private/table/useTableColumnResize.mjs.map +1 -1
  190. package/dist/private/table/useTableRow.cjs.map +1 -1
  191. package/dist/private/table/useTableRow.js.map +1 -1
  192. package/dist/private/table/useTableRow.mjs.map +1 -1
  193. package/dist/private/table/useTableSelectionCheckbox.cjs.map +1 -1
  194. package/dist/private/table/useTableSelectionCheckbox.js.map +1 -1
  195. package/dist/private/table/useTableSelectionCheckbox.mjs.map +1 -1
  196. package/dist/private/tabs/TabsKeyboardDelegate.cjs +2 -2
  197. package/dist/private/tabs/TabsKeyboardDelegate.cjs.map +1 -1
  198. package/dist/private/tabs/TabsKeyboardDelegate.js +2 -2
  199. package/dist/private/tabs/TabsKeyboardDelegate.js.map +1 -1
  200. package/dist/private/tabs/TabsKeyboardDelegate.mjs +2 -2
  201. package/dist/private/tabs/TabsKeyboardDelegate.mjs.map +1 -1
  202. package/dist/private/tag/useTag.cjs.map +1 -1
  203. package/dist/private/tag/useTag.js.map +1 -1
  204. package/dist/private/tag/useTag.mjs.map +1 -1
  205. package/dist/private/toast/useToast.cjs.map +1 -1
  206. package/dist/private/toast/useToast.js.map +1 -1
  207. package/dist/private/toast/useToast.mjs.map +1 -1
  208. package/dist/private/toast/useToastRegion.cjs.map +1 -1
  209. package/dist/private/toast/useToastRegion.js.map +1 -1
  210. package/dist/private/toast/useToastRegion.mjs.map +1 -1
  211. package/dist/private/toolbar/useToolbar.cjs +0 -1
  212. package/dist/private/toolbar/useToolbar.cjs.map +1 -1
  213. package/dist/private/toolbar/useToolbar.js +0 -1
  214. package/dist/private/toolbar/useToolbar.js.map +1 -1
  215. package/dist/private/toolbar/useToolbar.mjs +0 -1
  216. package/dist/private/toolbar/useToolbar.mjs.map +1 -1
  217. package/dist/private/tree/useTree.cjs.map +1 -1
  218. package/dist/private/tree/useTree.js.map +1 -1
  219. package/dist/private/tree/useTree.mjs.map +1 -1
  220. package/dist/private/tree/useTreeItem.cjs.map +1 -1
  221. package/dist/private/tree/useTreeItem.js.map +1 -1
  222. package/dist/private/tree/useTreeItem.mjs.map +1 -1
  223. package/dist/private/utils/isElementVisible.cjs +1 -1
  224. package/dist/private/utils/isElementVisible.cjs.map +1 -1
  225. package/dist/private/utils/isElementVisible.js +1 -1
  226. package/dist/private/utils/isElementVisible.js.map +1 -1
  227. package/dist/private/utils/isElementVisible.mjs +1 -1
  228. package/dist/private/utils/isElementVisible.mjs.map +1 -1
  229. package/dist/private/utils/isFocusable.cjs +3 -1
  230. package/dist/private/utils/isFocusable.cjs.map +1 -1
  231. package/dist/private/utils/isFocusable.js +3 -1
  232. package/dist/private/utils/isFocusable.js.map +1 -1
  233. package/dist/private/utils/isFocusable.mjs +3 -1
  234. package/dist/private/utils/isFocusable.mjs.map +1 -1
  235. package/dist/types/src/dnd/utils.d.ts +2 -2
  236. package/dist/types/src/gridlist/useGridList.d.ts +7 -0
  237. package/dist/types/src/menu/useMenu.d.ts +1 -1
  238. package/dist/types/src/menu/utils.d.ts +1 -1
  239. package/dist/types/src/overlays/calculatePosition.d.ts +1 -0
  240. package/dist/types/src/overlays/useOverlayPosition.d.ts +8 -0
  241. package/dist/types/src/selection/ListKeyboardDelegate.d.ts +1 -0
  242. package/dist/types/src/selection/useSelectableCollection.d.ts +7 -0
  243. package/dist/types/src/tree/useTree.d.ts +1 -1
  244. package/package.json +4 -4
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;;;;;;;;;;;;AAgIM,SAAS,0CACd,OAAwC;IAExC,IAAI,EACF,kBAAkB,OAAO,EACzB,kBAAkB,QAAQ,OAC1B,GAAG,aACH,YAAY,wBACZ,kBAAkB,+BAClB,yBAAyB,0BACzB,oBAAoB,0BACpB,oBAAoB,iCACpB,gBAAgB,QAAQ,iBAAiB,KAAK,8BAC9C,oBAAoB,8BACpB,qBAAqB,uBACrB,sBAAsB,kBACtB,kFAAkF;IAClF,YAAY,mBACZ,eAAe,UAChB,GAAG;IACJ,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,yCAAQ;IAC1B,IAAI,SAAS,CAAA,GAAA,yCAAQ;IAErB,IAAI,YAAY,CAAC;QACf,6GAA6G;QAC7G,IAAI,EAAE,MAAM,IAAI,EAAE,GAAG,KAAK,OACxB,EAAE,cAAc;QAGlB,uEAAuE;QACvE,oDAAoD;QACpD,IAAI,CAAC,IAAI,OAAO,IAAI,CAAC,CAAA,GA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IAAI,OAAO,IAAI;IAG9C,IAAI,eAAe,CAAA,GAAA,yCAAc,EAAE,QAAQ,UAAU;IACrD,OAAO;QACL,iBAAiB,CAAA,GAAA,yCAAS,EAAE,UAAU;sBACpC;YACA,mBAAmB;QACrB;IACF;AACF","sources":["packages/react-aria/src/selection/useSelectableCollection.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 {CLEAR_FOCUS_EVENT, FOCUS_EVENT} from '../utils/constants';\n\nimport {dispatchVirtualFocus, moveVirtualFocus} from '../focus/virtualFocus';\nimport {\n DOMAttributes,\n FocusableElement,\n FocusStrategy,\n Key,\n KeyboardDelegate,\n RefObject\n} from '@react-types/shared';\nimport {flushSync} from 'react-dom';\nimport {FocusEvent, KeyboardEvent, useEffect, useRef} from 'react';\nimport {focusSafely} from '../interactions/focusSafely';\nimport {focusWithoutScrolling} from '../utils/focusWithoutScrolling';\nimport {\n getActiveElement,\n getEventTarget,\n isFocusWithin,\n nodeContains\n} from '../utils/shadowdom/DOMFunctions';\nimport {getFocusableTreeWalker} from '../focus/FocusScope';\nimport {getInteractionModality} from '../interactions/useFocusVisible';\nimport {getItemElement, isNonContiguousSelectionModifier, useCollectionId} from './utils';\nimport {isCtrlKeyPressed} from '../utils/keyboard';\nimport {isTabbable} from '../utils/isFocusable';\nimport {mergeProps} from '../utils/mergeProps';\nimport {MultipleSelectionManager} from 'react-stately/useMultipleSelectionState';\nimport {scrollIntoView, scrollIntoViewport} from '../utils/scrollIntoView';\nimport {useEvent} from '../utils/useEvent';\nimport {useLocale} from '../i18n/I18nProvider';\nimport {useRouter} from '../utils/openLink';\nimport {useTypeSelect} from './useTypeSelect';\nimport {useUpdateLayoutEffect} from '../utils/useUpdateLayoutEffect';\n\nexport interface AriaSelectableCollectionOptions {\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 | null>;\n /**\n * Whether the collection or one of its items should be automatically focused upon render.\n *\n * @default false\n */\n autoFocus?: boolean | FocusStrategy;\n /**\n * Whether focus should wrap around when the end/start is reached.\n *\n * @default false\n */\n shouldFocusWrap?: boolean;\n /**\n * Whether the collection allows empty selection.\n *\n * @default false\n */\n disallowEmptySelection?: boolean;\n /**\n * Whether the collection allows the user to select all items via keyboard shortcut.\n *\n * @default false\n */\n disallowSelectAll?: boolean;\n /**\n * Whether pressing the Escape should clear selection in the collection or not.\n *\n * @default 'clearSelection'\n */\n escapeKeyBehavior?: 'clearSelection' | 'none';\n /**\n * Whether selection should occur automatically on focus.\n *\n * @default false\n */\n selectOnFocus?: boolean;\n /**\n * Whether typeahead is disabled.\n *\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\n * non-virtualized collections. If not provided, defaults to the collection ref.\n */\n scrollRef?: RefObject<HTMLElement | null>;\n /**\n * The behavior of links in the collection.\n * - 'action': link behaves like onAction.\n * - 'selection': link follows selection interactions (e.g. if URL drives selection).\n * - 'override': links override all other interactions (link items are not selectable).\n *\n * @default 'action'\n */\n linkBehavior?: 'action' | 'selection' | 'override';\n}\n\nexport interface SelectableCollectionAria {\n /** Props for the collection element. */\n collectionProps: DOMAttributes;\n}\n\n/**\n * Handles interactions with selectable collections.\n */\nexport function useSelectableCollection(\n options: AriaSelectableCollectionOptions\n): SelectableCollectionAria {\n let {\n selectionManager: manager,\n keyboardDelegate: delegate,\n ref,\n autoFocus = false,\n shouldFocusWrap = false,\n disallowEmptySelection = false,\n disallowSelectAll = false,\n escapeKeyBehavior = 'clearSelection',\n selectOnFocus = manager.selectionBehavior === 'replace',\n disallowTypeAhead = false,\n shouldUseVirtualFocus,\n allowsTabNavigation = false,\n // If no scrollRef is provided, assume the collection ref is the scrollable region\n scrollRef = ref,\n linkBehavior = 'action'\n } = options;\n let {direction} = useLocale();\n let router = useRouter();\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 || !nodeContains(ref.current, getEventTarget(e) as Element)) {\n return;\n }\n\n const navigateToKey = (key: Key | undefined, childFocus?: FocusStrategy) => {\n if (key != null) {\n if (\n manager.isLink(key) &&\n linkBehavior === 'selection' &&\n selectOnFocus &&\n !isNonContiguousSelectionModifier(e)\n ) {\n // Set focused key and re-render synchronously to bring item into view if needed.\n flushSync(() => {\n manager.setFocusedKey(key, childFocus);\n });\n\n let item = getItemElement(ref, key);\n let itemProps = manager.getItemProps(key);\n if (item) {\n router.open(item, e, itemProps.href, itemProps.routerOptions);\n }\n\n return;\n }\n\n manager.setFocusedKey(key, childFocus);\n\n if (manager.isLink(key) && linkBehavior === 'override') {\n return;\n }\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 let nextKey =\n manager.focusedKey != null\n ? delegate.getKeyBelow?.(manager.focusedKey)\n : delegate.getFirstKey?.();\n if (nextKey == null && shouldFocusWrap) {\n nextKey = delegate.getFirstKey?.(manager.focusedKey);\n }\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey);\n }\n }\n break;\n }\n case 'ArrowUp': {\n if (delegate.getKeyAbove) {\n let nextKey =\n manager.focusedKey != null\n ? delegate.getKeyAbove?.(manager.focusedKey)\n : delegate.getLastKey?.();\n if (nextKey == null && shouldFocusWrap) {\n nextKey = delegate.getLastKey?.(manager.focusedKey);\n }\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey);\n }\n }\n break;\n }\n case 'ArrowLeft': {\n if (delegate.getKeyLeftOf) {\n let nextKey: Key | undefined | null =\n manager.focusedKey != null\n ? delegate.getKeyLeftOf?.(manager.focusedKey)\n : delegate.getFirstKey?.();\n if (nextKey == null && shouldFocusWrap) {\n nextKey =\n direction === 'rtl'\n ? delegate.getFirstKey?.(manager.focusedKey)\n : delegate.getLastKey?.(manager.focusedKey);\n }\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey, direction === 'rtl' ? 'first' : 'last');\n }\n }\n break;\n }\n case 'ArrowRight': {\n if (delegate.getKeyRightOf) {\n let nextKey: Key | undefined | null =\n manager.focusedKey != null\n ? delegate.getKeyRightOf?.(manager.focusedKey)\n : delegate.getFirstKey?.();\n if (nextKey == null && shouldFocusWrap) {\n nextKey =\n direction === 'rtl'\n ? delegate.getLastKey?.(manager.focusedKey)\n : delegate.getFirstKey?.(manager.focusedKey);\n }\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey, direction === 'rtl' ? 'last' : 'first');\n }\n }\n break;\n }\n case 'Home':\n if (delegate.getFirstKey) {\n if (manager.focusedKey === null && e.shiftKey) {\n return;\n }\n e.preventDefault();\n let firstKey: Key | null = delegate.getFirstKey(manager.focusedKey, isCtrlKeyPressed(e));\n manager.setFocusedKey(firstKey);\n if (firstKey != null) {\n if (isCtrlKeyPressed(e) && e.shiftKey && manager.selectionMode === 'multiple') {\n manager.extendSelection(firstKey);\n } else if (selectOnFocus) {\n manager.replaceSelection(firstKey);\n }\n }\n }\n break;\n case 'End':\n if (delegate.getLastKey) {\n if (manager.focusedKey === null && e.shiftKey) {\n return;\n }\n e.preventDefault();\n let lastKey = delegate.getLastKey(manager.focusedKey, isCtrlKeyPressed(e));\n manager.setFocusedKey(lastKey);\n if (lastKey != null) {\n if (isCtrlKeyPressed(e) && e.shiftKey && manager.selectionMode === 'multiple') {\n manager.extendSelection(lastKey);\n } else if (selectOnFocus) {\n manager.replaceSelection(lastKey);\n }\n }\n }\n break;\n case 'PageDown':\n if (delegate.getKeyPageBelow && manager.focusedKey != null) {\n let nextKey = delegate.getKeyPageBelow(manager.focusedKey);\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey);\n }\n }\n break;\n case 'PageUp':\n if (delegate.getKeyPageAbove && manager.focusedKey != null) {\n let nextKey = delegate.getKeyPageAbove(manager.focusedKey);\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey);\n }\n }\n break;\n case 'a':\n if (\n isCtrlKeyPressed(e) &&\n manager.selectionMode === 'multiple' &&\n disallowSelectAll !== true\n ) {\n e.preventDefault();\n manager.selectAll();\n }\n break;\n case 'Escape':\n if (\n escapeKeyBehavior === 'clearSelection' &&\n !disallowEmptySelection &&\n manager.selectedKeys.size !== 0\n ) {\n e.stopPropagation();\n e.preventDefault();\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: FocusableElement | undefined = undefined;\n let last: FocusableElement;\n do {\n last = walker.lastChild() as FocusableElement;\n // oxlint-disable-next-line max-depth\n if (last) {\n next = last;\n }\n } while (last);\n\n // If the active element is NOT tabbable but is contained by an element that IS tabbable (aka the cell), the browser will actually move focus to\n // the containing element. We need to special case this so that tab will move focus out of the grid instead of looping between\n // focusing the containing cell and back to the non-tabbable child element\n let activeElement = getActiveElement();\n if (next && (!isFocusWithin(next) || (activeElement && !isTabbable(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 /// TODO: should this happen all the time??\n let scrollPos = useRef({top: 0, left: 0});\n useEvent(scrollRef, 'scroll', () => {\n scrollPos.current = {\n top: scrollRef.current?.scrollTop ?? 0,\n left: scrollRef.current?.scrollLeft ?? 0\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 (!nodeContains(e.currentTarget, getEventTarget(e))) {\n manager.setFocused(false);\n }\n\n return;\n }\n\n // Focus events can bubble through portals. Ignore these events.\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n manager.setFocused(true);\n if (manager.focusedKey == null) {\n let navigateToKey = (key: Key | undefined | null) => {\n if (key != null) {\n manager.setFocusedKey(key);\n if (selectOnFocus && !manager.isSelected(key)) {\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 (\n relatedTarget &&\n e.currentTarget.compareDocumentPosition(relatedTarget) & Node.DOCUMENT_POSITION_FOLLOWING\n ) {\n navigateToKey(manager.lastSelectedKey ?? delegate.getLastKey?.());\n } else {\n navigateToKey(manager.firstSelectedKey ?? delegate.getFirstKey?.());\n }\n } else if (scrollRef.current) {\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\n if (manager.focusedKey != null && scrollRef.current) {\n // Refocus and scroll the focused item into view if it exists within the scrollable region.\n let element = getItemElement(ref, manager.focusedKey);\n if (element instanceof HTMLElement) {\n // This prevents a flash of focus on the first/last element in the collection, or the collection itself.\n if (!isFocusWithin(element) && !shouldUseVirtualFocus) {\n focusWithoutScrolling(element);\n }\n\n let modality = getInteractionModality();\n if (modality === 'keyboard') {\n scrollIntoViewport(element, {containingElement: ref.current});\n }\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 (!nodeContains(e.currentTarget, e.relatedTarget as HTMLElement)) {\n manager.setFocused(false);\n }\n };\n\n // Ref to track whether the first item in the collection should be automatically focused. Specifically used for autocomplete when user types\n // to focus the first key AFTER the collection updates.\n // TODO: potentially expand the usage of this\n let shouldVirtualFocusFirst = useRef(false);\n // Add event listeners for custom virtual events. These handle updating the focused key in response to various keyboard events\n // at the autocomplete level\n // TODO: fix type later\n useEvent(\n ref,\n FOCUS_EVENT,\n !shouldUseVirtualFocus\n ? undefined\n : (e: any) => {\n let {detail} = e;\n e.stopPropagation();\n manager.setFocused(true);\n // If the user is typing forwards, autofocus the first option in the list.\n if (detail?.focusStrategy === 'first') {\n shouldVirtualFocusFirst.current = true;\n }\n }\n );\n\n // update active descendant\n useUpdateLayoutEffect(() => {\n if (shouldVirtualFocusFirst.current) {\n let keyToFocus = delegate.getFirstKey?.() ?? null;\n\n // If no focusable items exist in the list, make sure to clear any activedescendant that may still exist and move focus back to\n // the original active element (e.g. the autocomplete input)\n if (keyToFocus == null) {\n let previousActiveElement = getActiveElement();\n moveVirtualFocus(ref.current);\n dispatchVirtualFocus(previousActiveElement!, null);\n\n // If there wasn't a focusable key but the collection had items, then that means we aren't in an intermediate load state and all keys are disabled.\n // Reset shouldVirtualFocusFirst so that we don't erronously autofocus an item when the collection is filtered again.\n if (manager.collection.size > 0) {\n shouldVirtualFocusFirst.current = false;\n }\n } else {\n manager.setFocusedKey(keyToFocus);\n // Only set shouldVirtualFocusFirst to false if we've successfully set the first key as the focused key\n // If there wasn't a key to focus, we might be in a temporary loading state so we'll want to still focus the first key\n // after the collection updates after load\n shouldVirtualFocusFirst.current = false;\n }\n }\n }, [manager.collection]);\n\n // reset focus first flag\n useUpdateLayoutEffect(() => {\n // If user causes the focused key to change in any other way, clear shouldVirtualFocusFirst so we don't\n // accidentally move focus from under them. Skip this if the collection was empty because we might be in a load\n // state and will still want to focus the first item after load\n if (manager.collection.size > 0) {\n shouldVirtualFocusFirst.current = false;\n }\n }, [manager.focusedKey]);\n\n useEvent(\n ref,\n CLEAR_FOCUS_EVENT,\n !shouldUseVirtualFocus\n ? undefined\n : (e: any) => {\n e.stopPropagation();\n manager.setFocused(false);\n if (e.detail?.clearFocusKey) {\n manager.setFocusedKey(null);\n }\n }\n );\n\n const autoFocusRef = useRef(autoFocus);\n const didAutoFocusRef = useRef(false);\n useEffect(() => {\n if (autoFocusRef.current) {\n let focusedKey: Key | null = null;\n\n // Check focus strategy to determine which item to focus\n if (autoFocus === 'first') {\n focusedKey = delegate.getFirstKey?.() ?? null;\n }\n if (autoFocus === 'last') {\n focusedKey = delegate.getLastKey?.() ?? null;\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 for (let key of selectedKeys) {\n if (manager.canSelectItem(key)) {\n focusedKey = key;\n break;\n }\n }\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 && ref.current) {\n focusSafely(ref.current);\n }\n\n // Wait until the collection has items to autofocus.\n if (manager.collection.size > 0) {\n autoFocusRef.current = false;\n didAutoFocusRef.current = true;\n }\n }\n });\n\n // Scroll the focused element into view when the focusedKey changes.\n let lastFocusedKey = useRef(manager.focusedKey);\n let raf = useRef<number | null>(null);\n useEffect(() => {\n if (\n manager.isFocused &&\n manager.focusedKey != null &&\n (manager.focusedKey !== lastFocusedKey.current || didAutoFocusRef.current) &&\n scrollRef.current &&\n ref.current\n ) {\n let modality = getInteractionModality();\n let element = getItemElement(ref, manager.focusedKey);\n if (!(element instanceof HTMLElement)) {\n // If item element wasn't found, return early (don't update autoFocusRef and lastFocusedKey).\n // The collection may initially be empty (e.g. virtualizer), so wait until the element exists.\n return;\n }\n\n if (modality === 'keyboard' || didAutoFocusRef.current) {\n if (raf.current) {\n cancelAnimationFrame(raf.current);\n }\n\n raf.current = requestAnimationFrame(() => {\n if (scrollRef.current) {\n scrollIntoView(scrollRef.current, element);\n // Avoid scroll in iOS VO, since it may cause overlay to close (i.e. RAC submenu)\n if (modality !== 'virtual') {\n scrollIntoViewport(element, {containingElement: ref.current});\n }\n }\n });\n }\n }\n\n // If the focused key becomes null (e.g. the last item is deleted), focus the whole collection.\n if (\n !shouldUseVirtualFocus &&\n manager.isFocused &&\n manager.focusedKey == null &&\n lastFocusedKey.current != null &&\n ref.current\n ) {\n focusSafely(ref.current);\n }\n\n lastFocusedKey.current = manager.focusedKey;\n didAutoFocusRef.current = false;\n });\n\n useEffect(() => {\n return () => {\n if (raf.current) {\n cancelAnimationFrame(raf.current);\n }\n };\n }, []);\n\n // Intercept FocusScope restoration since virtualized collections can reuse DOM nodes.\n useEvent(ref, 'react-aria-focus-scope-restore', e => {\n e.preventDefault();\n manager.setFocused(true);\n });\n\n let handlers = {\n onKeyDown,\n onFocus,\n onBlur,\n onMouseDown(e) {\n // Ignore events that bubbled through portals.\n if (scrollRef.current === getEventTarget(e)) {\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 let tabIndex: number | undefined = undefined;\n if (!shouldUseVirtualFocus) {\n tabIndex = manager.focusedKey == null ? 0 : -1;\n }\n\n let collectionId = useCollectionId(manager.collection);\n return {\n collectionProps: mergeProps(handlers, {\n tabIndex,\n 'data-collection': collectionId\n })\n };\n}\n"],"names":[],"version":3,"file":"useSelectableCollection.mjs.map"}
1
+ {"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;;;;;;;;;;;;AAuIM,SAAS,0CACd,OAAwC;IAExC,IAAI,EACF,kBAAkB,OAAO,EACzB,kBAAkB,QAAQ,OAC1B,GAAG,aACH,YAAY,wBACZ,kBAAkB,+BAClB,yBAAyB,0BACzB,oBAAoB,0BACpB,oBAAoB,iCACpB,gBAAgB,QAAQ,iBAAiB,KAAK,8BAC9C,oBAAoB,8BACpB,qBAAqB,uBACrB,sBAAsB,kBACtB,kFAAkF;IAClF,YAAY,mBACZ,eAAe,iCACf,qBAAqB,EACtB,GAAG;IACJ,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,yCAAQ;IAC1B,IAAI,SAAS,CAAA,GAAA,yCAAQ;IAErB,IAAI,YAAY,CAAC;QACf,6GAA6G;QAC7G,IAAI,EAAE,MAAM,IAAI,EAAE,GAAG,KAAK,OACxB,EAAE,cAAc;QAGlB,uEAAuE;QACvE,oDAAoD;QACpD,IAAI,CAAC,IAAI,OAAO,IAAI,CAAC,CAAA,GAAA,yCAAW,EAAE,IAAI,OAAO,EAAE,CAAA,GAAA,yCAAa,EAAE,KAC5D;QAGF,MAAM,gBAAgB,CAAC,KAAsB;YAC3C,IAAI,OAAO,MAAM;gBACf,IACE,QAAQ,MAAM,CAAC,QACf,iBAAiB,eACjB,iBACA,CAAC,CAAA,GAAA,yCAA+B,EAAE,IAClC;oBACA,iFAAiF;oBACjF,CAAA,GAAA,gBAAQ,EAAE;wBACR,QAAQ,aAAa,CAAC,KAAK;oBAC7B;oBAEA,IAA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AE,UAAU;sBACpC;YACA,mBAAmB;QACrB;IACF;AACF","sources":["packages/react-aria/src/selection/useSelectableCollection.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 {CLEAR_FOCUS_EVENT, FOCUS_EVENT} from '../utils/constants';\n\nimport {dispatchVirtualFocus, moveVirtualFocus} from '../focus/virtualFocus';\nimport {\n DOMAttributes,\n FocusableElement,\n FocusStrategy,\n Key,\n KeyboardDelegate,\n RefObject\n} from '@react-types/shared';\nimport {flushSync} from 'react-dom';\nimport {FocusEvent, KeyboardEvent, useEffect, useRef} from 'react';\nimport {focusSafely} from '../interactions/focusSafely';\nimport {focusWithoutScrolling} from '../utils/focusWithoutScrolling';\nimport {\n getActiveElement,\n getEventTarget,\n isFocusWithin,\n nodeContains\n} from '../utils/shadowdom/DOMFunctions';\nimport {getFocusableTreeWalker} from '../focus/FocusScope';\nimport {getInteractionModality} from '../interactions/useFocusVisible';\nimport {getItemElement, isNonContiguousSelectionModifier, useCollectionId} from './utils';\nimport {isCtrlKeyPressed} from '../utils/keyboard';\nimport {isTabbable} from '../utils/isFocusable';\nimport {mergeProps} from '../utils/mergeProps';\nimport {MultipleSelectionManager} from 'react-stately/useMultipleSelectionState';\nimport {scrollIntoView, scrollIntoViewport} from '../utils/scrollIntoView';\nimport {useEvent} from '../utils/useEvent';\nimport {useLocale} from '../i18n/I18nProvider';\nimport {useRouter} from '../utils/openLink';\nimport {useTypeSelect} from './useTypeSelect';\nimport {useUpdateLayoutEffect} from '../utils/useUpdateLayoutEffect';\n\nexport interface AriaSelectableCollectionOptions {\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 | null>;\n /**\n * Whether the collection or one of its items should be automatically focused upon render.\n *\n * @default false\n */\n autoFocus?: boolean | FocusStrategy;\n /**\n * Whether focus should wrap around when the end/start is reached.\n *\n * @default false\n */\n shouldFocusWrap?: boolean;\n /**\n * Whether the collection allows empty selection.\n *\n * @default false\n */\n disallowEmptySelection?: boolean;\n /**\n * Whether the collection allows the user to select all items via keyboard shortcut.\n *\n * @default false\n */\n disallowSelectAll?: boolean;\n /**\n * Whether pressing the Escape should clear selection in the collection or not.\n *\n * @default 'clearSelection'\n */\n escapeKeyBehavior?: 'clearSelection' | 'none';\n /**\n * Whether selection should occur automatically on focus.\n *\n * @default false\n */\n selectOnFocus?: boolean;\n /**\n * Whether typeahead is disabled.\n *\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\n * non-virtualized collections. If not provided, defaults to the collection ref.\n */\n scrollRef?: RefObject<HTMLElement | null>;\n /**\n * The behavior of links in the collection.\n * - 'action': link behaves like onAction.\n * - 'selection': link follows selection interactions (e.g. if URL drives selection).\n * - 'override': links override all other interactions (link items are not selectable).\n *\n * @default 'action'\n */\n linkBehavior?: 'action' | 'selection' | 'override';\n /**\n * Which item in the collection to focus when tabbing into the collection. Overrides default\n * roving tab index like behavior.\n *\n * @private\n */\n UNSTABLE_focusOnEntry?: 'first' | 'last';\n}\n\nexport interface SelectableCollectionAria {\n /** Props for the collection element. */\n collectionProps: DOMAttributes;\n}\n\n/**\n * Handles interactions with selectable collections.\n */\nexport function useSelectableCollection(\n options: AriaSelectableCollectionOptions\n): SelectableCollectionAria {\n let {\n selectionManager: manager,\n keyboardDelegate: delegate,\n ref,\n autoFocus = false,\n shouldFocusWrap = false,\n disallowEmptySelection = false,\n disallowSelectAll = false,\n escapeKeyBehavior = 'clearSelection',\n selectOnFocus = manager.selectionBehavior === 'replace',\n disallowTypeAhead = false,\n shouldUseVirtualFocus,\n allowsTabNavigation = false,\n // If no scrollRef is provided, assume the collection ref is the scrollable region\n scrollRef = ref,\n linkBehavior = 'action',\n UNSTABLE_focusOnEntry\n } = options;\n let {direction} = useLocale();\n let router = useRouter();\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 || !nodeContains(ref.current, getEventTarget(e) as Element)) {\n return;\n }\n\n const navigateToKey = (key: Key | undefined, childFocus?: FocusStrategy) => {\n if (key != null) {\n if (\n manager.isLink(key) &&\n linkBehavior === 'selection' &&\n selectOnFocus &&\n !isNonContiguousSelectionModifier(e)\n ) {\n // Set focused key and re-render synchronously to bring item into view if needed.\n flushSync(() => {\n manager.setFocusedKey(key, childFocus);\n });\n\n let item = getItemElement(ref, key);\n let itemProps = manager.getItemProps(key);\n if (item) {\n router.open(item, e, itemProps.href, itemProps.routerOptions);\n }\n\n return;\n }\n\n manager.setFocusedKey(key, childFocus);\n\n if (manager.isLink(key) && linkBehavior === 'override') {\n return;\n }\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 let nextKey =\n manager.focusedKey != null\n ? delegate.getKeyBelow?.(manager.focusedKey)\n : delegate.getFirstKey?.();\n if (nextKey == null && shouldFocusWrap) {\n nextKey = delegate.getFirstKey?.(manager.focusedKey);\n }\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey);\n }\n }\n break;\n }\n case 'ArrowUp': {\n if (delegate.getKeyAbove) {\n let nextKey =\n manager.focusedKey != null\n ? delegate.getKeyAbove?.(manager.focusedKey)\n : delegate.getLastKey?.();\n if (nextKey == null && shouldFocusWrap) {\n nextKey = delegate.getLastKey?.(manager.focusedKey);\n }\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey);\n }\n }\n break;\n }\n case 'ArrowLeft': {\n if (delegate.getKeyLeftOf) {\n let nextKey: Key | undefined | null =\n manager.focusedKey != null\n ? delegate.getKeyLeftOf?.(manager.focusedKey)\n : delegate.getFirstKey?.();\n if (nextKey == null && shouldFocusWrap) {\n nextKey =\n direction === 'rtl'\n ? delegate.getFirstKey?.(manager.focusedKey)\n : delegate.getLastKey?.(manager.focusedKey);\n }\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey, direction === 'rtl' ? 'first' : 'last');\n }\n }\n break;\n }\n case 'ArrowRight': {\n if (delegate.getKeyRightOf) {\n let nextKey: Key | undefined | null =\n manager.focusedKey != null\n ? delegate.getKeyRightOf?.(manager.focusedKey)\n : delegate.getFirstKey?.();\n if (nextKey == null && shouldFocusWrap) {\n nextKey =\n direction === 'rtl'\n ? delegate.getLastKey?.(manager.focusedKey)\n : delegate.getFirstKey?.(manager.focusedKey);\n }\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey, direction === 'rtl' ? 'last' : 'first');\n }\n }\n break;\n }\n case 'Home':\n if (delegate.getFirstKey) {\n if (manager.focusedKey === null && e.shiftKey) {\n return;\n }\n\n e.preventDefault();\n let firstKey: Key | null = delegate.getFirstKey(manager.focusedKey, isCtrlKeyPressed(e));\n manager.setFocusedKey(firstKey);\n if (firstKey != null) {\n if (isCtrlKeyPressed(e) && e.shiftKey && manager.selectionMode === 'multiple') {\n manager.extendSelection(firstKey);\n } else if (selectOnFocus) {\n manager.replaceSelection(firstKey);\n }\n }\n }\n break;\n case 'End':\n if (delegate.getLastKey) {\n if (manager.focusedKey === null && e.shiftKey) {\n return;\n }\n e.preventDefault();\n let lastKey = delegate.getLastKey(manager.focusedKey, isCtrlKeyPressed(e));\n manager.setFocusedKey(lastKey);\n if (lastKey != null) {\n if (isCtrlKeyPressed(e) && e.shiftKey && manager.selectionMode === 'multiple') {\n manager.extendSelection(lastKey);\n } else if (selectOnFocus) {\n manager.replaceSelection(lastKey);\n }\n }\n }\n break;\n case 'PageDown':\n if (delegate.getKeyPageBelow && manager.focusedKey != null) {\n let nextKey = delegate.getKeyPageBelow(manager.focusedKey);\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey);\n }\n }\n break;\n case 'PageUp':\n if (delegate.getKeyPageAbove && manager.focusedKey != null) {\n let nextKey = delegate.getKeyPageAbove(manager.focusedKey);\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey);\n }\n }\n break;\n case 'a':\n if (\n isCtrlKeyPressed(e) &&\n manager.selectionMode === 'multiple' &&\n disallowSelectAll !== true\n ) {\n e.preventDefault();\n manager.selectAll();\n }\n break;\n case 'Escape':\n if (\n escapeKeyBehavior === 'clearSelection' &&\n !disallowEmptySelection &&\n manager.selectedKeys.size !== 0\n ) {\n e.stopPropagation();\n e.preventDefault();\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: FocusableElement | undefined = undefined;\n let last: FocusableElement;\n do {\n last = walker.lastChild() as FocusableElement;\n // oxlint-disable-next-line max-depth\n if (last) {\n next = last;\n }\n } while (last);\n\n // If the active element is NOT tabbable but is contained by an element that IS tabbable (aka the cell), the browser will actually move focus to\n // the containing element. We need to special case this so that tab will move focus out of the grid instead of looping between\n // focusing the containing cell and back to the non-tabbable child element\n let activeElement = getActiveElement();\n if (next && (!isFocusWithin(next) || (activeElement && !isTabbable(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 /// TODO: should this happen all the time??\n let scrollPos = useRef({top: 0, left: 0});\n useEvent(scrollRef, 'scroll', () => {\n scrollPos.current = {\n top: scrollRef.current?.scrollTop ?? 0,\n left: scrollRef.current?.scrollLeft ?? 0\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 (!nodeContains(e.currentTarget, getEventTarget(e))) {\n manager.setFocused(false);\n }\n return;\n }\n\n // Focus events can bubble through portals. Ignore these events.\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n let modality = getInteractionModality();\n manager.setFocused(true);\n let navigateToKey = (key: Key | undefined | null) => {\n if (key != null) {\n manager.setFocusedKey(key);\n if (selectOnFocus && !manager.isSelected(key)) {\n manager.replaceSelection(key);\n }\n }\n };\n\n // we need the \"virtual\" modality case checks here because shift tabbing from the prompt field's attachment card back into the\n // thread is a virtual focus event (the tab handler in onKeyDown focuses the ref of the AttachementList aka TagGroup via a focus() call, hence the virtual modality)\n if (UNSTABLE_focusOnEntry && (modality === 'keyboard' || modality === 'virtual')) {\n // always go to the first item in the Thread when tabbing forwards/backwards into the collection\n // since it is probably more important to the user to see the new prompt reply rather than go to the last focused key\n navigateToKey(\n UNSTABLE_focusOnEntry === 'first' ? delegate.getFirstKey?.() : delegate.getLastKey?.()\n );\n } else 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 (\n relatedTarget &&\n e.currentTarget.compareDocumentPosition(relatedTarget) & Node.DOCUMENT_POSITION_FOLLOWING\n ) {\n navigateToKey(manager.lastSelectedKey ?? delegate.getLastKey?.());\n } else {\n navigateToKey(manager.firstSelectedKey ?? delegate.getFirstKey?.());\n }\n } else if (scrollRef.current) {\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\n if (manager.focusedKey != null && scrollRef.current) {\n // Refocus and scroll the focused item into view if it exists within the scrollable region.\n let element = getItemElement(ref, manager.focusedKey);\n if (element instanceof HTMLElement) {\n // This prevents a flash of focus on the first/last element in the collection, or the collection itself.\n if (!isFocusWithin(element) && !shouldUseVirtualFocus) {\n focusWithoutScrolling(element);\n }\n\n if (modality === 'keyboard' || (UNSTABLE_focusOnEntry && modality === 'virtual')) {\n scrollIntoViewport(element, {containingElement: ref.current});\n }\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 (!nodeContains(e.currentTarget, e.relatedTarget as HTMLElement)) {\n manager.setFocused(false);\n }\n };\n\n // Ref to track whether the first item in the collection should be automatically focused. Specifically used for autocomplete when user types\n // to focus the first key AFTER the collection updates.\n // TODO: potentially expand the usage of this\n let shouldVirtualFocusFirst = useRef(false);\n // Add event listeners for custom virtual events. These handle updating the focused key in response to various keyboard events\n // at the autocomplete level\n // TODO: fix type later\n useEvent(\n ref,\n FOCUS_EVENT,\n !shouldUseVirtualFocus\n ? undefined\n : (e: any) => {\n let {detail} = e;\n e.stopPropagation();\n manager.setFocused(true);\n // If the user is typing forwards, autofocus the first option in the list.\n if (detail?.focusStrategy === 'first') {\n shouldVirtualFocusFirst.current = true;\n }\n }\n );\n\n // update active descendant\n let firstKey = delegate.getFirstKey?.() ?? null;\n useUpdateLayoutEffect(() => {\n if (shouldVirtualFocusFirst.current) {\n // If no focusable items exist in the list, make sure to clear any activedescendant that may still exist and move focus back to\n // the original active element (e.g. the autocomplete input)\n if (firstKey == null) {\n let previousActiveElement = getActiveElement();\n moveVirtualFocus(ref.current);\n dispatchVirtualFocus(previousActiveElement!, null);\n\n // If there wasn't a focusable key but the collection had items, then that means we aren't in an intermediate load state and all keys are disabled.\n // Reset shouldVirtualFocusFirst so that we don't erronously autofocus an item when the collection is filtered again.\n if (manager.collection.size > 0) {\n shouldVirtualFocusFirst.current = false;\n }\n } else {\n manager.setFocusedKey(firstKey);\n // Only set shouldVirtualFocusFirst to false if we've successfully set the first key as the focused key\n // If there wasn't a key to focus, we might be in a temporary loading state so we'll want to still focus the first key\n // after the collection updates after load\n shouldVirtualFocusFirst.current = false;\n }\n }\n }, [firstKey, manager.collection.size]);\n\n // reset focus first flag\n useUpdateLayoutEffect(() => {\n // If user causes the focused key to change in any other way, clear shouldVirtualFocusFirst so we don't\n // accidentally move focus from under them. Skip this if the collection was empty because we might be in a load\n // state and will still want to focus the first item after load\n if (manager.collection.size > 0) {\n shouldVirtualFocusFirst.current = false;\n }\n }, [manager.focusedKey]);\n\n useEvent(\n ref,\n CLEAR_FOCUS_EVENT,\n !shouldUseVirtualFocus\n ? undefined\n : (e: any) => {\n e.stopPropagation();\n manager.setFocused(false);\n if (e.detail?.clearFocusKey) {\n manager.setFocusedKey(null);\n }\n }\n );\n\n const autoFocusRef = useRef(autoFocus);\n const didAutoFocusRef = useRef(false);\n useEffect(() => {\n if (autoFocusRef.current) {\n let focusedKey: Key | null = null;\n\n // Check focus strategy to determine which item to focus\n if (autoFocus === 'first') {\n focusedKey = delegate.getFirstKey?.() ?? null;\n }\n if (autoFocus === 'last') {\n focusedKey = delegate.getLastKey?.() ?? null;\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 for (let key of selectedKeys) {\n if (manager.canSelectItem(key)) {\n focusedKey = key;\n break;\n }\n }\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 && ref.current) {\n focusSafely(ref.current);\n }\n\n // Wait until the collection has items to autofocus.\n if (manager.collection.size > 0) {\n autoFocusRef.current = false;\n didAutoFocusRef.current = true;\n }\n }\n });\n\n // Scroll the focused element into view when the focusedKey changes.\n let lastFocusedKey = useRef(manager.focusedKey);\n let raf = useRef<number | null>(null);\n useEffect(() => {\n if (\n manager.isFocused &&\n manager.focusedKey != null &&\n (manager.focusedKey !== lastFocusedKey.current || didAutoFocusRef.current) &&\n scrollRef.current &&\n ref.current\n ) {\n let modality = getInteractionModality();\n let element = getItemElement(ref, manager.focusedKey);\n if (!(element instanceof HTMLElement)) {\n // If item element wasn't found, return early (don't update autoFocusRef and lastFocusedKey).\n // The collection may initially be empty (e.g. virtualizer), so wait until the element exists.\n return;\n }\n\n if (modality === 'keyboard' || didAutoFocusRef.current) {\n if (raf.current) {\n cancelAnimationFrame(raf.current);\n }\n\n raf.current = requestAnimationFrame(() => {\n if (scrollRef.current) {\n scrollIntoView(scrollRef.current, element);\n // Avoid scroll in iOS VO, since it may cause overlay to close (i.e. RAC submenu)\n if (modality !== 'virtual') {\n scrollIntoViewport(element, {containingElement: ref.current});\n }\n }\n });\n }\n }\n\n // If the focused key becomes null (e.g. the last item is deleted), focus the whole collection.\n if (\n !shouldUseVirtualFocus &&\n manager.isFocused &&\n manager.focusedKey == null &&\n lastFocusedKey.current != null &&\n ref.current\n ) {\n focusSafely(ref.current);\n }\n\n lastFocusedKey.current = manager.focusedKey;\n didAutoFocusRef.current = false;\n });\n\n useEffect(() => {\n return () => {\n if (raf.current) {\n cancelAnimationFrame(raf.current);\n }\n };\n }, []);\n\n // Intercept FocusScope restoration since virtualized collections can reuse DOM nodes.\n useEvent(ref, 'react-aria-focus-scope-restore', e => {\n e.preventDefault();\n manager.setFocused(true);\n });\n\n let handlers = {\n onKeyDown,\n onFocus,\n onBlur,\n onMouseDown(e) {\n // Ignore events that bubbled through portals.\n if (scrollRef.current === getEventTarget(e)) {\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 let tabIndex: number | undefined = undefined;\n if (!shouldUseVirtualFocus) {\n tabIndex = manager.focusedKey == null ? 0 : -1;\n }\n\n let collectionId = useCollectionId(manager.collection);\n return {\n collectionProps: mergeProps(handlers, {\n tabIndex,\n 'data-collection': collectionId\n })\n };\n}\n"],"names":[],"version":3,"file":"useSelectableCollection.mjs.map"}
@@ -27,40 +27,72 @@ function $a6299e8d95fc8908$export$e32c88dfddc6e1d8(options) {
27
27
  let state = (0, $h2mV5$react.useRef)({
28
28
  search: '',
29
29
  timeout: undefined
30
- }).current;
31
- let onKeyDown = (e)=>{
32
- let character = $a6299e8d95fc8908$var$getStringForKey(e.key);
33
- if (!character || e.ctrlKey || e.metaKey || !(0, $da02ee888921bc9e$exports.nodeContains)(e.currentTarget, (0, $da02ee888921bc9e$exports.getEventTarget)(e)) || state.search.length === 0 && character === ' ') return;
34
- // Do not propagate the Spacebar event if it's meant to be part of the search.
35
- // When we time out, the search term becomes empty, hence the check on length.
36
- // Trimming is to account for the case of pressing the Spacebar more than once,
37
- // which should cycle through the selection/deselection of the focused item.
38
- if (character === ' ' && state.search.trim().length > 0) {
30
+ });
31
+ let onKeyDownCapture = (e)=>{
32
+ // if we're in the middle of a search, then a spacebar should be treated as a search and we should not propagate the event
33
+ // since we handle this one in a capture phase, we should ignore it in the bubble phase
34
+ if (state.current.search.length > 0 && e.key === ' ') {
39
35
  e.preventDefault();
40
- if (!('continuePropagation' in e)) e.stopPropagation();
36
+ if (!('continuePropagation' in e) || 'continuePropagation' in e && !e.isPropagationStopped()) e.stopPropagation();
37
+ state.current.search += ' ';
38
+ if (keyboardDelegate.getKeyForSearch != null) {
39
+ // Use the delegate to find a key to focus.
40
+ // Prioritize items after the currently focused item, falling back to searching the whole list.
41
+ let key = keyboardDelegate.getKeyForSearch(state.current.search, selectionManager.focusedKey);
42
+ // If no key found, search from the top.
43
+ if (key == null) key = keyboardDelegate.getKeyForSearch(state.current.search);
44
+ if (key != null) {
45
+ selectionManager.setFocusedKey(key);
46
+ if (onTypeSelect) onTypeSelect(key);
47
+ }
48
+ }
49
+ clearTimeout(state.current.timeout);
50
+ state.current.timeout = setTimeout(()=>{
51
+ state.current.search = '';
52
+ }, $a6299e8d95fc8908$var$TYPEAHEAD_DEBOUNCE_WAIT_MS);
41
53
  }
42
- state.search += character;
54
+ };
55
+ let onKeyDown = (e)=>{
56
+ let character = $a6299e8d95fc8908$var$getStringForKey(e.key);
57
+ if (!character || e.ctrlKey || e.metaKey || e.altKey || !(0, $da02ee888921bc9e$exports.nodeContains)(e.currentTarget, (0, $da02ee888921bc9e$exports.getEventTarget)(e)) || state.current.search.length === 0 && character === ' ') return;
58
+ state.current.search += character;
43
59
  if (keyboardDelegate.getKeyForSearch != null) {
44
60
  // Use the delegate to find a key to focus.
45
61
  // Prioritize items after the currently focused item, falling back to searching the whole list.
46
- let key = keyboardDelegate.getKeyForSearch(state.search, selectionManager.focusedKey);
47
- // If no key found, search from the top.
48
- if (key == null) key = keyboardDelegate.getKeyForSearch(state.search);
62
+ let key = keyboardDelegate.getKeyForSearch(state.current.search, selectionManager.focusedKey);
63
+ if (key == null) key = keyboardDelegate.getKeyForSearch(state.current.search);
49
64
  if (key != null) {
50
65
  selectionManager.setFocusedKey(key);
51
66
  if (onTypeSelect) onTypeSelect(key);
67
+ e.preventDefault();
68
+ if (!('continuePropagation' in e)) e.stopPropagation();
69
+ } else {
70
+ // if still nothing then the type to select is done and everything is reset
71
+ state.current.search = '';
72
+ clearTimeout(state.current.timeout);
73
+ state.current.timeout = undefined;
74
+ return;
52
75
  }
53
76
  }
54
- clearTimeout(state.timeout);
55
- state.timeout = setTimeout(()=>{
56
- state.search = '';
77
+ clearTimeout(state.current.timeout);
78
+ state.current.timeout = setTimeout(()=>{
79
+ state.current.search = '';
57
80
  }, $a6299e8d95fc8908$var$TYPEAHEAD_DEBOUNCE_WAIT_MS);
58
81
  };
82
+ (0, $h2mV5$react.useEffect)(()=>{
83
+ let timeout = state.current.timeout;
84
+ return ()=>{
85
+ clearTimeout(timeout);
86
+ };
87
+ }, [
88
+ state
89
+ ]);
59
90
  return {
60
91
  typeSelectProps: {
61
92
  // Using a capturing listener to catch the keydown event before
62
93
  // other hooks in order to handle the Spacebar event.
63
- onKeyDownCapture: keyboardDelegate.getKeyForSearch ? onKeyDown : undefined
94
+ onKeyDownCapture: keyboardDelegate.getKeyForSearch ? onKeyDownCapture : undefined,
95
+ onKeyDown: keyboardDelegate.getKeyForSearch ? onKeyDown : undefined
64
96
  }
65
97
  };
66
98
  }
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAOD;;CAEC,GACD,MAAM,mDAA6B,MAAM,WAAW;AA2B7C,SAAS,0CAAc,OAA8B;IAC1D,IAAI,oBAAC,gBAAgB,oBAAE,gBAAgB,gBAAE,YAAY,EAAC,GAAG;IACzD,IAAI,QAAQ,CAAA,GAAA,mBAAK,EAAwE;QACvF,QAAQ;QACR,SAAS;IACX,GAAG,OAAO;IAEV,IAAI,YAAY,CAAC;QACf,IAAI,YAAY,sCAAgB,EAAE,GAAG;QACrC,IACE,CAAC,aACD,EAAE,OAAO,IACT,EAAE,OAAO,IACT,CAAC,CAAA,GAAA,sCAAW,EAAE,EAAE,aAAa,EAAE,CAAA,GAAA,wCAAa,EAAE,OAC7C,MAAM,MAAM,CAAC,MAAM,KAAK,KAAK,cAAc,KAE5C;QAGF,8EAA8E;QAC9E,8EAA8E;QAC9E,+EAA+E;QAC/E,4EAA4E;QAC5E,IAAI,cAAc,OAAO,MAAM,MAAM,CAAC,IAAI,GAAG,MAAM,GAAG,GAAG;YACvD,EAAE,cAAc;YAChB,IAAI,CAAE,CAAA,yBAAyB,CAAA,GAC7B,EAAE,eAAe;QAErB;QAEA,MAAM,MAAM,IAAI;QAEhB,IAAI,iBAAiB,eAAe,IAAI,MAAM;YAC5C,2CAA2C;YAC3C,+FAA+F;YAC/F,IAAI,MAAM,iBAAiB,eAAe,CAAC,MAAM,MAAM,EAAE,iBAAiB,UAAU;YAEpF,wCAAwC;YACxC,IAAI,OAAO,MACT,MAAM,iBAAiB,eAAe,CAAC,MAAM,MAAM;YAGrD,IAAI,OAAO,MAAM;gBACf,iBAAiB,aAAa,CAAC;gBAC/B,IAAI,cACF,aAAa;YAEjB;QACF;QAEA,aAAa,MAAM,OAAO;QAC1B,MAAM,OAAO,GAAG,WAAW;YACzB,MAAM,MAAM,GAAG;QACjB,GAAG;IACL;IAEA,OAAO;QACL,iBAAiB;YACf,+DAA+D;YAC/D,qDAAqD;YACrD,kBAAkB,iBAAiB,eAAe,GAAG,YAAY;QACnE;IACF;AACF;AAEA,SAAS,sCAAgB,GAAW;IAClC,mDAAmD;IACnD,+DAA+D;IAC/D,6BAA6B;IAC7B,0CAA0C;IAC1C,IAAI,IAAI,MAAM,KAAK,KAAK,CAAC,UAAU,IAAI,CAAC,MACtC,OAAO;IAGT,OAAO;AACT","sources":["packages/react-aria/src/selection/useTypeSelect.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 {DOMAttributes, Key, KeyboardDelegate} from '@react-types/shared';\nimport {getEventTarget, nodeContains} from '../utils/shadowdom/DOMFunctions';\nimport {KeyboardEvent, useRef} from 'react';\nimport {MultipleSelectionManager} from 'react-stately/useMultipleSelectionState';\n\n/**\n * Controls how long to wait before clearing the typeahead buffer.\n */\nconst TYPEAHEAD_DEBOUNCE_WAIT_MS = 1000; // 1 second\n\nexport interface AriaTypeSelectOptions {\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\nexport interface TypeSelectAria {\n /**\n * Props to be spread on the owner of the options.\n */\n typeSelectProps: DOMAttributes;\n}\n\n/**\n * Handles typeahead interactions with collections.\n */\nexport function useTypeSelect(options: AriaTypeSelectOptions): TypeSelectAria {\n let {keyboardDelegate, selectionManager, onTypeSelect} = options;\n let state = useRef<{search: string; timeout: ReturnType<typeof setTimeout> | undefined}>({\n search: '',\n timeout: undefined\n }).current;\n\n let onKeyDown = (e: KeyboardEvent) => {\n let character = getStringForKey(e.key);\n if (\n !character ||\n e.ctrlKey ||\n e.metaKey ||\n !nodeContains(e.currentTarget, getEventTarget(e) as HTMLElement) ||\n (state.search.length === 0 && character === ' ')\n ) {\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 if (keyboardDelegate.getKeyForSearch != null) {\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\n clearTimeout(state.timeout);\n state.timeout = setTimeout(() => {\n state.search = '';\n }, TYPEAHEAD_DEBOUNCE_WAIT_MS);\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 : undefined\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"],"names":[],"version":3,"file":"useTypeSelect.cjs.map"}
1
+ {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAOD;;CAEC,GACD,MAAM,mDAA6B,MAAM,WAAW;AA2B7C,SAAS,0CAAc,OAA8B;IAC1D,IAAI,oBAAC,gBAAgB,oBAAE,gBAAgB,gBAAE,YAAY,EAAC,GAAG;IACzD,IAAI,QAAQ,CAAA,GAAA,mBAAK,EAAwE;QACvF,QAAQ;QACR,SAAS;IACX;IAEA,IAAI,mBAAmB,CAAC;QACtB,0HAA0H;QAC1H,uFAAuF;QACvF,IAAI,MAAM,OAAO,CAAC,MAAM,CAAC,MAAM,GAAG,KAAK,EAAE,GAAG,KAAK,KAAK;YACpD,EAAE,cAAc;YAChB,IACE,CAAE,CAAA,yBAAyB,CAAA,KAC1B,yBAAyB,KAAK,CAAC,EAAE,oBAAoB,IAEtD,EAAE,eAAe;YAEnB,MAAM,OAAO,CAAC,MAAM,IAAI;YAExB,IAAI,iBAAiB,eAAe,IAAI,MAAM;gBAC5C,2CAA2C;gBAC3C,+F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AC,OAAO,GAAG;gBACxB;YACF;QACF;QAEA,aAAa,MAAM,OAAO,CAAC,OAAO;QAClC,MAAM,OAAO,CAAC,OAAO,GAAG,WAAW;YACjC,MAAM,OAAO,CAAC,MAAM,GAAG;QACzB,GAAG;IACL;IAEA,CAAA,GAAA,sBAAQ,EAAE;QACR,IAAI,UAAU,MAAM,OAAO,CAAC,OAAO;QACnC,OAAO;YACL,aAAa;QACf;IACF,GAAG;QAAC;KAAM;IAEV,OAAO;QACL,iBAAiB;YACf,+DAA+D;YAC/D,qDAAqD;YACrD,kBAAkB,iBAAiB,eAAe,GAAG,mBAAmB;YACxE,WAAW,iBAAiB,eAAe,GAAG,YAAY;QAC5D;IACF;AACF;AAEA,SAAS,sCAAgB,GAAW;IAClC,mDAAmD;IACnD,+DAA+D;IAC/D,6BAA6B;IAC7B,0CAA0C;IAC1C,IAAI,IAAI,MAAM,KAAK,KAAK,CAAC,UAAU,IAAI,CAAC,MACtC,OAAO;IAGT,OAAO;AACT","sources":["packages/react-aria/src/selection/useTypeSelect.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 {DOMAttributes, Key, KeyboardDelegate} from '@react-types/shared';\nimport {getEventTarget, nodeContains} from '../utils/shadowdom/DOMFunctions';\nimport {KeyboardEvent, useEffect, useRef} from 'react';\nimport {MultipleSelectionManager} from 'react-stately/useMultipleSelectionState';\n\n/**\n * Controls how long to wait before clearing the typeahead buffer.\n */\nconst TYPEAHEAD_DEBOUNCE_WAIT_MS = 1000; // 1 second\n\nexport interface AriaTypeSelectOptions {\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\nexport interface TypeSelectAria {\n /**\n * Props to be spread on the owner of the options.\n */\n typeSelectProps: DOMAttributes;\n}\n\n/**\n * Handles typeahead interactions with collections.\n */\nexport function useTypeSelect(options: AriaTypeSelectOptions): TypeSelectAria {\n let {keyboardDelegate, selectionManager, onTypeSelect} = options;\n let state = useRef<{search: string; timeout: ReturnType<typeof setTimeout> | undefined}>({\n search: '',\n timeout: undefined\n });\n\n let onKeyDownCapture = (e: KeyboardEvent) => {\n // if we're in the middle of a search, then a spacebar should be treated as a search and we should not propagate the event\n // since we handle this one in a capture phase, we should ignore it in the bubble phase\n if (state.current.search.length > 0 && e.key === ' ') {\n e.preventDefault();\n if (\n !('continuePropagation' in e) ||\n ('continuePropagation' in e && !e.isPropagationStopped())\n ) {\n e.stopPropagation();\n }\n state.current.search += ' ';\n\n if (keyboardDelegate.getKeyForSearch != null) {\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(\n state.current.search,\n selectionManager.focusedKey\n );\n\n // If no key found, search from the top.\n if (key == null) {\n key = keyboardDelegate.getKeyForSearch(state.current.search);\n }\n\n if (key != null) {\n selectionManager.setFocusedKey(key);\n if (onTypeSelect) {\n onTypeSelect(key);\n }\n }\n }\n\n clearTimeout(state.current.timeout);\n state.current.timeout = setTimeout(() => {\n state.current.search = '';\n }, TYPEAHEAD_DEBOUNCE_WAIT_MS);\n }\n };\n\n let onKeyDown = (e: KeyboardEvent) => {\n let character = getStringForKey(e.key);\n if (\n !character ||\n e.ctrlKey ||\n e.metaKey ||\n e.altKey ||\n !nodeContains(e.currentTarget, getEventTarget(e) as HTMLElement) ||\n (state.current.search.length === 0 && character === ' ')\n ) {\n return;\n }\n\n state.current.search += character;\n\n if (keyboardDelegate.getKeyForSearch != null) {\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.current.search, selectionManager.focusedKey);\n\n if (key == null) {\n key = keyboardDelegate.getKeyForSearch(state.current.search);\n }\n\n if (key != null) {\n selectionManager.setFocusedKey(key);\n if (onTypeSelect) {\n onTypeSelect(key);\n }\n e.preventDefault();\n if (!('continuePropagation' in e)) {\n e.stopPropagation();\n }\n } else {\n // if still nothing then the type to select is done and everything is reset\n state.current.search = '';\n clearTimeout(state.current.timeout);\n state.current.timeout = undefined;\n return;\n }\n }\n\n clearTimeout(state.current.timeout);\n state.current.timeout = setTimeout(() => {\n state.current.search = '';\n }, TYPEAHEAD_DEBOUNCE_WAIT_MS);\n };\n\n useEffect(() => {\n let timeout = state.current.timeout;\n return () => {\n clearTimeout(timeout);\n };\n }, [state]);\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 ? onKeyDownCapture : undefined,\n onKeyDown: keyboardDelegate.getKeyForSearch ? onKeyDown : undefined\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"],"names":[],"version":3,"file":"useTypeSelect.cjs.map"}
@@ -1,5 +1,5 @@
1
1
  import {getEventTarget as $d8ac7ed472840322$export$e58f029f0fbfdb29, nodeContains as $d8ac7ed472840322$export$4282f70798064fe0} from "../utils/shadowdom/DOMFunctions.js";
2
- import {useRef as $hxkp5$useRef} from "react";
2
+ import {useRef as $hxkp5$useRef, useEffect as $hxkp5$useEffect} from "react";
3
3
 
4
4
  /*
5
5
  * Copyright 2020 Adobe. All rights reserved.
@@ -21,40 +21,72 @@ function $d6feb9780eea1a71$export$e32c88dfddc6e1d8(options) {
21
21
  let state = (0, $hxkp5$useRef)({
22
22
  search: '',
23
23
  timeout: undefined
24
- }).current;
25
- let onKeyDown = (e)=>{
26
- let character = $d6feb9780eea1a71$var$getStringForKey(e.key);
27
- if (!character || e.ctrlKey || e.metaKey || !(0, $d8ac7ed472840322$export$4282f70798064fe0)(e.currentTarget, (0, $d8ac7ed472840322$export$e58f029f0fbfdb29)(e)) || state.search.length === 0 && character === ' ') return;
28
- // Do not propagate the Spacebar event if it's meant to be part of the search.
29
- // When we time out, the search term becomes empty, hence the check on length.
30
- // Trimming is to account for the case of pressing the Spacebar more than once,
31
- // which should cycle through the selection/deselection of the focused item.
32
- if (character === ' ' && state.search.trim().length > 0) {
24
+ });
25
+ let onKeyDownCapture = (e)=>{
26
+ // if we're in the middle of a search, then a spacebar should be treated as a search and we should not propagate the event
27
+ // since we handle this one in a capture phase, we should ignore it in the bubble phase
28
+ if (state.current.search.length > 0 && e.key === ' ') {
33
29
  e.preventDefault();
34
- if (!('continuePropagation' in e)) e.stopPropagation();
30
+ if (!('continuePropagation' in e) || 'continuePropagation' in e && !e.isPropagationStopped()) e.stopPropagation();
31
+ state.current.search += ' ';
32
+ if (keyboardDelegate.getKeyForSearch != null) {
33
+ // Use the delegate to find a key to focus.
34
+ // Prioritize items after the currently focused item, falling back to searching the whole list.
35
+ let key = keyboardDelegate.getKeyForSearch(state.current.search, selectionManager.focusedKey);
36
+ // If no key found, search from the top.
37
+ if (key == null) key = keyboardDelegate.getKeyForSearch(state.current.search);
38
+ if (key != null) {
39
+ selectionManager.setFocusedKey(key);
40
+ if (onTypeSelect) onTypeSelect(key);
41
+ }
42
+ }
43
+ clearTimeout(state.current.timeout);
44
+ state.current.timeout = setTimeout(()=>{
45
+ state.current.search = '';
46
+ }, $d6feb9780eea1a71$var$TYPEAHEAD_DEBOUNCE_WAIT_MS);
35
47
  }
36
- state.search += character;
48
+ };
49
+ let onKeyDown = (e)=>{
50
+ let character = $d6feb9780eea1a71$var$getStringForKey(e.key);
51
+ if (!character || e.ctrlKey || e.metaKey || e.altKey || !(0, $d8ac7ed472840322$export$4282f70798064fe0)(e.currentTarget, (0, $d8ac7ed472840322$export$e58f029f0fbfdb29)(e)) || state.current.search.length === 0 && character === ' ') return;
52
+ state.current.search += character;
37
53
  if (keyboardDelegate.getKeyForSearch != null) {
38
54
  // Use the delegate to find a key to focus.
39
55
  // Prioritize items after the currently focused item, falling back to searching the whole list.
40
- let key = keyboardDelegate.getKeyForSearch(state.search, selectionManager.focusedKey);
41
- // If no key found, search from the top.
42
- if (key == null) key = keyboardDelegate.getKeyForSearch(state.search);
56
+ let key = keyboardDelegate.getKeyForSearch(state.current.search, selectionManager.focusedKey);
57
+ if (key == null) key = keyboardDelegate.getKeyForSearch(state.current.search);
43
58
  if (key != null) {
44
59
  selectionManager.setFocusedKey(key);
45
60
  if (onTypeSelect) onTypeSelect(key);
61
+ e.preventDefault();
62
+ if (!('continuePropagation' in e)) e.stopPropagation();
63
+ } else {
64
+ // if still nothing then the type to select is done and everything is reset
65
+ state.current.search = '';
66
+ clearTimeout(state.current.timeout);
67
+ state.current.timeout = undefined;
68
+ return;
46
69
  }
47
70
  }
48
- clearTimeout(state.timeout);
49
- state.timeout = setTimeout(()=>{
50
- state.search = '';
71
+ clearTimeout(state.current.timeout);
72
+ state.current.timeout = setTimeout(()=>{
73
+ state.current.search = '';
51
74
  }, $d6feb9780eea1a71$var$TYPEAHEAD_DEBOUNCE_WAIT_MS);
52
75
  };
76
+ (0, $hxkp5$useEffect)(()=>{
77
+ let timeout = state.current.timeout;
78
+ return ()=>{
79
+ clearTimeout(timeout);
80
+ };
81
+ }, [
82
+ state
83
+ ]);
53
84
  return {
54
85
  typeSelectProps: {
55
86
  // Using a capturing listener to catch the keydown event before
56
87
  // other hooks in order to handle the Spacebar event.
57
- onKeyDownCapture: keyboardDelegate.getKeyForSearch ? onKeyDown : undefined
88
+ onKeyDownCapture: keyboardDelegate.getKeyForSearch ? onKeyDownCapture : undefined,
89
+ onKeyDown: keyboardDelegate.getKeyForSearch ? onKeyDown : undefined
58
90
  }
59
91
  };
60
92
  }
@@ -1 +1 @@
1
- {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAOD;;CAEC,GACD,MAAM,mDAA6B,MAAM,WAAW;AA2B7C,SAAS,0CAAc,OAA8B;IAC1D,IAAI,oBAAC,gBAAgB,oBAAE,gBAAgB,gBAAE,YAAY,EAAC,GAAG;IACzD,IAAI,QAAQ,CAAA,GAAA,aAAK,EAAwE;QACvF,QAAQ;QACR,SAAS;IACX,GAAG,OAAO;IAEV,IAAI,YAAY,CAAC;QACf,IAAI,YAAY,sCAAgB,EAAE,GAAG;QACrC,IACE,CAAC,aACD,EAAE,OAAO,IACT,EAAE,OAAO,IACT,CAAC,CAAA,GAAA,yCAAW,EAAE,EAAE,aAAa,EAAE,CAAA,GAAA,yCAAa,EAAE,OAC7C,MAAM,MAAM,CAAC,MAAM,KAAK,KAAK,cAAc,KAE5C;QAGF,8EAA8E;QAC9E,8EAA8E;QAC9E,+EAA+E;QAC/E,4EAA4E;QAC5E,IAAI,cAAc,OAAO,MAAM,MAAM,CAAC,IAAI,GAAG,MAAM,GAAG,GAAG;YACvD,EAAE,cAAc;YAChB,IAAI,CAAE,CAAA,yBAAyB,CAAA,GAC7B,EAAE,eAAe;QAErB;QAEA,MAAM,MAAM,IAAI;QAEhB,IAAI,iBAAiB,eAAe,IAAI,MAAM;YAC5C,2CAA2C;YAC3C,+FAA+F;YAC/F,IAAI,MAAM,iBAAiB,eAAe,CAAC,MAAM,MAAM,EAAE,iBAAiB,UAAU;YAEpF,wCAAwC;YACxC,IAAI,OAAO,MACT,MAAM,iBAAiB,eAAe,CAAC,MAAM,MAAM;YAGrD,IAAI,OAAO,MAAM;gBACf,iBAAiB,aAAa,CAAC;gBAC/B,IAAI,cACF,aAAa;YAEjB;QACF;QAEA,aAAa,MAAM,OAAO;QAC1B,MAAM,OAAO,GAAG,WAAW;YACzB,MAAM,MAAM,GAAG;QACjB,GAAG;IACL;IAEA,OAAO;QACL,iBAAiB;YACf,+DAA+D;YAC/D,qDAAqD;YACrD,kBAAkB,iBAAiB,eAAe,GAAG,YAAY;QACnE;IACF;AACF;AAEA,SAAS,sCAAgB,GAAW;IAClC,mDAAmD;IACnD,+DAA+D;IAC/D,6BAA6B;IAC7B,0CAA0C;IAC1C,IAAI,IAAI,MAAM,KAAK,KAAK,CAAC,UAAU,IAAI,CAAC,MACtC,OAAO;IAGT,OAAO;AACT","sources":["packages/react-aria/src/selection/useTypeSelect.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 {DOMAttributes, Key, KeyboardDelegate} from '@react-types/shared';\nimport {getEventTarget, nodeContains} from '../utils/shadowdom/DOMFunctions';\nimport {KeyboardEvent, useRef} from 'react';\nimport {MultipleSelectionManager} from 'react-stately/useMultipleSelectionState';\n\n/**\n * Controls how long to wait before clearing the typeahead buffer.\n */\nconst TYPEAHEAD_DEBOUNCE_WAIT_MS = 1000; // 1 second\n\nexport interface AriaTypeSelectOptions {\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\nexport interface TypeSelectAria {\n /**\n * Props to be spread on the owner of the options.\n */\n typeSelectProps: DOMAttributes;\n}\n\n/**\n * Handles typeahead interactions with collections.\n */\nexport function useTypeSelect(options: AriaTypeSelectOptions): TypeSelectAria {\n let {keyboardDelegate, selectionManager, onTypeSelect} = options;\n let state = useRef<{search: string; timeout: ReturnType<typeof setTimeout> | undefined}>({\n search: '',\n timeout: undefined\n }).current;\n\n let onKeyDown = (e: KeyboardEvent) => {\n let character = getStringForKey(e.key);\n if (\n !character ||\n e.ctrlKey ||\n e.metaKey ||\n !nodeContains(e.currentTarget, getEventTarget(e) as HTMLElement) ||\n (state.search.length === 0 && character === ' ')\n ) {\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 if (keyboardDelegate.getKeyForSearch != null) {\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\n clearTimeout(state.timeout);\n state.timeout = setTimeout(() => {\n state.search = '';\n }, TYPEAHEAD_DEBOUNCE_WAIT_MS);\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 : undefined\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"],"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CAAC,MACtC,OAAO;IAGT,OAAO;AACT","sources":["packages/react-aria/src/selection/useTypeSelect.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 {DOMAttributes, Key, KeyboardDelegate} from '@react-types/shared';\nimport {getEventTarget, nodeContains} from '../utils/shadowdom/DOMFunctions';\nimport {KeyboardEvent, useEffect, useRef} from 'react';\nimport {MultipleSelectionManager} from 'react-stately/useMultipleSelectionState';\n\n/**\n * Controls how long to wait before clearing the typeahead buffer.\n */\nconst TYPEAHEAD_DEBOUNCE_WAIT_MS = 1000; // 1 second\n\nexport interface AriaTypeSelectOptions {\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\nexport interface TypeSelectAria {\n /**\n * Props to be spread on the owner of the options.\n */\n typeSelectProps: DOMAttributes;\n}\n\n/**\n * Handles typeahead interactions with collections.\n */\nexport function useTypeSelect(options: AriaTypeSelectOptions): TypeSelectAria {\n let {keyboardDelegate, selectionManager, onTypeSelect} = options;\n let state = useRef<{search: string; timeout: ReturnType<typeof setTimeout> | undefined}>({\n search: '',\n timeout: undefined\n });\n\n let onKeyDownCapture = (e: KeyboardEvent) => {\n // if we're in the middle of a search, then a spacebar should be treated as a search and we should not propagate the event\n // since we handle this one in a capture phase, we should ignore it in the bubble phase\n if (state.current.search.length > 0 && e.key === ' ') {\n e.preventDefault();\n if (\n !('continuePropagation' in e) ||\n ('continuePropagation' in e && !e.isPropagationStopped())\n ) {\n e.stopPropagation();\n }\n state.current.search += ' ';\n\n if (keyboardDelegate.getKeyForSearch != null) {\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(\n state.current.search,\n selectionManager.focusedKey\n );\n\n // If no key found, search from the top.\n if (key == null) {\n key = keyboardDelegate.getKeyForSearch(state.current.search);\n }\n\n if (key != null) {\n selectionManager.setFocusedKey(key);\n if (onTypeSelect) {\n onTypeSelect(key);\n }\n }\n }\n\n clearTimeout(state.current.timeout);\n state.current.timeout = setTimeout(() => {\n state.current.search = '';\n }, TYPEAHEAD_DEBOUNCE_WAIT_MS);\n }\n };\n\n let onKeyDown = (e: KeyboardEvent) => {\n let character = getStringForKey(e.key);\n if (\n !character ||\n e.ctrlKey ||\n e.metaKey ||\n e.altKey ||\n !nodeContains(e.currentTarget, getEventTarget(e) as HTMLElement) ||\n (state.current.search.length === 0 && character === ' ')\n ) {\n return;\n }\n\n state.current.search += character;\n\n if (keyboardDelegate.getKeyForSearch != null) {\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.current.search, selectionManager.focusedKey);\n\n if (key == null) {\n key = keyboardDelegate.getKeyForSearch(state.current.search);\n }\n\n if (key != null) {\n selectionManager.setFocusedKey(key);\n if (onTypeSelect) {\n onTypeSelect(key);\n }\n e.preventDefault();\n if (!('continuePropagation' in e)) {\n e.stopPropagation();\n }\n } else {\n // if still nothing then the type to select is done and everything is reset\n state.current.search = '';\n clearTimeout(state.current.timeout);\n state.current.timeout = undefined;\n return;\n }\n }\n\n clearTimeout(state.current.timeout);\n state.current.timeout = setTimeout(() => {\n state.current.search = '';\n }, TYPEAHEAD_DEBOUNCE_WAIT_MS);\n };\n\n useEffect(() => {\n let timeout = state.current.timeout;\n return () => {\n clearTimeout(timeout);\n };\n }, [state]);\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 ? onKeyDownCapture : undefined,\n onKeyDown: keyboardDelegate.getKeyForSearch ? onKeyDown : undefined\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"],"names":[],"version":3,"file":"useTypeSelect.js.map"}
@@ -1,5 +1,5 @@
1
1
  import {getEventTarget as $23f2114a1b82827e$export$e58f029f0fbfdb29, nodeContains as $23f2114a1b82827e$export$4282f70798064fe0} from "../utils/shadowdom/DOMFunctions.mjs";
2
- import {useRef as $dLAPo$useRef} from "react";
2
+ import {useRef as $dLAPo$useRef, useEffect as $dLAPo$useEffect} from "react";
3
3
 
4
4
  /*
5
5
  * Copyright 2020 Adobe. All rights reserved.
@@ -21,40 +21,72 @@ function $f5a4a9a3486154da$export$e32c88dfddc6e1d8(options) {
21
21
  let state = (0, $dLAPo$useRef)({
22
22
  search: '',
23
23
  timeout: undefined
24
- }).current;
25
- let onKeyDown = (e)=>{
26
- let character = $f5a4a9a3486154da$var$getStringForKey(e.key);
27
- if (!character || e.ctrlKey || e.metaKey || !(0, $23f2114a1b82827e$export$4282f70798064fe0)(e.currentTarget, (0, $23f2114a1b82827e$export$e58f029f0fbfdb29)(e)) || state.search.length === 0 && character === ' ') return;
28
- // Do not propagate the Spacebar event if it's meant to be part of the search.
29
- // When we time out, the search term becomes empty, hence the check on length.
30
- // Trimming is to account for the case of pressing the Spacebar more than once,
31
- // which should cycle through the selection/deselection of the focused item.
32
- if (character === ' ' && state.search.trim().length > 0) {
24
+ });
25
+ let onKeyDownCapture = (e)=>{
26
+ // if we're in the middle of a search, then a spacebar should be treated as a search and we should not propagate the event
27
+ // since we handle this one in a capture phase, we should ignore it in the bubble phase
28
+ if (state.current.search.length > 0 && e.key === ' ') {
33
29
  e.preventDefault();
34
- if (!('continuePropagation' in e)) e.stopPropagation();
30
+ if (!('continuePropagation' in e) || 'continuePropagation' in e && !e.isPropagationStopped()) e.stopPropagation();
31
+ state.current.search += ' ';
32
+ if (keyboardDelegate.getKeyForSearch != null) {
33
+ // Use the delegate to find a key to focus.
34
+ // Prioritize items after the currently focused item, falling back to searching the whole list.
35
+ let key = keyboardDelegate.getKeyForSearch(state.current.search, selectionManager.focusedKey);
36
+ // If no key found, search from the top.
37
+ if (key == null) key = keyboardDelegate.getKeyForSearch(state.current.search);
38
+ if (key != null) {
39
+ selectionManager.setFocusedKey(key);
40
+ if (onTypeSelect) onTypeSelect(key);
41
+ }
42
+ }
43
+ clearTimeout(state.current.timeout);
44
+ state.current.timeout = setTimeout(()=>{
45
+ state.current.search = '';
46
+ }, $f5a4a9a3486154da$var$TYPEAHEAD_DEBOUNCE_WAIT_MS);
35
47
  }
36
- state.search += character;
48
+ };
49
+ let onKeyDown = (e)=>{
50
+ let character = $f5a4a9a3486154da$var$getStringForKey(e.key);
51
+ if (!character || e.ctrlKey || e.metaKey || e.altKey || !(0, $23f2114a1b82827e$export$4282f70798064fe0)(e.currentTarget, (0, $23f2114a1b82827e$export$e58f029f0fbfdb29)(e)) || state.current.search.length === 0 && character === ' ') return;
52
+ state.current.search += character;
37
53
  if (keyboardDelegate.getKeyForSearch != null) {
38
54
  // Use the delegate to find a key to focus.
39
55
  // Prioritize items after the currently focused item, falling back to searching the whole list.
40
- let key = keyboardDelegate.getKeyForSearch(state.search, selectionManager.focusedKey);
41
- // If no key found, search from the top.
42
- if (key == null) key = keyboardDelegate.getKeyForSearch(state.search);
56
+ let key = keyboardDelegate.getKeyForSearch(state.current.search, selectionManager.focusedKey);
57
+ if (key == null) key = keyboardDelegate.getKeyForSearch(state.current.search);
43
58
  if (key != null) {
44
59
  selectionManager.setFocusedKey(key);
45
60
  if (onTypeSelect) onTypeSelect(key);
61
+ e.preventDefault();
62
+ if (!('continuePropagation' in e)) e.stopPropagation();
63
+ } else {
64
+ // if still nothing then the type to select is done and everything is reset
65
+ state.current.search = '';
66
+ clearTimeout(state.current.timeout);
67
+ state.current.timeout = undefined;
68
+ return;
46
69
  }
47
70
  }
48
- clearTimeout(state.timeout);
49
- state.timeout = setTimeout(()=>{
50
- state.search = '';
71
+ clearTimeout(state.current.timeout);
72
+ state.current.timeout = setTimeout(()=>{
73
+ state.current.search = '';
51
74
  }, $f5a4a9a3486154da$var$TYPEAHEAD_DEBOUNCE_WAIT_MS);
52
75
  };
76
+ (0, $dLAPo$useEffect)(()=>{
77
+ let timeout = state.current.timeout;
78
+ return ()=>{
79
+ clearTimeout(timeout);
80
+ };
81
+ }, [
82
+ state
83
+ ]);
53
84
  return {
54
85
  typeSelectProps: {
55
86
  // Using a capturing listener to catch the keydown event before
56
87
  // other hooks in order to handle the Spacebar event.
57
- onKeyDownCapture: keyboardDelegate.getKeyForSearch ? onKeyDown : undefined
88
+ onKeyDownCapture: keyboardDelegate.getKeyForSearch ? onKeyDownCapture : undefined,
89
+ onKeyDown: keyboardDelegate.getKeyForSearch ? onKeyDown : undefined
58
90
  }
59
91
  };
60
92
  }
@@ -1 +1 @@
1
- {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAOD;;CAEC,GACD,MAAM,mDAA6B,MAAM,WAAW;AA2B7C,SAAS,0CAAc,OAA8B;IAC1D,IAAI,oBAAC,gBAAgB,oBAAE,gBAAgB,gBAAE,YAAY,EAAC,GAAG;IACzD,IAAI,QAAQ,CAAA,GAAA,aAAK,EAAwE;QACvF,QAAQ;QACR,SAAS;IACX,GAAG,OAAO;IAEV,IAAI,YAAY,CAAC;QACf,IAAI,YAAY,sCAAgB,EAAE,GAAG;QACrC,IACE,CAAC,aACD,EAAE,OAAO,IACT,EAAE,OAAO,IACT,CAAC,CAAA,GAAA,yCAAW,EAAE,EAAE,aAAa,EAAE,CAAA,GAAA,yCAAa,EAAE,OAC7C,MAAM,MAAM,CAAC,MAAM,KAAK,KAAK,cAAc,KAE5C;QAGF,8EAA8E;QAC9E,8EAA8E;QAC9E,+EAA+E;QAC/E,4EAA4E;QAC5E,IAAI,cAAc,OAAO,MAAM,MAAM,CAAC,IAAI,GAAG,MAAM,GAAG,GAAG;YACvD,EAAE,cAAc;YAChB,IAAI,CAAE,CAAA,yBAAyB,CAAA,GAC7B,EAAE,eAAe;QAErB;QAEA,MAAM,MAAM,IAAI;QAEhB,IAAI,iBAAiB,eAAe,IAAI,MAAM;YAC5C,2CAA2C;YAC3C,+FAA+F;YAC/F,IAAI,MAAM,iBAAiB,eAAe,CAAC,MAAM,MAAM,EAAE,iBAAiB,UAAU;YAEpF,wCAAwC;YACxC,IAAI,OAAO,MACT,MAAM,iBAAiB,eAAe,CAAC,MAAM,MAAM;YAGrD,IAAI,OAAO,MAAM;gBACf,iBAAiB,aAAa,CAAC;gBAC/B,IAAI,cACF,aAAa;YAEjB;QACF;QAEA,aAAa,MAAM,OAAO;QAC1B,MAAM,OAAO,GAAG,WAAW;YACzB,MAAM,MAAM,GAAG;QACjB,GAAG;IACL;IAEA,OAAO;QACL,iBAAiB;YACf,+DAA+D;YAC/D,qDAAqD;YACrD,kBAAkB,iBAAiB,eAAe,GAAG,YAAY;QACnE;IACF;AACF;AAEA,SAAS,sCAAgB,GAAW;IAClC,mDAAmD;IACnD,+DAA+D;IAC/D,6BAA6B;IAC7B,0CAA0C;IAC1C,IAAI,IAAI,MAAM,KAAK,KAAK,CAAC,UAAU,IAAI,CAAC,MACtC,OAAO;IAGT,OAAO;AACT","sources":["packages/react-aria/src/selection/useTypeSelect.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 {DOMAttributes, Key, KeyboardDelegate} from '@react-types/shared';\nimport {getEventTarget, nodeContains} from '../utils/shadowdom/DOMFunctions';\nimport {KeyboardEvent, useRef} from 'react';\nimport {MultipleSelectionManager} from 'react-stately/useMultipleSelectionState';\n\n/**\n * Controls how long to wait before clearing the typeahead buffer.\n */\nconst TYPEAHEAD_DEBOUNCE_WAIT_MS = 1000; // 1 second\n\nexport interface AriaTypeSelectOptions {\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\nexport interface TypeSelectAria {\n /**\n * Props to be spread on the owner of the options.\n */\n typeSelectProps: DOMAttributes;\n}\n\n/**\n * Handles typeahead interactions with collections.\n */\nexport function useTypeSelect(options: AriaTypeSelectOptions): TypeSelectAria {\n let {keyboardDelegate, selectionManager, onTypeSelect} = options;\n let state = useRef<{search: string; timeout: ReturnType<typeof setTimeout> | undefined}>({\n search: '',\n timeout: undefined\n }).current;\n\n let onKeyDown = (e: KeyboardEvent) => {\n let character = getStringForKey(e.key);\n if (\n !character ||\n e.ctrlKey ||\n e.metaKey ||\n !nodeContains(e.currentTarget, getEventTarget(e) as HTMLElement) ||\n (state.search.length === 0 && character === ' ')\n ) {\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 if (keyboardDelegate.getKeyForSearch != null) {\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\n clearTimeout(state.timeout);\n state.timeout = setTimeout(() => {\n state.search = '';\n }, TYPEAHEAD_DEBOUNCE_WAIT_MS);\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 : undefined\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"],"names":[],"version":3,"file":"useTypeSelect.mjs.map"}
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAOD;;CAEC,GACD,MAAM,mDAA6B,MAAM,WAAW;AA2B7C,SAAS,0CAAc,OAA8B;IAC1D,IAAI,oBAAC,gBAAgB,oBAAE,gBAAgB,gBAAE,YAAY,EAAC,GAAG;IACzD,IAAI,QAAQ,CAAA,GAAA,aAAK,EAAwE;QACvF,QAAQ;QACR,SAAS;IACX;IAEA,IAAI,mBAAmB,CAAC;QACtB,0HAA0H;QAC1H,uFAAuF;QACvF,IAAI,MAAM,OAAO,CAAC,MAAM,CAAC,MAAM,GAAG,KAAK,EAAE,GAAG,KAAK,KAAK;YACpD,EAAE,cAAc;YAChB,IACE,CAAE,CAAA,yBAAyB,CAAA,KAC1B,yBAAyB,KAAK,CAAC,EAAE,oBAAoB,IAEtD,EAAE,eAAe;YAEnB,MAAM,OAAO,CAAC,MAAM,IA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AAM,GAAG;gBACvB,aAAa,MAAM,OAAO,CAAC,OAAO;gBAClC,MAAM,OAAO,CAAC,OAAO,GAAG;gBACxB;YACF;QACF;QAEA,aAAa,MAAM,OAAO,CAAC,OAAO;QAClC,MAAM,OAAO,CAAC,OAAO,GAAG,WAAW;YACjC,MAAM,OAAO,CAAC,MAAM,GAAG;QACzB,GAAG;IACL;IAEA,CAAA,GAAA,gBAAQ,EAAE;QACR,IAAI,UAAU,MAAM,OAAO,CAAC,OAAO;QACnC,OAAO;YACL,aAAa;QACf;IACF,GAAG;QAAC;KAAM;IAEV,OAAO;QACL,iBAAiB;YACf,+DAA+D;YAC/D,qDAAqD;YACrD,kBAAkB,iBAAiB,eAAe,GAAG,mBAAmB;YACxE,WAAW,iBAAiB,eAAe,GAAG,YAAY;QAC5D;IACF;AACF;AAEA,SAAS,sCAAgB,GAAW;IAClC,mDAAmD;IACnD,+DAA+D;IAC/D,6BAA6B;IAC7B,0CAA0C;IAC1C,IAAI,IAAI,MAAM,KAAK,KAAK,CAAC,UAAU,IAAI,CAAC,MACtC,OAAO;IAGT,OAAO;AACT","sources":["packages/react-aria/src/selection/useTypeSelect.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 {DOMAttributes, Key, KeyboardDelegate} from '@react-types/shared';\nimport {getEventTarget, nodeContains} from '../utils/shadowdom/DOMFunctions';\nimport {KeyboardEvent, useEffect, useRef} from 'react';\nimport {MultipleSelectionManager} from 'react-stately/useMultipleSelectionState';\n\n/**\n * Controls how long to wait before clearing the typeahead buffer.\n */\nconst TYPEAHEAD_DEBOUNCE_WAIT_MS = 1000; // 1 second\n\nexport interface AriaTypeSelectOptions {\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\nexport interface TypeSelectAria {\n /**\n * Props to be spread on the owner of the options.\n */\n typeSelectProps: DOMAttributes;\n}\n\n/**\n * Handles typeahead interactions with collections.\n */\nexport function useTypeSelect(options: AriaTypeSelectOptions): TypeSelectAria {\n let {keyboardDelegate, selectionManager, onTypeSelect} = options;\n let state = useRef<{search: string; timeout: ReturnType<typeof setTimeout> | undefined}>({\n search: '',\n timeout: undefined\n });\n\n let onKeyDownCapture = (e: KeyboardEvent) => {\n // if we're in the middle of a search, then a spacebar should be treated as a search and we should not propagate the event\n // since we handle this one in a capture phase, we should ignore it in the bubble phase\n if (state.current.search.length > 0 && e.key === ' ') {\n e.preventDefault();\n if (\n !('continuePropagation' in e) ||\n ('continuePropagation' in e && !e.isPropagationStopped())\n ) {\n e.stopPropagation();\n }\n state.current.search += ' ';\n\n if (keyboardDelegate.getKeyForSearch != null) {\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(\n state.current.search,\n selectionManager.focusedKey\n );\n\n // If no key found, search from the top.\n if (key == null) {\n key = keyboardDelegate.getKeyForSearch(state.current.search);\n }\n\n if (key != null) {\n selectionManager.setFocusedKey(key);\n if (onTypeSelect) {\n onTypeSelect(key);\n }\n }\n }\n\n clearTimeout(state.current.timeout);\n state.current.timeout = setTimeout(() => {\n state.current.search = '';\n }, TYPEAHEAD_DEBOUNCE_WAIT_MS);\n }\n };\n\n let onKeyDown = (e: KeyboardEvent) => {\n let character = getStringForKey(e.key);\n if (\n !character ||\n e.ctrlKey ||\n e.metaKey ||\n e.altKey ||\n !nodeContains(e.currentTarget, getEventTarget(e) as HTMLElement) ||\n (state.current.search.length === 0 && character === ' ')\n ) {\n return;\n }\n\n state.current.search += character;\n\n if (keyboardDelegate.getKeyForSearch != null) {\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.current.search, selectionManager.focusedKey);\n\n if (key == null) {\n key = keyboardDelegate.getKeyForSearch(state.current.search);\n }\n\n if (key != null) {\n selectionManager.setFocusedKey(key);\n if (onTypeSelect) {\n onTypeSelect(key);\n }\n e.preventDefault();\n if (!('continuePropagation' in e)) {\n e.stopPropagation();\n }\n } else {\n // if still nothing then the type to select is done and everything is reset\n state.current.search = '';\n clearTimeout(state.current.timeout);\n state.current.timeout = undefined;\n return;\n }\n }\n\n clearTimeout(state.current.timeout);\n state.current.timeout = setTimeout(() => {\n state.current.search = '';\n }, TYPEAHEAD_DEBOUNCE_WAIT_MS);\n };\n\n useEffect(() => {\n let timeout = state.current.timeout;\n return () => {\n clearTimeout(timeout);\n };\n }, [state]);\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 ? onKeyDownCapture : undefined,\n onKeyDown: keyboardDelegate.getKeyForSearch ? onKeyDown : undefined\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"],"names":[],"version":3,"file":"useTypeSelect.mjs.map"}