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;;;;;;;;;;;;;;AAwDD,MAAM,uCAAiB;IACrB,QAAQ;QACN,KAAK;QACL,KAAK;IACP;IACA,UAAU;QACR,KAAK;QACL,KAAK;IACP;AACF;AASO,SAAS,0CACd,KAA8B,EAC9B,KAAkC,EAClC,GAAuC;IAEvC,+EAA+E;IAC/E,IAAI,QAAC,IAAI,iBAAE,aAAa,EAAC,GAAG;IAE5B,2FAA2F;IAC3F,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,yCAAQ;IAC1B,IAAI,YAAC,QAAQ,gBAAE,YAAY,8BAAE,0BAA0B,yBAAE,qBAAqB,EAAC,GAC7E,CAAA,GAAA,yCAAM,EAAE,GAAG,CAAC;IACd,IAAI,gBAAgB,CAAA,GAAA,yCAAQ;IAE5B,wFAAwF;IACxF,6FAA6F;IAC7F,IAAI,iBAAiB,CAAA,GAAA,aAAK,EAAc;IACxC,IAAI,QAAQ;QACV,yFAAyF;QACzF,kCAAkC;QAClC,IACE,IAAI,OA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,MAAO,KAAM;QACX,SAAS,IAAI,CAAC;QACd,OAAO,KAAK,OAAO,IAAI,OAAO,WAAW,OAAO,CAAC,KAAK,OAAO,IAAI;IACnE;IACA,OAAO;AACT","sources":["packages/react-aria/src/gridlist/useGridListItem.ts"],"sourcesContent":["/*\n * Copyright 2022 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 {chain} from '../utils/chain';\n\nimport {\n Collection,\n DOMAttributes,\n FocusableElement,\n Key,\n RefObject,\n Node as RSNode\n} from '@react-types/shared';\nimport {focusSafely} from '../interactions/focusSafely';\nimport {\n getActiveElement,\n getEventTarget,\n isFocusWithin,\n nodeContains\n} from '../utils/shadowdom/DOMFunctions';\nimport {getFocusableTreeWalker} from '../focus/FocusScope';\nimport {getRowId, listMap} from './utils';\nimport {getScrollParent} from '../utils/getScrollParent';\nimport {HTMLAttributes, KeyboardEvent as ReactKeyboardEvent, useRef} from 'react';\nimport {isFocusVisible} from '../interactions/useFocusVisible';\nimport type {ListState} from 'react-stately/useListState';\nimport {mergeProps} from '../utils/mergeProps';\nimport {scrollIntoViewport} from '../utils/scrollIntoView';\nimport {SelectableItemStates, useSelectableItem} from '../selection/useSelectableItem';\nimport type {TreeState} from 'react-stately/useTreeState';\nimport {useLocale} from '../i18n/I18nProvider';\nimport {useSlotId} from '../utils/useId';\nimport {useSyntheticLinkProps} from '../utils/openLink';\n\nexport interface AriaGridListItemOptions {\n /**\n * An object representing the list item. Contains all the relevant information that makes up the\n * list row.\n */\n node: RSNode<unknown>;\n /** Whether the list row is contained in a virtual scroller. */\n isVirtualized?: boolean;\n /** Whether selection should occur on press up instead of press down. */\n shouldSelectOnPressUp?: boolean;\n /** Whether this item has children, even if not loaded yet. */\n hasChildItems?: boolean;\n}\n\nexport interface GridListItemAria extends SelectableItemStates {\n /** Props for the list row element. */\n rowProps: DOMAttributes;\n /** Props for the grid cell element within the list row. */\n gridCellProps: DOMAttributes;\n /** Props for the list item description element, if any. */\n descriptionProps: DOMAttributes;\n}\n\nconst EXPANSION_KEYS = {\n expand: {\n ltr: 'ArrowRight',\n rtl: 'ArrowLeft'\n },\n collapse: {\n ltr: 'ArrowLeft',\n rtl: 'ArrowRight'\n }\n};\n\n/**\n * Provides the behavior and accessibility implementation for a row in a grid list.\n *\n * @param props - Props for the row.\n * @param state - State of the parent list, as returned by `useListState`.\n * @param ref - The ref attached to the row element.\n */\nexport function useGridListItem<T>(\n props: AriaGridListItemOptions,\n state: ListState<T> | TreeState<T>,\n ref: RefObject<FocusableElement | null>\n): GridListItemAria {\n // Copied from useGridCell + some modifications to make it not so grid specific\n let {node, isVirtualized} = props;\n\n // let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/gridlist');\n let {direction} = useLocale();\n let {onAction, linkBehavior, keyboardNavigationBehavior, shouldSelectOnPressUp} =\n listMap.get(state)!;\n let descriptionId = useSlotId();\n\n // We need to track the key of the item at the time it was last focused so that we force\n // focus to go to the item when the DOM node is reused for a different item in a virtualizer.\n let keyWhenFocused = useRef<Key | null>(null);\n let focus = () => {\n // Don't shift focus to the row if the active element is a element within the row already\n // (e.g. clicking on a row button)\n if (\n ref.current !== null &&\n ((keyWhenFocused.current != null && node.key !== keyWhenFocused.current) ||\n !isFocusWithin(ref.current))\n ) {\n focusSafely(ref.current);\n }\n };\n\n let treeGridRowProps: HTMLAttributes<HTMLElement> = {};\n let hasChildRows = props.hasChildItems;\n let hasLink = state.selectionManager.isLink(node.key);\n if (node != null && 'expandedKeys' in state) {\n // TODO: ideally node.hasChildNodes would be a way to tell if a row has child nodes, but the row's contents make it so that value is always\n // true...\n let children = state.collection.getChildren?.(node.key);\n hasChildRows = hasChildRows || [...(children ?? [])].length > 1;\n\n if (\n onAction == null &&\n !hasLink &&\n state.selectionManager.selectionMode === 'none' &&\n hasChildRows\n ) {\n onAction = () => state.toggleKey(node.key);\n }\n\n let isExpanded = hasChildRows ? state.expandedKeys.has(node.key) : undefined;\n let setSize = 1;\n let index = node.index;\n if (node.level >= 0 && node?.parentKey != null) {\n let parent = state.collection.getItem(node.parentKey);\n if (parent) {\n // siblings must exist because our original node exists\n let siblings = getDirectChildren(parent, state.collection);\n setSize = [...siblings].filter(row => row.type === 'item').length;\n if (index > 0 && siblings[0].type !== 'item') {\n index -= 1; // subtract one for the parent item's content node\n }\n }\n } else {\n setSize = [...state.collection].filter(row => row.level === 0 && row.type === 'item').length;\n }\n\n treeGridRowProps = {\n 'aria-expanded': isExpanded,\n 'aria-level': node.level + 1,\n 'aria-posinset': index + 1,\n 'aria-setsize': setSize\n };\n }\n\n let {itemProps, ...itemStates} = useSelectableItem({\n selectionManager: state.selectionManager,\n key: node.key,\n ref,\n isVirtualized,\n shouldSelectOnPressUp: props.shouldSelectOnPressUp || shouldSelectOnPressUp,\n onAction:\n onAction || node.props?.onAction\n ? chain(node.props?.onAction, onAction ? () => onAction(node.key) : undefined)\n : undefined,\n focus,\n linkBehavior\n });\n\n let onKeyDownCapture = (e: ReactKeyboardEvent) => {\n let activeElement = getActiveElement();\n if (\n !nodeContains(e.currentTarget, getEventTarget(e) as Element) ||\n !ref.current ||\n !activeElement\n ) {\n return;\n }\n\n let walker = getFocusableTreeWalker(ref.current);\n walker.currentNode = activeElement;\n\n if ('expandedKeys' in state && activeElement === ref.current) {\n if (\n e.key === EXPANSION_KEYS['expand'][direction] &&\n state.selectionManager.focusedKey === node.key &&\n hasChildRows &&\n !state.expandedKeys.has(node.key)\n ) {\n state.toggleKey(node.key);\n e.stopPropagation();\n return;\n } else if (\n e.key === EXPANSION_KEYS['collapse'][direction] &&\n state.selectionManager.focusedKey === node.key\n ) {\n // If item is collapsible, collapse it; else move to parent\n if (hasChildRows && state.expandedKeys.has(node.key)) {\n state.toggleKey(node.key);\n e.stopPropagation();\n return;\n } else if (\n !state.expandedKeys.has(node.key) &&\n node.parentKey &&\n state.collection.getItem(node.parentKey)?.type === 'item'\n ) {\n // Item is a leaf or already collapsed, move focus to parent\n state.selectionManager.setFocusedKey(node.parentKey);\n e.stopPropagation();\n return;\n }\n }\n }\n\n switch (e.key) {\n case 'ArrowLeft': {\n if (keyboardNavigationBehavior === 'arrow') {\n // Find the next focusable element within the row.\n let focusable =\n direction === 'rtl'\n ? (walker.nextNode() as FocusableElement)\n : (walker.previousNode() as FocusableElement);\n\n if (focusable) {\n e.preventDefault();\n e.stopPropagation();\n focusSafely(focusable);\n scrollIntoViewport(focusable, {containingElement: getScrollParent(ref.current)});\n } else {\n // If there is no next focusable child, then return focus back to the row\n e.preventDefault();\n e.stopPropagation();\n if (direction === 'rtl') {\n focusSafely(ref.current);\n scrollIntoViewport(ref.current, {containingElement: getScrollParent(ref.current)});\n } else {\n walker.currentNode = ref.current;\n let lastElement = last(walker);\n // oxlint-disable-next-line max-depth\n if (lastElement) {\n focusSafely(lastElement);\n scrollIntoViewport(lastElement, {containingElement: getScrollParent(ref.current)});\n }\n }\n }\n }\n break;\n }\n case 'ArrowRight': {\n if (keyboardNavigationBehavior === 'arrow') {\n let focusable =\n direction === 'rtl'\n ? (walker.previousNode() as FocusableElement)\n : (walker.nextNode() as FocusableElement);\n\n if (focusable) {\n e.preventDefault();\n e.stopPropagation();\n focusSafely(focusable);\n scrollIntoViewport(focusable, {containingElement: getScrollParent(ref.current)});\n } else {\n e.preventDefault();\n e.stopPropagation();\n if (direction === 'ltr') {\n focusSafely(ref.current);\n scrollIntoViewport(ref.current, {containingElement: getScrollParent(ref.current)});\n } else {\n walker.currentNode = ref.current;\n let lastElement = last(walker);\n // oxlint-disable-next-line max-depth\n if (lastElement) {\n focusSafely(lastElement);\n scrollIntoViewport(lastElement, {containingElement: getScrollParent(ref.current)});\n }\n }\n }\n }\n break;\n }\n case 'ArrowUp':\n case 'ArrowDown':\n // Prevent this event from reaching row children, e.g. menu buttons. We want arrow keys to navigate\n // to the row above/below instead. We need to re-dispatch the event from a higher parent so it still\n // bubbles and gets handled by useSelectableCollection.\n if (!e.altKey && nodeContains(ref.current, getEventTarget(e) as Element)) {\n e.stopPropagation();\n e.preventDefault();\n ref.current.parentElement?.dispatchEvent(\n new KeyboardEvent(e.nativeEvent.type, e.nativeEvent)\n );\n }\n break;\n }\n };\n\n let onFocus = e => {\n keyWhenFocused.current = node.key;\n if (getEventTarget(e) !== ref.current) {\n // useSelectableItem only handles setting the focused key when\n // the focused element is the row itself. We also want to\n // set the focused key when a child element receives focus.\n // If focus is currently visible (e.g. the user is navigating with the keyboard),\n // then skip this. We want to restore focus to the previously focused row\n // in that case since the list should act like a single tab stop.\n if (!isFocusVisible()) {\n state.selectionManager.setFocusedKey(node.key);\n }\n return;\n }\n };\n\n let onKeyDown = e => {\n let activeElement = getActiveElement();\n if (\n !nodeContains(e.currentTarget, getEventTarget(e) as Element) ||\n !ref.current ||\n !activeElement\n ) {\n return;\n }\n\n switch (e.key) {\n case 'Tab': {\n if (keyboardNavigationBehavior === 'tab') {\n // If there is another focusable element within this item, stop propagation so the tab key\n // is handled by the browser and not by useSelectableCollection (which would take us out of the list).\n let walker = getFocusableTreeWalker(ref.current, {tabbable: true});\n walker.currentNode = activeElement;\n let next = e.shiftKey ? walker.previousNode() : walker.nextNode();\n\n if (next) {\n e.stopPropagation();\n }\n }\n }\n }\n };\n\n let syntheticLinkProps = useSyntheticLinkProps(node.props);\n let linkProps = itemStates.hasAction ? syntheticLinkProps : {};\n // TODO: re-add when we get translations and fix this for iOS VO\n // let rowAnnouncement;\n // if (onAction) {\n // rowAnnouncement = stringFormatter.format('hasActionAnnouncement');\n // } else if (hasLink) {\n // rowAnnouncement = stringFormatter.format('hasLinkAnnouncement', {\n // link: node.props.href\n // });\n // }\n\n let rowProps: DOMAttributes = mergeProps(itemProps, linkProps, {\n role: 'row',\n onKeyDownCapture,\n onKeyDown,\n onFocus,\n // 'aria-label': [(node.textValue || undefined), rowAnnouncement].filter(Boolean).join(', '),\n 'aria-label': node['aria-label'] || node.textValue || undefined,\n 'aria-selected': state.selectionManager.canSelectItem(node.key)\n ? state.selectionManager.isSelected(node.key)\n : undefined,\n 'aria-disabled': state.selectionManager.isDisabled(node.key) || undefined,\n 'aria-labelledby':\n descriptionId && (node['aria-label'] || node.textValue)\n ? `${getRowId(state, node.key)} ${descriptionId}`\n : undefined,\n id: getRowId(state, node.key)\n });\n\n if (isVirtualized) {\n let {collection} = state;\n let nodes = [...collection];\n // TODO: refactor ListCollection to store an absolute index of a node's position?\n rowProps['aria-rowindex'] = nodes.find(node => node.type === 'section')\n ? [...collection.getKeys()]\n .filter(key => collection.getItem(key)?.type !== 'section')\n .findIndex(key => key === node.key) + 1\n : node.index + 1;\n }\n\n let gridCellProps = {\n role: 'gridcell',\n 'aria-colindex': 1\n };\n\n // TODO: should isExpanded and hasChildRows be a item state that gets returned by the hook?\n return {\n rowProps: {...mergeProps(rowProps, treeGridRowProps)},\n gridCellProps,\n descriptionProps: {\n id: descriptionId\n },\n ...itemStates\n };\n}\n\nfunction last(walker: TreeWalker) {\n let next: FocusableElement | null = null;\n let last: FocusableElement | null = null;\n do {\n last = walker.lastChild() as FocusableElement | null;\n if (last) {\n next = last;\n }\n } while (last);\n return next;\n}\n\nfunction getDirectChildren<T>(parent: RSNode<T>, collection: Collection<RSNode<T>>) {\n // We can't assume that we can use firstChildKey because if a person builds a tree using hooks, they would not have access to that property (using type Node vs CollectionNode)\n // Instead, get all children and start at the first node (rather than just using firstChildKey) and only look at its siblings\n let children = collection.getChildren?.(parent.key);\n let childArray = children ? Array.from(children) : [];\n let node = childArray.length > 0 ? childArray[0] : null;\n let siblings: RSNode<T>[] = [];\n while (node) {\n siblings.push(node);\n node = node.nextKey != null ? collection.getItem(node.nextKey) : null;\n }\n return siblings;\n}\n"],"names":[],"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IACd,MAAM,UAAU,CAAC,OAAO,CAAC,KAAK,SAAS,GAAG,SAAS,QACnD;YACA,4DAA4D;YAC5D,MAAM,gBAAgB,CAAC,aAAa,CAAC,KAAK,SAAS;YACnD,EAAE,eAAe;YACjB,OAAO;QACT;IACF;IACA,OAAO;AACT;AAEA,SAAS,2BAAK,MAAkB;IAC9B,IAAI,OAAgC;IACpC,IAAI,OAAgC;IACpC,GAAG;QACD,OAAO,OAAO,SAAS;QACvB,IAAI,MACF,OAAO;IAEX,QAAS,MAAM;IACf,OAAO;AACT;AAEA,SAAS,wCAAqB,MAAiB,EAAE,UAAiC;IAChF,+KAA+K;IAC/K,6HAA6H;IAC7H,IAAI,WAAW,WAAW,WAAW,GAAG,OAAO,GAAG;IAClD,IAAI,aAAa,WAAW,MAAM,IAAI,CAAC,YAAY,EAAE;IACrD,IAAI,OAAO,WAAW,MAAM,GAAG,IAAI,UAAU,CAAC,EAAE,GAAG;IACnD,IAAI,WAAwB,EAAE;IAC9B,MAAO,KAAM;QACX,SAAS,IAAI,CAAC;QACd,OAAO,KAAK,OAAO,IAAI,OAAO,WAAW,OAAO,CAAC,KAAK,OAAO,IAAI;IACnE;IACA,OAAO;AACT","sources":["packages/react-aria/src/gridlist/useGridListItem.ts"],"sourcesContent":["/*\n * Copyright 2022 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 {chain} from '../utils/chain';\nimport {\n Collection,\n DOMAttributes,\n FocusableElement,\n Key,\n RefObject,\n Node as RSNode\n} from '@react-types/shared';\nimport {focusSafely} from '../interactions/focusSafely';\nimport {\n getActiveElement,\n getEventTarget,\n isFocusWithin,\n nodeContains\n} from '../utils/shadowdom/DOMFunctions';\nimport {getFocusableTreeWalker} from '../focus/FocusScope';\nimport {getRowId, listMap} from './utils';\nimport {getScrollParent} from '../utils/getScrollParent';\nimport {\n HTMLAttributes,\n KeyboardEvent as ReactKeyboardEvent,\n MouseEvent as ReactMouseEvent,\n PointerEvent as ReactPointerEvent,\n useRef\n} from 'react';\nimport {isFocusVisible} from '../interactions/useFocusVisible';\nimport {isTabbable} from '../utils/isFocusable';\nimport type {ListState} from 'react-stately/useListState';\nimport {mergeProps} from '../utils/mergeProps';\nimport {scrollIntoViewport} from '../utils/scrollIntoView';\nimport {SelectableItemStates, useSelectableItem} from '../selection/useSelectableItem';\nimport type {TreeState} from 'react-stately/useTreeState';\nimport {useLocale} from '../i18n/I18nProvider';\nimport {useSlotId} from '../utils/useId';\nimport {useSyntheticLinkProps} from '../utils/openLink';\n\nexport interface AriaGridListItemOptions {\n /**\n * An object representing the list item. Contains all the relevant information that makes up the\n * list row.\n */\n node: RSNode<unknown>;\n /** Whether the list row is contained in a virtual scroller. */\n isVirtualized?: boolean;\n /** Whether selection should occur on press up instead of press down. */\n shouldSelectOnPressUp?: boolean;\n /** Whether this item has children, even if not loaded yet. */\n hasChildItems?: boolean;\n}\n\nexport interface GridListItemAria extends SelectableItemStates {\n /** Props for the list row element. */\n rowProps: DOMAttributes;\n /** Props for the grid cell element within the list row. */\n gridCellProps: DOMAttributes;\n /** Props for the list item description element, if any. */\n descriptionProps: DOMAttributes;\n}\n\nconst EXPANSION_KEYS = {\n expand: {\n ltr: 'ArrowRight',\n rtl: 'ArrowLeft'\n },\n collapse: {\n ltr: 'ArrowLeft',\n rtl: 'ArrowRight'\n }\n};\n\n/**\n * Provides the behavior and accessibility implementation for a row in a grid list.\n *\n * @param props - Props for the row.\n * @param state - State of the parent list, as returned by `useListState`.\n * @param ref - The ref attached to the row element.\n */\nexport function useGridListItem<T>(\n props: AriaGridListItemOptions,\n state: ListState<T> | TreeState<T>,\n ref: RefObject<FocusableElement | null>\n): GridListItemAria {\n // Copied from useGridCell + some modifications to make it not so grid specific\n let {node, isVirtualized} = props;\n\n // let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/gridlist');\n let {direction} = useLocale();\n let {onAction, linkBehavior, keyboardNavigationBehavior, shouldSelectOnPressUp} =\n listMap.get(state)!;\n let descriptionId = useSlotId();\n\n // We need to track the key of the item at the time it was last focused so that we force\n // focus to go to the item when the DOM node is reused for a different item in a virtualizer.\n let keyWhenFocused = useRef<Key | null>(null);\n let focus = () => {\n // Don't shift focus to the row if the active element is a element within the row already\n // (e.g. clicking on a row button)\n if (\n ref.current !== null &&\n ((keyWhenFocused.current != null && node.key !== keyWhenFocused.current) ||\n !isFocusWithin(ref.current))\n ) {\n focusSafely(ref.current);\n }\n };\n\n let treeGridRowProps: HTMLAttributes<HTMLElement> = {};\n let hasChildRows = props.hasChildItems;\n let hasLink = state.selectionManager.isLink(node.key);\n if (node != null && 'expandedKeys' in state) {\n // TODO: ideally node.hasChildNodes would be a way to tell if a row has child nodes, but the row's contents make it so that value is always\n // true...\n let children = state.collection.getChildren?.(node.key);\n hasChildRows = hasChildRows || [...(children ?? [])].length > 1;\n\n if (\n onAction == null &&\n !hasLink &&\n state.selectionManager.selectionMode === 'none' &&\n hasChildRows\n ) {\n onAction = () => state.toggleKey(node.key);\n }\n\n let isExpanded = hasChildRows ? state.expandedKeys.has(node.key) : undefined;\n let setSize = 1;\n let index = node.index;\n if (node.level >= 0 && node?.parentKey != null) {\n let parent = state.collection.getItem(node.parentKey);\n if (parent) {\n // siblings must exist because our original node exists\n let siblings = getDirectChildren(parent, state.collection);\n setSize = [...siblings].filter(row => row.type === 'item').length;\n if (index > 0 && siblings[0].type !== 'item') {\n index -= 1; // subtract one for the parent item's content node\n }\n }\n } else {\n setSize = [...state.collection].filter(row => row.level === 0 && row.type === 'item').length;\n }\n\n treeGridRowProps = {\n 'aria-expanded': isExpanded,\n 'aria-level': node.level + 1,\n 'aria-posinset': index + 1,\n 'aria-setsize': setSize\n };\n }\n\n let {itemProps, ...itemStates} = useSelectableItem({\n selectionManager: state.selectionManager,\n key: node.key,\n ref,\n isVirtualized,\n shouldSelectOnPressUp: props.shouldSelectOnPressUp || shouldSelectOnPressUp,\n onAction:\n onAction || node.props?.onAction\n ? chain(node.props?.onAction, onAction ? () => onAction(node.key) : undefined)\n : undefined,\n focus,\n linkBehavior\n });\n\n let onKeyDownCapture = (e: ReactKeyboardEvent) => {\n let activeElement = getActiveElement();\n if (\n !nodeContains(e.currentTarget, getEventTarget(e) as Element) ||\n !ref.current ||\n !activeElement\n ) {\n return;\n }\n\n let walker = getFocusableTreeWalker(ref.current);\n walker.currentNode = activeElement;\n\n if (\n handleTreeExpansionKeys(e, state, node, hasChildRows, direction, activeElement, ref.current)\n ) {\n return;\n }\n\n switch (e.key) {\n case 'ArrowLeft': {\n if (keyboardNavigationBehavior === 'arrow') {\n // Find the next focusable element within the row.\n let focusable =\n direction === 'rtl'\n ? (walker.nextNode() as FocusableElement)\n : (walker.previousNode() as FocusableElement);\n\n if (focusable) {\n e.preventDefault();\n e.stopPropagation();\n focusSafely(focusable);\n scrollIntoViewport(focusable, {containingElement: getScrollParent(ref.current)});\n } else {\n // If there is no next focusable child, then return focus back to the row\n e.preventDefault();\n e.stopPropagation();\n if (direction === 'rtl') {\n focusSafely(ref.current);\n scrollIntoViewport(ref.current, {containingElement: getScrollParent(ref.current)});\n } else {\n walker.currentNode = ref.current;\n let lastElement = last(walker);\n // oxlint-disable-next-line max-depth\n if (lastElement) {\n focusSafely(lastElement);\n scrollIntoViewport(lastElement, {containingElement: getScrollParent(ref.current)});\n }\n }\n }\n }\n break;\n }\n case 'ArrowRight': {\n if (keyboardNavigationBehavior === 'arrow') {\n let focusable =\n direction === 'rtl'\n ? (walker.previousNode() as FocusableElement)\n : (walker.nextNode() as FocusableElement);\n\n if (focusable) {\n e.preventDefault();\n e.stopPropagation();\n focusSafely(focusable);\n scrollIntoViewport(focusable, {containingElement: getScrollParent(ref.current)});\n } else {\n e.preventDefault();\n e.stopPropagation();\n if (direction === 'ltr') {\n focusSafely(ref.current);\n scrollIntoViewport(ref.current, {containingElement: getScrollParent(ref.current)});\n } else {\n walker.currentNode = ref.current;\n let lastElement = last(walker);\n // oxlint-disable-next-line max-depth\n if (lastElement) {\n focusSafely(lastElement);\n scrollIntoViewport(lastElement, {containingElement: getScrollParent(ref.current)});\n }\n }\n }\n }\n break;\n }\n case 'ArrowUp':\n case 'ArrowDown':\n // Prevent this event from reaching row children, e.g. menu buttons. We want arrow keys to navigate\n // to the row above/below instead. We need to re-dispatch the event from a higher parent so it still\n // bubbles and gets handled by useSelectableCollection.\n if (!e.altKey && nodeContains(ref.current, getEventTarget(e) as Element)) {\n e.stopPropagation();\n e.preventDefault();\n ref.current.parentElement?.dispatchEvent(\n new KeyboardEvent(e.nativeEvent.type, e.nativeEvent)\n );\n }\n break;\n }\n };\n\n let onFocus = e => {\n keyWhenFocused.current = node.key;\n if (getEventTarget(e) !== ref.current) {\n // useSelectableItem only handles setting the focused key when\n // the focused element is the row itself. We also want to\n // set the focused key when a child element receives focus.\n // If focus is currently visible (e.g. the user is navigating with the keyboard),\n // then skip this. We want to restore focus to the previously focused row\n // in that case since the list should act like a single tab stop.\n if (!isFocusVisible()) {\n state.selectionManager.setFocusedKey(node.key);\n }\n return;\n }\n };\n\n let onKeyDown = (e: ReactKeyboardEvent) => {\n let activeElement = getActiveElement();\n if (\n !nodeContains(e.currentTarget, getEventTarget(e) as Element) ||\n !ref.current ||\n !activeElement\n ) {\n return;\n }\n\n if (keyboardNavigationBehavior === 'tab') {\n // Stop propagation for all events that originate from the children of the gridlist item since we don't want to trigger\n // grid level interactions (row navigation/typeselect/etc)\n // exception made for Tab since that needs to propagate to useSelectableCollection to tab out of the gridlist, might be others?\n if (getEventTarget(e) !== ref.current && e.key !== 'Tab') {\n e.stopPropagation();\n return;\n }\n\n if (\n handleTreeExpansionKeys(e, state, node, hasChildRows, direction, activeElement, ref.current)\n ) {\n return;\n }\n }\n\n switch (e.key) {\n case 'Tab': {\n if (keyboardNavigationBehavior === 'tab') {\n // If there is another focusable element within this item, stop propagation so the tab key\n // is handled by the browser and not by useSelectableCollection (which would take us out of the list).\n let walker = getFocusableTreeWalker(ref.current, {tabbable: true});\n walker.currentNode = activeElement;\n let next = e.shiftKey ? walker.previousNode() : walker.nextNode();\n\n if (next) {\n e.stopPropagation();\n }\n }\n }\n }\n };\n\n let syntheticLinkProps = useSyntheticLinkProps(node.props);\n let linkProps = itemStates.hasAction ? syntheticLinkProps : {};\n // TODO: re-add when we get translations and fix this for iOS VO\n // let rowAnnouncement;\n // if (onAction) {\n // rowAnnouncement = stringFormatter.format('hasActionAnnouncement');\n // } else if (hasLink) {\n // rowAnnouncement = stringFormatter.format('hasLinkAnnouncement', {\n // link: node.props.href\n // });\n // }\n\n let rowProps: DOMAttributes = mergeProps(itemProps, linkProps, {\n role: 'row',\n onKeyDownCapture: keyboardNavigationBehavior === 'arrow' ? onKeyDownCapture : undefined,\n onFocus,\n // 'aria-label': [(node.textValue || undefined), rowAnnouncement].filter(Boolean).join(', '),\n 'aria-label': node['aria-label'] || node.textValue || undefined,\n 'aria-selected': state.selectionManager.canSelectItem(node.key)\n ? state.selectionManager.isSelected(node.key)\n : undefined,\n 'aria-disabled': state.selectionManager.isDisabled(node.key) || undefined,\n 'aria-labelledby':\n descriptionId && (node['aria-label'] || node.textValue)\n ? `${getRowId(state, node.key)} ${descriptionId}`\n : undefined,\n id: getRowId(state, node.key)\n });\n\n // we need to guard against space/enter triggering selection/row link via usePress (from itemProps) so check if propagation\n // is stopped. this also fixes space not working in a textfield in a tree parent row\n let baseOnKeyDown = rowProps.onKeyDown;\n rowProps.onKeyDown = (e: ReactKeyboardEvent<FocusableElement>) => {\n onKeyDown(e as ReactKeyboardEvent);\n if (!e.isPropagationStopped()) {\n baseOnKeyDown?.(e);\n }\n };\n\n // guard against presses triggering row selecition when they happen on elements within the row\n // am currently assuming if it is tabbable it is interactive, but maybe can use a different kind of check\n let baseOnPointerDown = rowProps.onPointerDown;\n rowProps.onPointerDown = (e: ReactPointerEvent<FocusableElement>) => {\n let target = getEventTarget(e) as Element | null;\n if (target && target !== ref.current && isTabbable(target)) {\n e.stopPropagation();\n return;\n }\n baseOnPointerDown?.(e);\n };\n\n let baseOnMouseDown = rowProps.onMouseDown;\n rowProps.onMouseDown = (e: ReactMouseEvent<FocusableElement>) => {\n let target = getEventTarget(e) as Element | null;\n if (target && target !== ref.current && isTabbable(target)) {\n e.stopPropagation();\n return;\n }\n baseOnMouseDown?.(e);\n };\n\n if (isVirtualized) {\n let {collection} = state;\n let nodes = [...collection];\n // TODO: refactor ListCollection to store an absolute index of a node's position?\n rowProps['aria-rowindex'] = nodes.find(node => node.type === 'section')\n ? [...collection.getKeys()]\n .filter(key => collection.getItem(key)?.type !== 'section')\n .findIndex(key => key === node.key) + 1\n : node.index + 1;\n }\n\n let gridCellProps = {\n role: 'gridcell',\n 'aria-colindex': 1\n };\n\n // TODO: should isExpanded and hasChildRows be a item state that gets returned by the hook?\n return {\n rowProps: {...mergeProps(rowProps, treeGridRowProps)},\n gridCellProps,\n descriptionProps: {\n id: descriptionId\n },\n ...itemStates\n };\n}\n\nfunction handleTreeExpansionKeys<T>(\n e: ReactKeyboardEvent,\n state: ListState<T> | TreeState<T>,\n node: RSNode<unknown>,\n hasChildRows: boolean | undefined,\n direction: string,\n activeElement: Element | null,\n rowRef: FocusableElement | null\n): boolean {\n if (!('expandedKeys' in state) || activeElement !== rowRef) {\n return false;\n }\n if (\n e.key === EXPANSION_KEYS['expand'][direction] &&\n state.selectionManager.focusedKey === node.key &&\n hasChildRows &&\n !state.expandedKeys.has(node.key)\n ) {\n state.toggleKey(node.key);\n e.stopPropagation();\n return true;\n } else if (\n e.key === EXPANSION_KEYS['collapse'][direction] &&\n state.selectionManager.focusedKey === node.key\n ) {\n // If item is collapsible, collapse it; else move to parent\n if (hasChildRows && state.expandedKeys.has(node.key)) {\n state.toggleKey(node.key);\n e.stopPropagation();\n return true;\n } else if (\n !state.expandedKeys.has(node.key) &&\n node.parentKey &&\n state.collection.getItem(node.parentKey)?.type === 'item'\n ) {\n // Item is a leaf or already collapsed, move focus to parent\n state.selectionManager.setFocusedKey(node.parentKey);\n e.stopPropagation();\n return true;\n }\n }\n return false;\n}\n\nfunction last(walker: TreeWalker) {\n let next: FocusableElement | null = null;\n let last: FocusableElement | null = null;\n do {\n last = walker.lastChild() as FocusableElement | null;\n if (last) {\n next = last;\n }\n } while (last);\n return next;\n}\n\nfunction getDirectChildren<T>(parent: RSNode<T>, collection: Collection<RSNode<T>>) {\n // We can't assume that we can use firstChildKey because if a person builds a tree using hooks, they would not have access to that property (using type Node vs CollectionNode)\n // Instead, get all children and start at the first node (rather than just using firstChildKey) and only look at its siblings\n let children = collection.getChildren?.(parent.key);\n let childArray = children ? Array.from(children) : [];\n let node = childArray.length > 0 ? childArray[0] : null;\n let siblings: RSNode<T>[] = [];\n while (node) {\n siblings.push(node);\n node = node.nextKey != null ? collection.getItem(node.nextKey) : null;\n }\n return siblings;\n}\n"],"names":[],"version":3,"file":"useGridListItem.mjs.map"}
@@ -32,6 +32,9 @@ $parcel$export(module.exports, "createEventHandler", function () { return $4a9c6
32
32
  },
33
33
  continuePropagation () {
34
34
  shouldStopPropagation = false;
35
+ // nested createEventHandler might have set continue propagation so we should continue
36
+ // propagation on wrappers
37
+ if (typeof e.continuePropagation === 'function') e.continuePropagation();
35
38
  },
36
39
  isPropagationStopped () {
37
40
  return shouldStopPropagation;
@@ -1 +1 @@
1
- {"mappings":";;;;;;AAAA;;;;;;;;;;CAUC,GASM,SAAS,0CACd,OAAmC;IAEnC,IAAI,CAAC,SACH,OAAO;IAGT,IAAI,wBAAwB;IAC5B,OAAO,CAAC;QACN,IAAI,QAAsB;YACxB,GAAG,CAAC;YACJ;gBACE,EAAE,cAAc;YAClB;YACA;gBACE,OAAO,EAAE,kBAAkB;YAC7B;YACA;gBACE,IAAI,yBAAyB,QAAQ,GAAG,CAAC,QAAQ,KAAK,cACpD,QAAQ,KAAK,CACX;qBAGF,wBAAwB;YAE5B;YACA;gBACE,wBAAwB;YAC1B;YACA;gBACE,OAAO;YACT;QACF;QAEA,QAAQ;QAER,IAAI,uBACF,EAAE,eAAe;IAErB;AACF","sources":["packages/react-aria/src/interactions/createEventHandler.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 {BaseEvent} from '@react-types/shared';\nimport {SyntheticEvent} from 'react';\n\n/**\n * This function wraps a React event handler to make stopPropagation the default, and support\n * continuePropagation instead.\n */\nexport function createEventHandler<T extends SyntheticEvent>(\n handler?: (e: BaseEvent<T>) => void\n): ((e: T) => void) | undefined {\n if (!handler) {\n return undefined;\n }\n\n let shouldStopPropagation = true;\n return (e: T) => {\n let event: BaseEvent<T> = {\n ...e,\n preventDefault() {\n e.preventDefault();\n },\n isDefaultPrevented() {\n return e.isDefaultPrevented();\n },\n stopPropagation() {\n if (shouldStopPropagation && process.env.NODE_ENV !== 'production') {\n console.error(\n 'stopPropagation is now the default behavior for events in React Spectrum. You can use continuePropagation() to revert this behavior.'\n );\n } else {\n shouldStopPropagation = true;\n }\n },\n continuePropagation() {\n shouldStopPropagation = false;\n },\n isPropagationStopped() {\n return shouldStopPropagation;\n }\n };\n\n handler(event);\n\n if (shouldStopPropagation) {\n e.stopPropagation();\n }\n };\n}\n"],"names":[],"version":3,"file":"createEventHandler.cjs.map"}
1
+ {"mappings":";;;;;;AAAA;;;;;;;;;;CAUC,GASM,SAAS,0CACd,OAAmC;IAEnC,IAAI,CAAC,SACH,OAAO;IAGT,IAAI,wBAAwB;IAC5B,OAAO,CAAC;QACN,IAAI,QAAsB;YACxB,GAAG,CAAC;YACJ;gBACE,EAAE,cAAc;YAClB;YACA;gBACE,OAAO,EAAE,kBAAkB;YAC7B;YACA;gBACE,IAAI,yBAAyB,QAAQ,GAAG,CAAC,QAAQ,KAAK,cACpD,QAAQ,KAAK,CACX;qBAGF,wBAAwB;YAE5B;YACA;gBACE,wBAAwB;gBACxB,sFAAsF;gBACtF,0BAA0B;gBAC1B,IAAI,OAAO,AAAC,EAAU,mBAAmB,KAAK,YAC5C,AAAC,EAAU,mBAAmB;YAElC;YACA;gBACE,OAAO;YACT;QACF;QAEA,QAAQ;QAER,IAAI,uBACF,EAAE,eAAe;IAErB;AACF","sources":["packages/react-aria/src/interactions/createEventHandler.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 {BaseEvent} from '@react-types/shared';\nimport {SyntheticEvent} from 'react';\n\n/**\n * This function wraps a React event handler to make stopPropagation the default, and support\n * continuePropagation instead.\n */\nexport function createEventHandler<T extends SyntheticEvent>(\n handler?: (e: BaseEvent<T>) => void\n): ((e: T) => void) | undefined {\n if (!handler) {\n return undefined;\n }\n\n let shouldStopPropagation = true;\n return (e: T) => {\n let event: BaseEvent<T> = {\n ...e,\n preventDefault() {\n e.preventDefault();\n },\n isDefaultPrevented() {\n return e.isDefaultPrevented();\n },\n stopPropagation() {\n if (shouldStopPropagation && process.env.NODE_ENV !== 'production') {\n console.error(\n 'stopPropagation is now the default behavior for events in React Spectrum. You can use continuePropagation() to revert this behavior.'\n );\n } else {\n shouldStopPropagation = true;\n }\n },\n continuePropagation() {\n shouldStopPropagation = false;\n // nested createEventHandler might have set continue propagation so we should continue\n // propagation on wrappers\n if (typeof (e as any).continuePropagation === 'function') {\n (e as any).continuePropagation();\n }\n },\n isPropagationStopped() {\n return shouldStopPropagation;\n }\n };\n\n handler(event);\n\n if (shouldStopPropagation) {\n e.stopPropagation();\n }\n };\n}\n"],"names":[],"version":3,"file":"createEventHandler.cjs.map"}
@@ -26,6 +26,9 @@
26
26
  },
27
27
  continuePropagation () {
28
28
  shouldStopPropagation = false;
29
+ // nested createEventHandler might have set continue propagation so we should continue
30
+ // propagation on wrappers
31
+ if (typeof e.continuePropagation === 'function') e.continuePropagation();
29
32
  },
30
33
  isPropagationStopped () {
31
34
  return shouldStopPropagation;
@@ -1 +1 @@
1
- {"mappings":"AAAA;;;;;;;;;;CAUC,GASM,SAAS,0CACd,OAAmC;IAEnC,IAAI,CAAC,SACH,OAAO;IAGT,IAAI,wBAAwB;IAC5B,OAAO,CAAC;QACN,IAAI,QAAsB;YACxB,GAAG,CAAC;YACJ;gBACE,EAAE,cAAc;YAClB;YACA;gBACE,OAAO,EAAE,kBAAkB;YAC7B;YACA;gBACE,IAAI,yBAAyB,QAAQ,GAAG,CAAC,QAAQ,KAAK,cACpD,QAAQ,KAAK,CACX;qBAGF,wBAAwB;YAE5B;YACA;gBACE,wBAAwB;YAC1B;YACA;gBACE,OAAO;YACT;QACF;QAEA,QAAQ;QAER,IAAI,uBACF,EAAE,eAAe;IAErB;AACF","sources":["packages/react-aria/src/interactions/createEventHandler.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 {BaseEvent} from '@react-types/shared';\nimport {SyntheticEvent} from 'react';\n\n/**\n * This function wraps a React event handler to make stopPropagation the default, and support\n * continuePropagation instead.\n */\nexport function createEventHandler<T extends SyntheticEvent>(\n handler?: (e: BaseEvent<T>) => void\n): ((e: T) => void) | undefined {\n if (!handler) {\n return undefined;\n }\n\n let shouldStopPropagation = true;\n return (e: T) => {\n let event: BaseEvent<T> = {\n ...e,\n preventDefault() {\n e.preventDefault();\n },\n isDefaultPrevented() {\n return e.isDefaultPrevented();\n },\n stopPropagation() {\n if (shouldStopPropagation && process.env.NODE_ENV !== 'production') {\n console.error(\n 'stopPropagation is now the default behavior for events in React Spectrum. You can use continuePropagation() to revert this behavior.'\n );\n } else {\n shouldStopPropagation = true;\n }\n },\n continuePropagation() {\n shouldStopPropagation = false;\n },\n isPropagationStopped() {\n return shouldStopPropagation;\n }\n };\n\n handler(event);\n\n if (shouldStopPropagation) {\n e.stopPropagation();\n }\n };\n}\n"],"names":[],"version":3,"file":"createEventHandler.js.map"}
1
+ {"mappings":"AAAA;;;;;;;;;;CAUC,GASM,SAAS,0CACd,OAAmC;IAEnC,IAAI,CAAC,SACH,OAAO;IAGT,IAAI,wBAAwB;IAC5B,OAAO,CAAC;QACN,IAAI,QAAsB;YACxB,GAAG,CAAC;YACJ;gBACE,EAAE,cAAc;YAClB;YACA;gBACE,OAAO,EAAE,kBAAkB;YAC7B;YACA;gBACE,IAAI,yBAAyB,QAAQ,GAAG,CAAC,QAAQ,KAAK,cACpD,QAAQ,KAAK,CACX;qBAGF,wBAAwB;YAE5B;YACA;gBACE,wBAAwB;gBACxB,sFAAsF;gBACtF,0BAA0B;gBAC1B,IAAI,OAAO,AAAC,EAAU,mBAAmB,KAAK,YAC5C,AAAC,EAAU,mBAAmB;YAElC;YACA;gBACE,OAAO;YACT;QACF;QAEA,QAAQ;QAER,IAAI,uBACF,EAAE,eAAe;IAErB;AACF","sources":["packages/react-aria/src/interactions/createEventHandler.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 {BaseEvent} from '@react-types/shared';\nimport {SyntheticEvent} from 'react';\n\n/**\n * This function wraps a React event handler to make stopPropagation the default, and support\n * continuePropagation instead.\n */\nexport function createEventHandler<T extends SyntheticEvent>(\n handler?: (e: BaseEvent<T>) => void\n): ((e: T) => void) | undefined {\n if (!handler) {\n return undefined;\n }\n\n let shouldStopPropagation = true;\n return (e: T) => {\n let event: BaseEvent<T> = {\n ...e,\n preventDefault() {\n e.preventDefault();\n },\n isDefaultPrevented() {\n return e.isDefaultPrevented();\n },\n stopPropagation() {\n if (shouldStopPropagation && process.env.NODE_ENV !== 'production') {\n console.error(\n 'stopPropagation is now the default behavior for events in React Spectrum. You can use continuePropagation() to revert this behavior.'\n );\n } else {\n shouldStopPropagation = true;\n }\n },\n continuePropagation() {\n shouldStopPropagation = false;\n // nested createEventHandler might have set continue propagation so we should continue\n // propagation on wrappers\n if (typeof (e as any).continuePropagation === 'function') {\n (e as any).continuePropagation();\n }\n },\n isPropagationStopped() {\n return shouldStopPropagation;\n }\n };\n\n handler(event);\n\n if (shouldStopPropagation) {\n e.stopPropagation();\n }\n };\n}\n"],"names":[],"version":3,"file":"createEventHandler.js.map"}
@@ -26,6 +26,9 @@
26
26
  },
27
27
  continuePropagation () {
28
28
  shouldStopPropagation = false;
29
+ // nested createEventHandler might have set continue propagation so we should continue
30
+ // propagation on wrappers
31
+ if (typeof e.continuePropagation === 'function') e.continuePropagation();
29
32
  },
30
33
  isPropagationStopped () {
31
34
  return shouldStopPropagation;
@@ -1 +1 @@
1
- {"mappings":"AAAA;;;;;;;;;;CAUC,GASM,SAAS,0CACd,OAAmC;IAEnC,IAAI,CAAC,SACH,OAAO;IAGT,IAAI,wBAAwB;IAC5B,OAAO,CAAC;QACN,IAAI,QAAsB;YACxB,GAAG,CAAC;YACJ;gBACE,EAAE,cAAc;YAClB;YACA;gBACE,OAAO,EAAE,kBAAkB;YAC7B;YACA;gBACE,IAAI,yBAAyB,QAAQ,GAAG,CAAC,QAAQ,KAAK,cACpD,QAAQ,KAAK,CACX;qBAGF,wBAAwB;YAE5B;YACA;gBACE,wBAAwB;YAC1B;YACA;gBACE,OAAO;YACT;QACF;QAEA,QAAQ;QAER,IAAI,uBACF,EAAE,eAAe;IAErB;AACF","sources":["packages/react-aria/src/interactions/createEventHandler.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 {BaseEvent} from '@react-types/shared';\nimport {SyntheticEvent} from 'react';\n\n/**\n * This function wraps a React event handler to make stopPropagation the default, and support\n * continuePropagation instead.\n */\nexport function createEventHandler<T extends SyntheticEvent>(\n handler?: (e: BaseEvent<T>) => void\n): ((e: T) => void) | undefined {\n if (!handler) {\n return undefined;\n }\n\n let shouldStopPropagation = true;\n return (e: T) => {\n let event: BaseEvent<T> = {\n ...e,\n preventDefault() {\n e.preventDefault();\n },\n isDefaultPrevented() {\n return e.isDefaultPrevented();\n },\n stopPropagation() {\n if (shouldStopPropagation && process.env.NODE_ENV !== 'production') {\n console.error(\n 'stopPropagation is now the default behavior for events in React Spectrum. You can use continuePropagation() to revert this behavior.'\n );\n } else {\n shouldStopPropagation = true;\n }\n },\n continuePropagation() {\n shouldStopPropagation = false;\n },\n isPropagationStopped() {\n return shouldStopPropagation;\n }\n };\n\n handler(event);\n\n if (shouldStopPropagation) {\n e.stopPropagation();\n }\n };\n}\n"],"names":[],"version":3,"file":"createEventHandler.mjs.map"}
1
+ {"mappings":"AAAA;;;;;;;;;;CAUC,GASM,SAAS,0CACd,OAAmC;IAEnC,IAAI,CAAC,SACH,OAAO;IAGT,IAAI,wBAAwB;IAC5B,OAAO,CAAC;QACN,IAAI,QAAsB;YACxB,GAAG,CAAC;YACJ;gBACE,EAAE,cAAc;YAClB;YACA;gBACE,OAAO,EAAE,kBAAkB;YAC7B;YACA;gBACE,IAAI,yBAAyB,QAAQ,GAAG,CAAC,QAAQ,KAAK,cACpD,QAAQ,KAAK,CACX;qBAGF,wBAAwB;YAE5B;YACA;gBACE,wBAAwB;gBACxB,sFAAsF;gBACtF,0BAA0B;gBAC1B,IAAI,OAAO,AAAC,EAAU,mBAAmB,KAAK,YAC5C,AAAC,EAAU,mBAAmB;YAElC;YACA;gBACE,OAAO;YACT;QACF;QAEA,QAAQ;QAER,IAAI,uBACF,EAAE,eAAe;IAErB;AACF","sources":["packages/react-aria/src/interactions/createEventHandler.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 {BaseEvent} from '@react-types/shared';\nimport {SyntheticEvent} from 'react';\n\n/**\n * This function wraps a React event handler to make stopPropagation the default, and support\n * continuePropagation instead.\n */\nexport function createEventHandler<T extends SyntheticEvent>(\n handler?: (e: BaseEvent<T>) => void\n): ((e: T) => void) | undefined {\n if (!handler) {\n return undefined;\n }\n\n let shouldStopPropagation = true;\n return (e: T) => {\n let event: BaseEvent<T> = {\n ...e,\n preventDefault() {\n e.preventDefault();\n },\n isDefaultPrevented() {\n return e.isDefaultPrevented();\n },\n stopPropagation() {\n if (shouldStopPropagation && process.env.NODE_ENV !== 'production') {\n console.error(\n 'stopPropagation is now the default behavior for events in React Spectrum. You can use continuePropagation() to revert this behavior.'\n );\n } else {\n shouldStopPropagation = true;\n }\n },\n continuePropagation() {\n shouldStopPropagation = false;\n // nested createEventHandler might have set continue propagation so we should continue\n // propagation on wrappers\n if (typeof (e as any).continuePropagation === 'function') {\n (e as any).continuePropagation();\n }\n },\n isPropagationStopped() {\n return shouldStopPropagation;\n }\n };\n\n handler(event);\n\n if (shouldStopPropagation) {\n e.stopPropagation();\n }\n };\n}\n"],"names":[],"version":3,"file":"createEventHandler.mjs.map"}
@@ -122,11 +122,18 @@ function $d0df89f3abe2c2ca$var$handleWindowBlur() {
122
122
  // However, we need to detect other cases when a focus event occurs without
123
123
  // a preceding user event (e.g. screen reader focus). Overriding the focus
124
124
  // method on HTMLElement.prototype is a bit hacky, but works.
125
+ // defineProperty (not assignment) so this works even if `focus` is currently
126
+ // a getter-only accessor — e.g. when @testing-library/user-event's setup()
127
+ // has instrumented it. Plain assignment throws in that case.
125
128
  let focus = windowObject.HTMLElement.prototype.focus;
126
- windowObject.HTMLElement.prototype.focus = function() {
127
- $d0df89f3abe2c2ca$var$hasEventBeforeFocus = true;
128
- focus.apply(this, arguments);
129
- };
129
+ Reflect.defineProperty(windowObject.HTMLElement.prototype, 'focus', {
130
+ configurable: true,
131
+ writable: true,
132
+ value: function() {
133
+ $d0df89f3abe2c2ca$var$hasEventBeforeFocus = true;
134
+ focus.apply(this, arguments);
135
+ }
136
+ });
130
137
  documentObject.addEventListener('keydown', $d0df89f3abe2c2ca$var$handleKeyboardEvent, true);
131
138
  documentObject.addEventListener('keyup', $d0df89f3abe2c2ca$var$handleKeyboardEvent, true);
132
139
  documentObject.addEventListener('click', $d0df89f3abe2c2ca$var$handleClickEvent, true);
@@ -158,7 +165,11 @@ const $d0df89f3abe2c2ca$var$tearDownWindowFocusTracking = (element, loadListener
158
165
  const documentObject = (0, $49582955cc364b1c$exports.getOwnerDocument)(element);
159
166
  if (loadListener) documentObject.removeEventListener('DOMContentLoaded', loadListener);
160
167
  if (!$d0df89f3abe2c2ca$export$d90243b58daecda7.has(windowObject)) return;
161
- windowObject.HTMLElement.prototype.focus = $d0df89f3abe2c2ca$export$d90243b58daecda7.get(windowObject).focus;
168
+ Reflect.defineProperty(windowObject.HTMLElement.prototype, 'focus', {
169
+ configurable: true,
170
+ writable: true,
171
+ value: $d0df89f3abe2c2ca$export$d90243b58daecda7.get(windowObject).focus
172
+ });
162
173
  documentObject.removeEventListener('keydown', $d0df89f3abe2c2ca$var$handleKeyboardEvent, true);
163
174
  documentObject.removeEventListener('keyup', $d0df89f3abe2c2ca$var$handleKeyboardEvent, true);
164
175
  documentObject.removeEventListener('click', $d0df89f3abe2c2ca$var$handleClickEvent, true);
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC,GAED,kEAAkE;AAClE,2DAA2D;AAC3D,yDAAyD;AACzD,kHAAkH;;;;;;;;;AA6BlH,IAAI,wCAAmC;AACvC,IAAI,2CAAkC;AAC/B,MAAM,4CAAiB,IAAI;AAI3B,IAAI,4CAA2D,IAAI,OAGrE,yFAAyF;AAC9F,IAAI,4CAAsB;AAC1B,IAAI,iDAA2B;AAE/B,sEAAsE;AACtE,MAAM,iDAA2B;IAC/B,KAAK;IACL,QAAQ;AACV;AAEA,SAAS,4CAAsB,QAAkB,EAAE,CAAe;IAChE,KAAK,IAAI,WAAW,0CAClB,QAAQ,UAAU;AAEtB;AAEA;;;CAGC,GACD,SAAS,iC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B;IAC3E,OAAO,CACL,CAAA,eACA,aAAa,cACb,aAAa,kBACb,CAAC,8CAAwB,CAAC,EAAE,GAAG,CAAC,AAAD;AAEnC;AAKO,SAAS,0CAAgB,QAA2B,CAAC,CAAC;IAC3D,IAAI,eAAC,WAAW,aAAE,SAAS,EAAC,GAAG;IAC/B,IAAI,CAAC,qBAAqB,gBAAgB,GAAG,CAAA,GAAA,qBAAO,EAAE,aAAa;IACnE,0CACE,CAAA;QACE,gBAAgB;IAClB,GACA;QAAC;KAAY,EACb;qBAAC;IAAW;IAGd,OAAO;QAAC,gBAAgB;IAAmB;AAC7C;AAKO,SAAS,0CACd,EAAuB,EACvB,IAAwB,EACxB,IAAiD;IAEjD;IAEA,CAAA,GAAA,sBAAQ,EAAE;QACR,IAAI,MAAM,YAAY,OACpB;QAEF,IAAI,UAAU,CAAC,UAAoB;YACjC,0GAA0G;YAC1G,IAAI,CAAC,2CAAqB,CAAC,CAAC,MAAM,aAAa,UAAU,IACvD;YAEF,GAAG;QACL;QACA,0CAAe,GAAG,CAAC;QACnB,OAAO;YACL,0CAAe,MAAM,CAAC;QACxB;IACA,uDAAuD;IACzD,GAAG;AACL","sources":["packages/react-aria/src/interactions/useFocusVisible.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\n// Portions of the code in this file are based on code from react.\n// Original licensing for the following can be found in the\n// NOTICE file in the root directory of this source tree.\n// See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions\n\nimport {getActiveElement, getEventTarget} from '../utils/shadowdom/DOMFunctions';\n\nimport {getOwnerDocument, getOwnerWindow} from '../utils/domHelpers';\nimport {ignoreFocusEvent} from './utils';\nimport {isMac} from '../utils/platform';\nimport {isVirtualClick} from '../utils/isVirtualEvent';\nimport {openLink} from '../utils/openLink';\nimport {PointerType} from '@react-types/shared';\nimport {useEffect, useState} from 'react';\nimport {useIsSSR} from '../ssr/SSRProvider';\n\nexport type Modality = 'keyboard' | 'pointer' | 'virtual';\ntype HandlerEvent = PointerEvent | MouseEvent | KeyboardEvent | FocusEvent | null;\ntype Handler = (modality: Modality, e: HandlerEvent) => void;\nexport type FocusVisibleHandler = (isFocusVisible: boolean) => void;\nexport interface FocusVisibleProps {\n /** Whether the element is a text input. */\n isTextInput?: boolean;\n /** Whether the element will be auto focused. */\n autoFocus?: boolean;\n}\n\nexport interface FocusVisibleResult {\n /** Whether keyboard focus is visible globally. */\n isFocusVisible: boolean;\n}\n\nlet currentModality: null | Modality = null;\nlet currentPointerType: PointerType = 'keyboard';\nexport const changeHandlers = new Set<Handler>();\ninterface GlobalListenerData {\n focus: () => void;\n}\nexport let hasSetupGlobalListeners: Map<Window, GlobalListenerData> = new Map<\n Window,\n GlobalListenerData\n>(); // We use a map here to support setting event listeners across multiple document objects.\nlet hasEventBeforeFocus = false;\nlet hasBlurredWindowRecently = false;\n\n// Only Tab or Esc keys will make focus visible on text input elements\nconst FOCUS_VISIBLE_INPUT_KEYS = {\n Tab: true,\n Escape: true\n};\n\nfunction triggerChangeHandlers(modality: Modality, e: HandlerEvent) {\n for (let handler of changeHandlers) {\n handler(modality, e);\n }\n}\n\n/**\n * Helper function to determine if a KeyboardEvent is unmodified and could make keyboard focus\n * styles visible.\n */\nfunction isValidKey(e: KeyboardEvent) {\n // Control and Shift keys trigger when navigating back to the tab with keyboard.\n return !(\n e.metaKey ||\n (!isMac() && e.altKey) ||\n e.ctrlKey ||\n e.key === 'Control' ||\n e.key === 'Shift' ||\n e.key === 'Meta'\n );\n}\n\nfunction handleKeyboardEvent(e: KeyboardEvent) {\n hasEventBeforeFocus = true;\n if (!(openLink as any).isOpening && isValidKey(e)) {\n currentModality = 'keyboard';\n currentPointerType = 'keyboard';\n triggerChangeHandlers('keyboard', e);\n }\n}\n\nfunction handlePointerEvent(e: PointerEvent | MouseEvent) {\n currentModality = 'pointer';\n currentPointerType = 'pointerType' in e ? (e.pointerType as PointerType) : 'mouse';\n if (e.type === 'mousedown' || e.type === 'pointerdown') {\n hasEventBeforeFocus = true;\n triggerChangeHandlers('pointer', e);\n }\n}\n\nfunction handleClickEvent(e: MouseEvent) {\n if (!(openLink as any).isOpening && isVirtualClick(e)) {\n hasEventBeforeFocus = true;\n currentModality = 'virtual';\n currentPointerType = 'virtual';\n }\n}\n\nfunction handleFocusEvent(e: FocusEvent) {\n // Firefox fires two extra focus events when the user first clicks into an iframe:\n // first on the window, then on the document. We ignore these events so they don't\n // cause keyboard focus rings to appear.\n let ownerWindow = getOwnerWindow(getEventTarget(e) as Element);\n let ownerDocument = getOwnerDocument(getEventTarget(e) as Element);\n if (\n getEventTarget(e) === ownerWindow ||\n getEventTarget(e) === ownerDocument ||\n ignoreFocusEvent ||\n !e.isTrusted\n ) {\n return;\n }\n\n // If a focus event occurs without a preceding keyboard or pointer event, switch to virtual modality.\n // This occurs, for example, when navigating a form with the next/previous buttons on iOS.\n if (!hasEventBeforeFocus && !hasBlurredWindowRecently) {\n currentModality = 'virtual';\n currentPointerType = 'virtual';\n triggerChangeHandlers('virtual', e);\n }\n\n hasEventBeforeFocus = false;\n hasBlurredWindowRecently = false;\n}\n\nfunction handleWindowBlur() {\n if (ignoreFocusEvent) {\n return;\n }\n\n // When the window is blurred, reset state. This is necessary when tabbing out of the window,\n // for example, since a subsequent focus event won't be fired.\n hasEventBeforeFocus = false;\n hasBlurredWindowRecently = true;\n}\n\n/**\n * Setup global event listeners to control when keyboard focus style should be visible.\n */\nfunction setupGlobalFocusEvents(element?: HTMLElement | null) {\n // eslint-disable-next-line no-restricted-globals\n if (typeof window === 'undefined' || typeof document === 'undefined') {\n return;\n }\n\n const windowObject = getOwnerWindow(element);\n const documentObject = getOwnerDocument(element);\n\n if (hasSetupGlobalListeners.get(windowObject)) {\n return;\n }\n\n // Programmatic focus() calls shouldn't affect the current input modality.\n // However, we need to detect other cases when a focus event occurs without\n // a preceding user event (e.g. screen reader focus). Overriding the focus\n // method on HTMLElement.prototype is a bit hacky, but works.\n let focus = windowObject.HTMLElement.prototype.focus;\n windowObject.HTMLElement.prototype.focus = function () {\n hasEventBeforeFocus = true;\n focus.apply(this, arguments as unknown as [options?: FocusOptions | undefined]);\n };\n\n documentObject.addEventListener('keydown', handleKeyboardEvent, true);\n documentObject.addEventListener('keyup', handleKeyboardEvent, true);\n documentObject.addEventListener('click', handleClickEvent, true);\n\n // Register focus events on the window so they are sure to happen\n // before React's event listeners (registered on the document).\n windowObject.addEventListener('focus', handleFocusEvent, true);\n windowObject.addEventListener('blur', handleWindowBlur, false);\n\n if (typeof PointerEvent !== 'undefined') {\n documentObject.addEventListener('pointerdown', handlePointerEvent, true);\n documentObject.addEventListener('pointermove', handlePointerEvent, true);\n documentObject.addEventListener('pointerup', handlePointerEvent, true);\n } else if (process.env.NODE_ENV === 'test') {\n documentObject.addEventListener('mousedown', handlePointerEvent, true);\n documentObject.addEventListener('mousemove', handlePointerEvent, true);\n documentObject.addEventListener('mouseup', handlePointerEvent, true);\n }\n\n // Add unmount handler\n windowObject.addEventListener(\n 'beforeunload',\n () => {\n tearDownWindowFocusTracking(element);\n },\n {once: true}\n );\n\n hasSetupGlobalListeners.set(windowObject, {focus});\n}\n\nconst tearDownWindowFocusTracking = (element, loadListener?: () => void) => {\n const windowObject = getOwnerWindow(element);\n const documentObject = getOwnerDocument(element);\n if (loadListener) {\n documentObject.removeEventListener('DOMContentLoaded', loadListener);\n }\n if (!hasSetupGlobalListeners.has(windowObject)) {\n return;\n }\n windowObject.HTMLElement.prototype.focus = hasSetupGlobalListeners.get(windowObject)!.focus;\n\n documentObject.removeEventListener('keydown', handleKeyboardEvent, true);\n documentObject.removeEventListener('keyup', handleKeyboardEvent, true);\n documentObject.removeEventListener('click', handleClickEvent, true);\n\n windowObject.removeEventListener('focus', handleFocusEvent, true);\n windowObject.removeEventListener('blur', handleWindowBlur, false);\n\n if (typeof PointerEvent !== 'undefined') {\n documentObject.removeEventListener('pointerdown', handlePointerEvent, true);\n documentObject.removeEventListener('pointermove', handlePointerEvent, true);\n documentObject.removeEventListener('pointerup', handlePointerEvent, true);\n } else if (process.env.NODE_ENV === 'test') {\n documentObject.removeEventListener('mousedown', handlePointerEvent, true);\n documentObject.removeEventListener('mousemove', handlePointerEvent, true);\n documentObject.removeEventListener('mouseup', handlePointerEvent, true);\n }\n\n hasSetupGlobalListeners.delete(windowObject);\n};\n\n/**\n * EXPERIMENTAL\n * Adds a window (i.e. iframe) to the list of windows that are being tracked for focus visible.\n *\n * Sometimes apps render portions of their tree into an iframe. In this case, we cannot accurately\n * track if the focus is visible because we cannot see interactions inside the iframe. If you have\n * this in your application's architecture, then this function will attach event listeners inside\n * the iframe. You should call `addWindowFocusTracking` with an element from inside the window you\n * wish to add. We'll retrieve the relevant elements based on that. Note, you do not need to call\n * this for the default window, as we call it for you.\n *\n * When you are ready to stop listening, but you do not wish to unmount the iframe, you may call the\n * cleanup function returned by `addWindowFocusTracking`. Otherwise, when you unmount the iframe,\n * all listeners and state will be cleaned up automatically for you.\n *\n * @param element @default document.body - The element provided will be used to get the window to\n * add.\n * @returns A function to remove the event listeners and cleanup the state.\n */\nexport function addWindowFocusTracking(element?: HTMLElement | null): () => void {\n const documentObject = getOwnerDocument(element);\n let loadListener;\n if (documentObject.readyState !== 'loading') {\n setupGlobalFocusEvents(element);\n } else {\n loadListener = () => {\n setupGlobalFocusEvents(element);\n };\n documentObject.addEventListener('DOMContentLoaded', loadListener);\n }\n\n return () => tearDownWindowFocusTracking(element, loadListener);\n}\n\n// Server-side rendering does not have the document object defined\n// eslint-disable-next-line no-restricted-globals\nif (typeof document !== 'undefined') {\n addWindowFocusTracking();\n}\n\n/**\n * If true, keyboard focus is visible.\n */\nexport function isFocusVisible(): boolean {\n return currentModality !== 'pointer';\n}\n\nexport function getInteractionModality(): Modality | null {\n return currentModality;\n}\n\nexport function setInteractionModality(modality: Modality): void {\n currentModality = modality;\n currentPointerType = modality === 'pointer' ? 'mouse' : modality;\n triggerChangeHandlers(modality, null);\n}\n\n/** @private */\nexport function getPointerType(): PointerType {\n return currentPointerType;\n}\n\n/**\n * Keeps state of the current modality.\n */\nexport function useInteractionModality(): Modality | null {\n setupGlobalFocusEvents();\n\n let [modality, setModality] = useState(currentModality);\n useEffect(() => {\n let handler = () => {\n setModality(currentModality);\n };\n\n changeHandlers.add(handler);\n return () => {\n changeHandlers.delete(handler);\n };\n }, []);\n\n return useIsSSR() ? null : modality;\n}\n\nconst nonTextInputTypes = new Set([\n 'checkbox',\n 'radio',\n 'range',\n 'color',\n 'file',\n 'image',\n 'button',\n 'submit',\n 'reset'\n]);\n\n/**\n * If this is attached to text input component, return if the event is a focus event (Tab/Escape\n * keys pressed) so that focus visible style can be properly set.\n */\nfunction isKeyboardFocusEvent(isTextInput: boolean, modality: Modality, e: HandlerEvent) {\n let eventTarget = e ? (getEventTarget(e) as Element) : undefined;\n let document = getOwnerDocument(eventTarget);\n let ownerWindow = getOwnerWindow(eventTarget);\n const IHTMLInputElement =\n typeof ownerWindow !== 'undefined' ? ownerWindow.HTMLInputElement : HTMLInputElement;\n const IHTMLTextAreaElement =\n typeof ownerWindow !== 'undefined' ? ownerWindow.HTMLTextAreaElement : HTMLTextAreaElement;\n const IHTMLElement = typeof ownerWindow !== 'undefined' ? ownerWindow.HTMLElement : HTMLElement;\n const IKeyboardEvent =\n typeof ownerWindow !== 'undefined' ? ownerWindow.KeyboardEvent : KeyboardEvent;\n\n // For keyboard events that occur on a non-input element that will move focus into input element (aka ArrowLeft going from Datepicker button to the main input group)\n // we need to rely on the user passing isTextInput into here. This way we can skip toggling focus visiblity for said input element\n let activeElement = getActiveElement(document);\n isTextInput =\n isTextInput ||\n (activeElement instanceof IHTMLInputElement && !nonTextInputTypes.has(activeElement.type)) ||\n activeElement instanceof IHTMLTextAreaElement ||\n (activeElement instanceof IHTMLElement && activeElement.isContentEditable);\n return !(\n isTextInput &&\n modality === 'keyboard' &&\n e instanceof IKeyboardEvent &&\n !FOCUS_VISIBLE_INPUT_KEYS[e.key]\n );\n}\n\n/**\n * Manages focus visible state for the page, and subscribes individual components for updates.\n */\nexport function useFocusVisible(props: FocusVisibleProps = {}): FocusVisibleResult {\n let {isTextInput, autoFocus} = props;\n let [isFocusVisibleState, setFocusVisible] = useState(autoFocus || isFocusVisible());\n useFocusVisibleListener(\n isFocusVisible => {\n setFocusVisible(isFocusVisible);\n },\n [isTextInput],\n {isTextInput}\n );\n\n return {isFocusVisible: isFocusVisibleState};\n}\n\n/**\n * Listens for trigger change and reports if focus is visible (i.e., modality is not pointer).\n */\nexport function useFocusVisibleListener(\n fn: FocusVisibleHandler,\n deps: ReadonlyArray<any>,\n opts?: {enabled?: boolean; isTextInput?: boolean}\n): void {\n setupGlobalFocusEvents();\n\n useEffect(() => {\n if (opts?.enabled === false) {\n return;\n }\n let handler = (modality: Modality, e: HandlerEvent) => {\n // We want to early return for any keyboard events that occur inside text inputs EXCEPT for Tab and Escape\n if (!isKeyboardFocusEvent(!!opts?.isTextInput, modality, e)) {\n return;\n }\n fn(isFocusVisible());\n };\n changeHandlers.add(handler);\n return () => {\n changeHandlers.delete(handler);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, deps);\n}\n"],"names":[],"version":3,"file":"useFocusVisible.cjs.map"}
1
+ {"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC,GAED,kEAAkE;AAClE,2DAA2D;AAC3D,yDAAyD;AACzD,kHAAkH;;;;;;;;;AA6BlH,IAAI,wCAAmC;AACvC,IAAI,2CAAkC;AAC/B,MAAM,4CAAiB,IAAI;AAI3B,IAAI,4CAA2D,IAAI,OAGrE,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gBAAgB,GAAG;IACtE,MAAM,uBACJ,OAAO,gBAAgB,cAAc,YAAY,mBAAmB,GAAG;IACzE,MAAM,eAAe,OAAO,gBAAgB,cAAc,YAAY,WAAW,GAAG;IACpF,MAAM,iBACJ,OAAO,gBAAgB,cAAc,YAAY,aAAa,GAAG;IAEnE,qKAAqK;IACrK,kIAAkI;IAClI,IAAI,gBAAgB,CAAA,GAAA,0CAAe,EAAE;IACrC,cACE,eACC,yBAAyB,qBAAqB,CAAC,wCAAkB,GAAG,CAAC,cAAc,IAAI,KACxF,yBAAyB,wBACxB,yBAAyB,gBAAgB,cAAc,iBAAiB;IAC3E,OAAO,CACL,CAAA,eACA,aAAa,cACb,aAAa,kBACb,CAAC,8CAAwB,CAAC,EAAE,GAAG,CAAC,AAAD;AAEnC;AAKO,SAAS,0CAAgB,QAA2B,CAAC,CAAC;IAC3D,IAAI,eAAC,WAAW,aAAE,SAAS,EAAC,GAAG;IAC/B,IAAI,CAAC,qBAAqB,gBAAgB,GAAG,CAAA,GAAA,qBAAO,EAAE,aAAa;IACnE,0CACE,CAAA;QACE,gBAAgB;IAClB,GACA;QAAC;KAAY,EACb;qBAAC;IAAW;IAGd,OAAO;QAAC,gBAAgB;IAAmB;AAC7C;AAKO,SAAS,0CACd,EAAuB,EACvB,IAAwB,EACxB,IAAiD;IAEjD;IAEA,CAAA,GAAA,sBAAQ,EAAE;QACR,IAAI,MAAM,YAAY,OACpB;QAEF,IAAI,UAAU,CAAC,UAAoB;YACjC,0GAA0G;YAC1G,IAAI,CAAC,2CAAqB,CAAC,CAAC,MAAM,aAAa,UAAU,IACvD;YAEF,GAAG;QACL;QACA,0CAAe,GAAG,CAAC;QACnB,OAAO;YACL,0CAAe,MAAM,CAAC;QACxB;IACA,uDAAuD;IACzD,GAAG;AACL","sources":["packages/react-aria/src/interactions/useFocusVisible.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\n// Portions of the code in this file are based on code from react.\n// Original licensing for the following can be found in the\n// NOTICE file in the root directory of this source tree.\n// See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions\n\nimport {getActiveElement, getEventTarget} from '../utils/shadowdom/DOMFunctions';\n\nimport {getOwnerDocument, getOwnerWindow} from '../utils/domHelpers';\nimport {ignoreFocusEvent} from './utils';\nimport {isMac} from '../utils/platform';\nimport {isVirtualClick} from '../utils/isVirtualEvent';\nimport {openLink} from '../utils/openLink';\nimport {PointerType} from '@react-types/shared';\nimport {useEffect, useState} from 'react';\nimport {useIsSSR} from '../ssr/SSRProvider';\n\nexport type Modality = 'keyboard' | 'pointer' | 'virtual';\ntype HandlerEvent = PointerEvent | MouseEvent | KeyboardEvent | FocusEvent | null;\ntype Handler = (modality: Modality, e: HandlerEvent) => void;\nexport type FocusVisibleHandler = (isFocusVisible: boolean) => void;\nexport interface FocusVisibleProps {\n /** Whether the element is a text input. */\n isTextInput?: boolean;\n /** Whether the element will be auto focused. */\n autoFocus?: boolean;\n}\n\nexport interface FocusVisibleResult {\n /** Whether keyboard focus is visible globally. */\n isFocusVisible: boolean;\n}\n\nlet currentModality: null | Modality = null;\nlet currentPointerType: PointerType = 'keyboard';\nexport const changeHandlers = new Set<Handler>();\ninterface GlobalListenerData {\n focus: () => void;\n}\nexport let hasSetupGlobalListeners: Map<Window, GlobalListenerData> = new Map<\n Window,\n GlobalListenerData\n>(); // We use a map here to support setting event listeners across multiple document objects.\nlet hasEventBeforeFocus = false;\nlet hasBlurredWindowRecently = false;\n\n// Only Tab or Esc keys will make focus visible on text input elements\nconst FOCUS_VISIBLE_INPUT_KEYS = {\n Tab: true,\n Escape: true\n};\n\nfunction triggerChangeHandlers(modality: Modality, e: HandlerEvent) {\n for (let handler of changeHandlers) {\n handler(modality, e);\n }\n}\n\n/**\n * Helper function to determine if a KeyboardEvent is unmodified and could make keyboard focus\n * styles visible.\n */\nfunction isValidKey(e: KeyboardEvent) {\n // Control and Shift keys trigger when navigating back to the tab with keyboard.\n return !(\n e.metaKey ||\n (!isMac() && e.altKey) ||\n e.ctrlKey ||\n e.key === 'Control' ||\n e.key === 'Shift' ||\n e.key === 'Meta'\n );\n}\n\nfunction handleKeyboardEvent(e: KeyboardEvent) {\n hasEventBeforeFocus = true;\n if (!(openLink as any).isOpening && isValidKey(e)) {\n currentModality = 'keyboard';\n currentPointerType = 'keyboard';\n triggerChangeHandlers('keyboard', e);\n }\n}\n\nfunction handlePointerEvent(e: PointerEvent | MouseEvent) {\n currentModality = 'pointer';\n currentPointerType = 'pointerType' in e ? (e.pointerType as PointerType) : 'mouse';\n if (e.type === 'mousedown' || e.type === 'pointerdown') {\n hasEventBeforeFocus = true;\n triggerChangeHandlers('pointer', e);\n }\n}\n\nfunction handleClickEvent(e: MouseEvent) {\n if (!(openLink as any).isOpening && isVirtualClick(e)) {\n hasEventBeforeFocus = true;\n currentModality = 'virtual';\n currentPointerType = 'virtual';\n }\n}\n\nfunction handleFocusEvent(e: FocusEvent) {\n // Firefox fires two extra focus events when the user first clicks into an iframe:\n // first on the window, then on the document. We ignore these events so they don't\n // cause keyboard focus rings to appear.\n let ownerWindow = getOwnerWindow(getEventTarget(e) as Element);\n let ownerDocument = getOwnerDocument(getEventTarget(e) as Element);\n if (\n getEventTarget(e) === ownerWindow ||\n getEventTarget(e) === ownerDocument ||\n ignoreFocusEvent ||\n !e.isTrusted\n ) {\n return;\n }\n\n // If a focus event occurs without a preceding keyboard or pointer event, switch to virtual modality.\n // This occurs, for example, when navigating a form with the next/previous buttons on iOS.\n if (!hasEventBeforeFocus && !hasBlurredWindowRecently) {\n currentModality = 'virtual';\n currentPointerType = 'virtual';\n triggerChangeHandlers('virtual', e);\n }\n\n hasEventBeforeFocus = false;\n hasBlurredWindowRecently = false;\n}\n\nfunction handleWindowBlur() {\n if (ignoreFocusEvent) {\n return;\n }\n\n // When the window is blurred, reset state. This is necessary when tabbing out of the window,\n // for example, since a subsequent focus event won't be fired.\n hasEventBeforeFocus = false;\n hasBlurredWindowRecently = true;\n}\n\n/**\n * Setup global event listeners to control when keyboard focus style should be visible.\n */\nfunction setupGlobalFocusEvents(element?: HTMLElement | null) {\n // eslint-disable-next-line no-restricted-globals\n if (typeof window === 'undefined' || typeof document === 'undefined') {\n return;\n }\n\n const windowObject = getOwnerWindow(element);\n const documentObject = getOwnerDocument(element);\n\n if (hasSetupGlobalListeners.get(windowObject)) {\n return;\n }\n\n // Programmatic focus() calls shouldn't affect the current input modality.\n // However, we need to detect other cases when a focus event occurs without\n // a preceding user event (e.g. screen reader focus). Overriding the focus\n // method on HTMLElement.prototype is a bit hacky, but works.\n // defineProperty (not assignment) so this works even if `focus` is currently\n // a getter-only accessor — e.g. when @testing-library/user-event's setup()\n // has instrumented it. Plain assignment throws in that case.\n let focus = windowObject.HTMLElement.prototype.focus;\n Reflect.defineProperty(windowObject.HTMLElement.prototype, 'focus', {\n configurable: true,\n writable: true,\n value: function () {\n hasEventBeforeFocus = true;\n focus.apply(this, arguments as unknown as [options?: FocusOptions | undefined]);\n }\n });\n\n documentObject.addEventListener('keydown', handleKeyboardEvent, true);\n documentObject.addEventListener('keyup', handleKeyboardEvent, true);\n documentObject.addEventListener('click', handleClickEvent, true);\n\n // Register focus events on the window so they are sure to happen\n // before React's event listeners (registered on the document).\n windowObject.addEventListener('focus', handleFocusEvent, true);\n windowObject.addEventListener('blur', handleWindowBlur, false);\n\n if (typeof PointerEvent !== 'undefined') {\n documentObject.addEventListener('pointerdown', handlePointerEvent, true);\n documentObject.addEventListener('pointermove', handlePointerEvent, true);\n documentObject.addEventListener('pointerup', handlePointerEvent, true);\n } else if (process.env.NODE_ENV === 'test') {\n documentObject.addEventListener('mousedown', handlePointerEvent, true);\n documentObject.addEventListener('mousemove', handlePointerEvent, true);\n documentObject.addEventListener('mouseup', handlePointerEvent, true);\n }\n\n // Add unmount handler\n windowObject.addEventListener(\n 'beforeunload',\n () => {\n tearDownWindowFocusTracking(element);\n },\n {once: true}\n );\n\n hasSetupGlobalListeners.set(windowObject, {focus});\n}\n\nconst tearDownWindowFocusTracking = (element, loadListener?: () => void) => {\n const windowObject = getOwnerWindow(element);\n const documentObject = getOwnerDocument(element);\n if (loadListener) {\n documentObject.removeEventListener('DOMContentLoaded', loadListener);\n }\n if (!hasSetupGlobalListeners.has(windowObject)) {\n return;\n }\n Reflect.defineProperty(windowObject.HTMLElement.prototype, 'focus', {\n configurable: true,\n writable: true,\n value: hasSetupGlobalListeners.get(windowObject)!.focus\n });\n\n documentObject.removeEventListener('keydown', handleKeyboardEvent, true);\n documentObject.removeEventListener('keyup', handleKeyboardEvent, true);\n documentObject.removeEventListener('click', handleClickEvent, true);\n\n windowObject.removeEventListener('focus', handleFocusEvent, true);\n windowObject.removeEventListener('blur', handleWindowBlur, false);\n\n if (typeof PointerEvent !== 'undefined') {\n documentObject.removeEventListener('pointerdown', handlePointerEvent, true);\n documentObject.removeEventListener('pointermove', handlePointerEvent, true);\n documentObject.removeEventListener('pointerup', handlePointerEvent, true);\n } else if (process.env.NODE_ENV === 'test') {\n documentObject.removeEventListener('mousedown', handlePointerEvent, true);\n documentObject.removeEventListener('mousemove', handlePointerEvent, true);\n documentObject.removeEventListener('mouseup', handlePointerEvent, true);\n }\n\n hasSetupGlobalListeners.delete(windowObject);\n};\n\n/**\n * EXPERIMENTAL\n * Adds a window (i.e. iframe) to the list of windows that are being tracked for focus visible.\n *\n * Sometimes apps render portions of their tree into an iframe. In this case, we cannot accurately\n * track if the focus is visible because we cannot see interactions inside the iframe. If you have\n * this in your application's architecture, then this function will attach event listeners inside\n * the iframe. You should call `addWindowFocusTracking` with an element from inside the window you\n * wish to add. We'll retrieve the relevant elements based on that. Note, you do not need to call\n * this for the default window, as we call it for you.\n *\n * When you are ready to stop listening, but you do not wish to unmount the iframe, you may call the\n * cleanup function returned by `addWindowFocusTracking`. Otherwise, when you unmount the iframe,\n * all listeners and state will be cleaned up automatically for you.\n *\n * @param element @default document.body - The element provided will be used to get the window to\n * add.\n * @returns A function to remove the event listeners and cleanup the state.\n */\nexport function addWindowFocusTracking(element?: HTMLElement | null): () => void {\n const documentObject = getOwnerDocument(element);\n let loadListener;\n if (documentObject.readyState !== 'loading') {\n setupGlobalFocusEvents(element);\n } else {\n loadListener = () => {\n setupGlobalFocusEvents(element);\n };\n documentObject.addEventListener('DOMContentLoaded', loadListener);\n }\n\n return () => tearDownWindowFocusTracking(element, loadListener);\n}\n\n// Server-side rendering does not have the document object defined\n// eslint-disable-next-line no-restricted-globals\nif (typeof document !== 'undefined') {\n addWindowFocusTracking();\n}\n\n/**\n * If true, keyboard focus is visible.\n */\nexport function isFocusVisible(): boolean {\n return currentModality !== 'pointer';\n}\n\nexport function getInteractionModality(): Modality | null {\n return currentModality;\n}\n\nexport function setInteractionModality(modality: Modality): void {\n currentModality = modality;\n currentPointerType = modality === 'pointer' ? 'mouse' : modality;\n triggerChangeHandlers(modality, null);\n}\n\n/** @private */\nexport function getPointerType(): PointerType {\n return currentPointerType;\n}\n\n/**\n * Keeps state of the current modality.\n */\nexport function useInteractionModality(): Modality | null {\n setupGlobalFocusEvents();\n\n let [modality, setModality] = useState(currentModality);\n useEffect(() => {\n let handler = () => {\n setModality(currentModality);\n };\n\n changeHandlers.add(handler);\n return () => {\n changeHandlers.delete(handler);\n };\n }, []);\n\n return useIsSSR() ? null : modality;\n}\n\nconst nonTextInputTypes = new Set([\n 'checkbox',\n 'radio',\n 'range',\n 'color',\n 'file',\n 'image',\n 'button',\n 'submit',\n 'reset'\n]);\n\n/**\n * If this is attached to text input component, return if the event is a focus event (Tab/Escape\n * keys pressed) so that focus visible style can be properly set.\n */\nfunction isKeyboardFocusEvent(isTextInput: boolean, modality: Modality, e: HandlerEvent) {\n let eventTarget = e ? (getEventTarget(e) as Element) : undefined;\n let document = getOwnerDocument(eventTarget);\n let ownerWindow = getOwnerWindow(eventTarget);\n const IHTMLInputElement =\n typeof ownerWindow !== 'undefined' ? ownerWindow.HTMLInputElement : HTMLInputElement;\n const IHTMLTextAreaElement =\n typeof ownerWindow !== 'undefined' ? ownerWindow.HTMLTextAreaElement : HTMLTextAreaElement;\n const IHTMLElement = typeof ownerWindow !== 'undefined' ? ownerWindow.HTMLElement : HTMLElement;\n const IKeyboardEvent =\n typeof ownerWindow !== 'undefined' ? ownerWindow.KeyboardEvent : KeyboardEvent;\n\n // For keyboard events that occur on a non-input element that will move focus into input element (aka ArrowLeft going from Datepicker button to the main input group)\n // we need to rely on the user passing isTextInput into here. This way we can skip toggling focus visiblity for said input element\n let activeElement = getActiveElement(document);\n isTextInput =\n isTextInput ||\n (activeElement instanceof IHTMLInputElement && !nonTextInputTypes.has(activeElement.type)) ||\n activeElement instanceof IHTMLTextAreaElement ||\n (activeElement instanceof IHTMLElement && activeElement.isContentEditable);\n return !(\n isTextInput &&\n modality === 'keyboard' &&\n e instanceof IKeyboardEvent &&\n !FOCUS_VISIBLE_INPUT_KEYS[e.key]\n );\n}\n\n/**\n * Manages focus visible state for the page, and subscribes individual components for updates.\n */\nexport function useFocusVisible(props: FocusVisibleProps = {}): FocusVisibleResult {\n let {isTextInput, autoFocus} = props;\n let [isFocusVisibleState, setFocusVisible] = useState(autoFocus || isFocusVisible());\n useFocusVisibleListener(\n isFocusVisible => {\n setFocusVisible(isFocusVisible);\n },\n [isTextInput],\n {isTextInput}\n );\n\n return {isFocusVisible: isFocusVisibleState};\n}\n\n/**\n * Listens for trigger change and reports if focus is visible (i.e., modality is not pointer).\n */\nexport function useFocusVisibleListener(\n fn: FocusVisibleHandler,\n deps: ReadonlyArray<any>,\n opts?: {enabled?: boolean; isTextInput?: boolean}\n): void {\n setupGlobalFocusEvents();\n\n useEffect(() => {\n if (opts?.enabled === false) {\n return;\n }\n let handler = (modality: Modality, e: HandlerEvent) => {\n // We want to early return for any keyboard events that occur inside text inputs EXCEPT for Tab and Escape\n if (!isKeyboardFocusEvent(!!opts?.isTextInput, modality, e)) {\n return;\n }\n fn(isFocusVisible());\n };\n changeHandlers.add(handler);\n return () => {\n changeHandlers.delete(handler);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, deps);\n}\n"],"names":[],"version":3,"file":"useFocusVisible.cjs.map"}
@@ -109,11 +109,18 @@ function $b50b1cc8a843ace7$var$handleWindowBlur() {
109
109
  // However, we need to detect other cases when a focus event occurs without
110
110
  // a preceding user event (e.g. screen reader focus). Overriding the focus
111
111
  // method on HTMLElement.prototype is a bit hacky, but works.
112
+ // defineProperty (not assignment) so this works even if `focus` is currently
113
+ // a getter-only accessor — e.g. when @testing-library/user-event's setup()
114
+ // has instrumented it. Plain assignment throws in that case.
112
115
  let focus = windowObject.HTMLElement.prototype.focus;
113
- windowObject.HTMLElement.prototype.focus = function() {
114
- $b50b1cc8a843ace7$var$hasEventBeforeFocus = true;
115
- focus.apply(this, arguments);
116
- };
116
+ Reflect.defineProperty(windowObject.HTMLElement.prototype, 'focus', {
117
+ configurable: true,
118
+ writable: true,
119
+ value: function() {
120
+ $b50b1cc8a843ace7$var$hasEventBeforeFocus = true;
121
+ focus.apply(this, arguments);
122
+ }
123
+ });
117
124
  documentObject.addEventListener('keydown', $b50b1cc8a843ace7$var$handleKeyboardEvent, true);
118
125
  documentObject.addEventListener('keyup', $b50b1cc8a843ace7$var$handleKeyboardEvent, true);
119
126
  documentObject.addEventListener('click', $b50b1cc8a843ace7$var$handleClickEvent, true);
@@ -145,7 +152,11 @@ const $b50b1cc8a843ace7$var$tearDownWindowFocusTracking = (element, loadListener
145
152
  const documentObject = (0, $cc3c3666b64debad$export$b204af158042fbac)(element);
146
153
  if (loadListener) documentObject.removeEventListener('DOMContentLoaded', loadListener);
147
154
  if (!$b50b1cc8a843ace7$export$d90243b58daecda7.has(windowObject)) return;
148
- windowObject.HTMLElement.prototype.focus = $b50b1cc8a843ace7$export$d90243b58daecda7.get(windowObject).focus;
155
+ Reflect.defineProperty(windowObject.HTMLElement.prototype, 'focus', {
156
+ configurable: true,
157
+ writable: true,
158
+ value: $b50b1cc8a843ace7$export$d90243b58daecda7.get(windowObject).focus
159
+ });
149
160
  documentObject.removeEventListener('keydown', $b50b1cc8a843ace7$var$handleKeyboardEvent, true);
150
161
  documentObject.removeEventListener('keyup', $b50b1cc8a843ace7$var$handleKeyboardEvent, true);
151
162
  documentObject.removeEventListener('click', $b50b1cc8a843ace7$var$handleClickEvent, true);
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC,GAED,kEAAkE;AAClE,2DAA2D;AAC3D,yDAAyD;AACzD,kHAAkH;;;;;;;;;AA6BlH,IAAI,wCAAmC;AACvC,IAAI,2CAAkC;AAC/B,MAAM,4CAAiB,IAAI;AAI3B,IAAI,4CAA2D,IAAI,OAGrE,yFAAyF;AAC9F,IAAI,4CAAsB;AAC1B,IAAI,iDAA2B;AAE/B,sEAAsE;AACtE,MAAM,iDAA2B;IAC/B,KAAK;IACL,QAAQ;AACV;AAEA,SAAS,4CAAsB,QAAkB,EAAE,CAAe;IAChE,KAAK,IAAI,WAAW,0CAClB,QAAQ,UAAU;AAEtB;AAEA;;;CAGC,GACD,SAAS,iCAAW,CAAgB;IAClC,gFAAgF;IAChF,OAAO,CACL,CAAA,EAAE,OAAO,IACR,CAAC,CAAA,GAAA,yCAAI,OAAO,EAAE,MAAM,IACrB,EAAE,OAAO,IACT,EAAE,GAAG,KAAK,aACV,EAAE,GAAG,KAAK,WACV,EAAE,GAAG,KAAK,MAAK;AAEnB;AAEA,SAAS,0CAAoB,CAAgB;IAC3C,4CAAsB;IACtB,IAAI,CAAC,AAAC,CAAA,GAAA,yCAAO,EAAU,SAAS,IAAI,iCAAW,IAAI;QACjD,wCAA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IAGd,OAAO;QAAC,gBAAgB;IAAmB;AAC7C;AAKO,SAAS,0CACd,EAAuB,EACvB,IAAwB,EACxB,IAAiD;IAEjD;IAEA,CAAA,GAAA,gBAAQ,EAAE;QACR,IAAI,CAAA,iBAAA,2BAAA,KAAM,OAAO,MAAK,OACpB;QAEF,IAAI,UAAU,CAAC,UAAoB;YACjC,0GAA0G;YAC1G,IAAI,CAAC,2CAAqB,CAAC,EAAC,iBAAA,2BAAA,KAAM,WAAW,GAAE,UAAU,IACvD;YAEF,GAAG;QACL;QACA,0CAAe,GAAG,CAAC;QACnB,OAAO;YACL,0CAAe,MAAM,CAAC;QACxB;IACA,uDAAuD;IACzD,GAAG;AACL","sources":["packages/react-aria/src/interactions/useFocusVisible.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\n// Portions of the code in this file are based on code from react.\n// Original licensing for the following can be found in the\n// NOTICE file in the root directory of this source tree.\n// See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions\n\nimport {getActiveElement, getEventTarget} from '../utils/shadowdom/DOMFunctions';\n\nimport {getOwnerDocument, getOwnerWindow} from '../utils/domHelpers';\nimport {ignoreFocusEvent} from './utils';\nimport {isMac} from '../utils/platform';\nimport {isVirtualClick} from '../utils/isVirtualEvent';\nimport {openLink} from '../utils/openLink';\nimport {PointerType} from '@react-types/shared';\nimport {useEffect, useState} from 'react';\nimport {useIsSSR} from '../ssr/SSRProvider';\n\nexport type Modality = 'keyboard' | 'pointer' | 'virtual';\ntype HandlerEvent = PointerEvent | MouseEvent | KeyboardEvent | FocusEvent | null;\ntype Handler = (modality: Modality, e: HandlerEvent) => void;\nexport type FocusVisibleHandler = (isFocusVisible: boolean) => void;\nexport interface FocusVisibleProps {\n /** Whether the element is a text input. */\n isTextInput?: boolean;\n /** Whether the element will be auto focused. */\n autoFocus?: boolean;\n}\n\nexport interface FocusVisibleResult {\n /** Whether keyboard focus is visible globally. */\n isFocusVisible: boolean;\n}\n\nlet currentModality: null | Modality = null;\nlet currentPointerType: PointerType = 'keyboard';\nexport const changeHandlers = new Set<Handler>();\ninterface GlobalListenerData {\n focus: () => void;\n}\nexport let hasSetupGlobalListeners: Map<Window, GlobalListenerData> = new Map<\n Window,\n GlobalListenerData\n>(); // We use a map here to support setting event listeners across multiple document objects.\nlet hasEventBeforeFocus = false;\nlet hasBlurredWindowRecently = false;\n\n// Only Tab or Esc keys will make focus visible on text input elements\nconst FOCUS_VISIBLE_INPUT_KEYS = {\n Tab: true,\n Escape: true\n};\n\nfunction triggerChangeHandlers(modality: Modality, e: HandlerEvent) {\n for (let handler of changeHandlers) {\n handler(modality, e);\n }\n}\n\n/**\n * Helper function to determine if a KeyboardEvent is unmodified and could make keyboard focus\n * styles visible.\n */\nfunction isValidKey(e: KeyboardEvent) {\n // Control and Shift keys trigger when navigating back to the tab with keyboard.\n return !(\n e.metaKey ||\n (!isMac() && e.altKey) ||\n e.ctrlKey ||\n e.key === 'Control' ||\n e.key === 'Shift' ||\n e.key === 'Meta'\n );\n}\n\nfunction handleKeyboardEvent(e: KeyboardEvent) {\n hasEventBeforeFocus = true;\n if (!(openLink as any).isOpening && isValidKey(e)) {\n currentModality = 'keyboard';\n currentPointerType = 'keyboard';\n triggerChangeHandlers('keyboard', e);\n }\n}\n\nfunction handlePointerEvent(e: PointerEvent | MouseEvent) {\n currentModality = 'pointer';\n currentPointerType = 'pointerType' in e ? (e.pointerType as PointerType) : 'mouse';\n if (e.type === 'mousedown' || e.type === 'pointerdown') {\n hasEventBeforeFocus = true;\n triggerChangeHandlers('pointer', e);\n }\n}\n\nfunction handleClickEvent(e: MouseEvent) {\n if (!(openLink as any).isOpening && isVirtualClick(e)) {\n hasEventBeforeFocus = true;\n currentModality = 'virtual';\n currentPointerType = 'virtual';\n }\n}\n\nfunction handleFocusEvent(e: FocusEvent) {\n // Firefox fires two extra focus events when the user first clicks into an iframe:\n // first on the window, then on the document. We ignore these events so they don't\n // cause keyboard focus rings to appear.\n let ownerWindow = getOwnerWindow(getEventTarget(e) as Element);\n let ownerDocument = getOwnerDocument(getEventTarget(e) as Element);\n if (\n getEventTarget(e) === ownerWindow ||\n getEventTarget(e) === ownerDocument ||\n ignoreFocusEvent ||\n !e.isTrusted\n ) {\n return;\n }\n\n // If a focus event occurs without a preceding keyboard or pointer event, switch to virtual modality.\n // This occurs, for example, when navigating a form with the next/previous buttons on iOS.\n if (!hasEventBeforeFocus && !hasBlurredWindowRecently) {\n currentModality = 'virtual';\n currentPointerType = 'virtual';\n triggerChangeHandlers('virtual', e);\n }\n\n hasEventBeforeFocus = false;\n hasBlurredWindowRecently = false;\n}\n\nfunction handleWindowBlur() {\n if (ignoreFocusEvent) {\n return;\n }\n\n // When the window is blurred, reset state. This is necessary when tabbing out of the window,\n // for example, since a subsequent focus event won't be fired.\n hasEventBeforeFocus = false;\n hasBlurredWindowRecently = true;\n}\n\n/**\n * Setup global event listeners to control when keyboard focus style should be visible.\n */\nfunction setupGlobalFocusEvents(element?: HTMLElement | null) {\n // eslint-disable-next-line no-restricted-globals\n if (typeof window === 'undefined' || typeof document === 'undefined') {\n return;\n }\n\n const windowObject = getOwnerWindow(element);\n const documentObject = getOwnerDocument(element);\n\n if (hasSetupGlobalListeners.get(windowObject)) {\n return;\n }\n\n // Programmatic focus() calls shouldn't affect the current input modality.\n // However, we need to detect other cases when a focus event occurs without\n // a preceding user event (e.g. screen reader focus). Overriding the focus\n // method on HTMLElement.prototype is a bit hacky, but works.\n let focus = windowObject.HTMLElement.prototype.focus;\n windowObject.HTMLElement.prototype.focus = function () {\n hasEventBeforeFocus = true;\n focus.apply(this, arguments as unknown as [options?: FocusOptions | undefined]);\n };\n\n documentObject.addEventListener('keydown', handleKeyboardEvent, true);\n documentObject.addEventListener('keyup', handleKeyboardEvent, true);\n documentObject.addEventListener('click', handleClickEvent, true);\n\n // Register focus events on the window so they are sure to happen\n // before React's event listeners (registered on the document).\n windowObject.addEventListener('focus', handleFocusEvent, true);\n windowObject.addEventListener('blur', handleWindowBlur, false);\n\n if (typeof PointerEvent !== 'undefined') {\n documentObject.addEventListener('pointerdown', handlePointerEvent, true);\n documentObject.addEventListener('pointermove', handlePointerEvent, true);\n documentObject.addEventListener('pointerup', handlePointerEvent, true);\n } else if (process.env.NODE_ENV === 'test') {\n documentObject.addEventListener('mousedown', handlePointerEvent, true);\n documentObject.addEventListener('mousemove', handlePointerEvent, true);\n documentObject.addEventListener('mouseup', handlePointerEvent, true);\n }\n\n // Add unmount handler\n windowObject.addEventListener(\n 'beforeunload',\n () => {\n tearDownWindowFocusTracking(element);\n },\n {once: true}\n );\n\n hasSetupGlobalListeners.set(windowObject, {focus});\n}\n\nconst tearDownWindowFocusTracking = (element, loadListener?: () => void) => {\n const windowObject = getOwnerWindow(element);\n const documentObject = getOwnerDocument(element);\n if (loadListener) {\n documentObject.removeEventListener('DOMContentLoaded', loadListener);\n }\n if (!hasSetupGlobalListeners.has(windowObject)) {\n return;\n }\n windowObject.HTMLElement.prototype.focus = hasSetupGlobalListeners.get(windowObject)!.focus;\n\n documentObject.removeEventListener('keydown', handleKeyboardEvent, true);\n documentObject.removeEventListener('keyup', handleKeyboardEvent, true);\n documentObject.removeEventListener('click', handleClickEvent, true);\n\n windowObject.removeEventListener('focus', handleFocusEvent, true);\n windowObject.removeEventListener('blur', handleWindowBlur, false);\n\n if (typeof PointerEvent !== 'undefined') {\n documentObject.removeEventListener('pointerdown', handlePointerEvent, true);\n documentObject.removeEventListener('pointermove', handlePointerEvent, true);\n documentObject.removeEventListener('pointerup', handlePointerEvent, true);\n } else if (process.env.NODE_ENV === 'test') {\n documentObject.removeEventListener('mousedown', handlePointerEvent, true);\n documentObject.removeEventListener('mousemove', handlePointerEvent, true);\n documentObject.removeEventListener('mouseup', handlePointerEvent, true);\n }\n\n hasSetupGlobalListeners.delete(windowObject);\n};\n\n/**\n * EXPERIMENTAL\n * Adds a window (i.e. iframe) to the list of windows that are being tracked for focus visible.\n *\n * Sometimes apps render portions of their tree into an iframe. In this case, we cannot accurately\n * track if the focus is visible because we cannot see interactions inside the iframe. If you have\n * this in your application's architecture, then this function will attach event listeners inside\n * the iframe. You should call `addWindowFocusTracking` with an element from inside the window you\n * wish to add. We'll retrieve the relevant elements based on that. Note, you do not need to call\n * this for the default window, as we call it for you.\n *\n * When you are ready to stop listening, but you do not wish to unmount the iframe, you may call the\n * cleanup function returned by `addWindowFocusTracking`. Otherwise, when you unmount the iframe,\n * all listeners and state will be cleaned up automatically for you.\n *\n * @param element @default document.body - The element provided will be used to get the window to\n * add.\n * @returns A function to remove the event listeners and cleanup the state.\n */\nexport function addWindowFocusTracking(element?: HTMLElement | null): () => void {\n const documentObject = getOwnerDocument(element);\n let loadListener;\n if (documentObject.readyState !== 'loading') {\n setupGlobalFocusEvents(element);\n } else {\n loadListener = () => {\n setupGlobalFocusEvents(element);\n };\n documentObject.addEventListener('DOMContentLoaded', loadListener);\n }\n\n return () => tearDownWindowFocusTracking(element, loadListener);\n}\n\n// Server-side rendering does not have the document object defined\n// eslint-disable-next-line no-restricted-globals\nif (typeof document !== 'undefined') {\n addWindowFocusTracking();\n}\n\n/**\n * If true, keyboard focus is visible.\n */\nexport function isFocusVisible(): boolean {\n return currentModality !== 'pointer';\n}\n\nexport function getInteractionModality(): Modality | null {\n return currentModality;\n}\n\nexport function setInteractionModality(modality: Modality): void {\n currentModality = modality;\n currentPointerType = modality === 'pointer' ? 'mouse' : modality;\n triggerChangeHandlers(modality, null);\n}\n\n/** @private */\nexport function getPointerType(): PointerType {\n return currentPointerType;\n}\n\n/**\n * Keeps state of the current modality.\n */\nexport function useInteractionModality(): Modality | null {\n setupGlobalFocusEvents();\n\n let [modality, setModality] = useState(currentModality);\n useEffect(() => {\n let handler = () => {\n setModality(currentModality);\n };\n\n changeHandlers.add(handler);\n return () => {\n changeHandlers.delete(handler);\n };\n }, []);\n\n return useIsSSR() ? null : modality;\n}\n\nconst nonTextInputTypes = new Set([\n 'checkbox',\n 'radio',\n 'range',\n 'color',\n 'file',\n 'image',\n 'button',\n 'submit',\n 'reset'\n]);\n\n/**\n * If this is attached to text input component, return if the event is a focus event (Tab/Escape\n * keys pressed) so that focus visible style can be properly set.\n */\nfunction isKeyboardFocusEvent(isTextInput: boolean, modality: Modality, e: HandlerEvent) {\n let eventTarget = e ? (getEventTarget(e) as Element) : undefined;\n let document = getOwnerDocument(eventTarget);\n let ownerWindow = getOwnerWindow(eventTarget);\n const IHTMLInputElement =\n typeof ownerWindow !== 'undefined' ? ownerWindow.HTMLInputElement : HTMLInputElement;\n const IHTMLTextAreaElement =\n typeof ownerWindow !== 'undefined' ? ownerWindow.HTMLTextAreaElement : HTMLTextAreaElement;\n const IHTMLElement = typeof ownerWindow !== 'undefined' ? ownerWindow.HTMLElement : HTMLElement;\n const IKeyboardEvent =\n typeof ownerWindow !== 'undefined' ? ownerWindow.KeyboardEvent : KeyboardEvent;\n\n // For keyboard events that occur on a non-input element that will move focus into input element (aka ArrowLeft going from Datepicker button to the main input group)\n // we need to rely on the user passing isTextInput into here. This way we can skip toggling focus visiblity for said input element\n let activeElement = getActiveElement(document);\n isTextInput =\n isTextInput ||\n (activeElement instanceof IHTMLInputElement && !nonTextInputTypes.has(activeElement.type)) ||\n activeElement instanceof IHTMLTextAreaElement ||\n (activeElement instanceof IHTMLElement && activeElement.isContentEditable);\n return !(\n isTextInput &&\n modality === 'keyboard' &&\n e instanceof IKeyboardEvent &&\n !FOCUS_VISIBLE_INPUT_KEYS[e.key]\n );\n}\n\n/**\n * Manages focus visible state for the page, and subscribes individual components for updates.\n */\nexport function useFocusVisible(props: FocusVisibleProps = {}): FocusVisibleResult {\n let {isTextInput, autoFocus} = props;\n let [isFocusVisibleState, setFocusVisible] = useState(autoFocus || isFocusVisible());\n useFocusVisibleListener(\n isFocusVisible => {\n setFocusVisible(isFocusVisible);\n },\n [isTextInput],\n {isTextInput}\n );\n\n return {isFocusVisible: isFocusVisibleState};\n}\n\n/**\n * Listens for trigger change and reports if focus is visible (i.e., modality is not pointer).\n */\nexport function useFocusVisibleListener(\n fn: FocusVisibleHandler,\n deps: ReadonlyArray<any>,\n opts?: {enabled?: boolean; isTextInput?: boolean}\n): void {\n setupGlobalFocusEvents();\n\n useEffect(() => {\n if (opts?.enabled === false) {\n return;\n }\n let handler = (modality: Modality, e: HandlerEvent) => {\n // We want to early return for any keyboard events that occur inside text inputs EXCEPT for Tab and Escape\n if (!isKeyboardFocusEvent(!!opts?.isTextInput, modality, e)) {\n return;\n }\n fn(isFocusVisible());\n };\n changeHandlers.add(handler);\n return () => {\n changeHandlers.delete(handler);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, deps);\n}\n"],"names":[],"version":3,"file":"useFocusVisible.js.map"}
1
+ {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC,GAED,kEAAkE;AAClE,2DAA2D;AAC3D,yDAAyD;AACzD,kHAAkH;;;;;;;;;AA6BlH,IAAI,wCAAmC;AACvC,IAAI,2CAAkC;AAC/B,MAAM,4CAAiB,IAAI;AAI3B,IAAI,4CAA2D,IAAI,OAGrE,yFAAyF;AAC9F,IAAI,4CAAsB;AAC1B,IAAI,iDAA2B;AAE/B,sEAAsE;AACtE,MAAM,iDAA2B;IAC/B,KAAK;IACL,QAAQ;AACV;AAEA,SAAS,4CAAsB,QAAkB,EAAE,CAAe;IAChE,KAAK,IAAI,WAAW,0CAClB,QAAQ,UAAU;AAEtB;AAEA;;;CAGC,GACD,SAAS,iCAAW,CAAgB;IAClC,gFAAgF;IAChF,OAAO,CACL,CAAA,EAAE,OAAO,IACR,CAAC,CA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AAG,CAAC,cAAc,IAAI,KACxF,yBAAyB,wBACxB,yBAAyB,gBAAgB,cAAc,iBAAiB;IAC3E,OAAO,CACL,CAAA,eACA,aAAa,cACb,aAAa,kBACb,CAAC,8CAAwB,CAAC,EAAE,GAAG,CAAC,AAAD;AAEnC;AAKO,SAAS,0CAAgB,QAA2B,CAAC,CAAC;IAC3D,IAAI,eAAC,WAAW,aAAE,SAAS,EAAC,GAAG;IAC/B,IAAI,CAAC,qBAAqB,gBAAgB,GAAG,CAAA,GAAA,eAAO,EAAE,aAAa;IACnE,0CACE,CAAA;QACE,gBAAgB;IAClB,GACA;QAAC;KAAY,EACb;qBAAC;IAAW;IAGd,OAAO;QAAC,gBAAgB;IAAmB;AAC7C;AAKO,SAAS,0CACd,EAAuB,EACvB,IAAwB,EACxB,IAAiD;IAEjD;IAEA,CAAA,GAAA,gBAAQ,EAAE;QACR,IAAI,CAAA,iBAAA,2BAAA,KAAM,OAAO,MAAK,OACpB;QAEF,IAAI,UAAU,CAAC,UAAoB;YACjC,0GAA0G;YAC1G,IAAI,CAAC,2CAAqB,CAAC,EAAC,iBAAA,2BAAA,KAAM,WAAW,GAAE,UAAU,IACvD;YAEF,GAAG;QACL;QACA,0CAAe,GAAG,CAAC;QACnB,OAAO;YACL,0CAAe,MAAM,CAAC;QACxB;IACA,uDAAuD;IACzD,GAAG;AACL","sources":["packages/react-aria/src/interactions/useFocusVisible.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\n// Portions of the code in this file are based on code from react.\n// Original licensing for the following can be found in the\n// NOTICE file in the root directory of this source tree.\n// See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions\n\nimport {getActiveElement, getEventTarget} from '../utils/shadowdom/DOMFunctions';\n\nimport {getOwnerDocument, getOwnerWindow} from '../utils/domHelpers';\nimport {ignoreFocusEvent} from './utils';\nimport {isMac} from '../utils/platform';\nimport {isVirtualClick} from '../utils/isVirtualEvent';\nimport {openLink} from '../utils/openLink';\nimport {PointerType} from '@react-types/shared';\nimport {useEffect, useState} from 'react';\nimport {useIsSSR} from '../ssr/SSRProvider';\n\nexport type Modality = 'keyboard' | 'pointer' | 'virtual';\ntype HandlerEvent = PointerEvent | MouseEvent | KeyboardEvent | FocusEvent | null;\ntype Handler = (modality: Modality, e: HandlerEvent) => void;\nexport type FocusVisibleHandler = (isFocusVisible: boolean) => void;\nexport interface FocusVisibleProps {\n /** Whether the element is a text input. */\n isTextInput?: boolean;\n /** Whether the element will be auto focused. */\n autoFocus?: boolean;\n}\n\nexport interface FocusVisibleResult {\n /** Whether keyboard focus is visible globally. */\n isFocusVisible: boolean;\n}\n\nlet currentModality: null | Modality = null;\nlet currentPointerType: PointerType = 'keyboard';\nexport const changeHandlers = new Set<Handler>();\ninterface GlobalListenerData {\n focus: () => void;\n}\nexport let hasSetupGlobalListeners: Map<Window, GlobalListenerData> = new Map<\n Window,\n GlobalListenerData\n>(); // We use a map here to support setting event listeners across multiple document objects.\nlet hasEventBeforeFocus = false;\nlet hasBlurredWindowRecently = false;\n\n// Only Tab or Esc keys will make focus visible on text input elements\nconst FOCUS_VISIBLE_INPUT_KEYS = {\n Tab: true,\n Escape: true\n};\n\nfunction triggerChangeHandlers(modality: Modality, e: HandlerEvent) {\n for (let handler of changeHandlers) {\n handler(modality, e);\n }\n}\n\n/**\n * Helper function to determine if a KeyboardEvent is unmodified and could make keyboard focus\n * styles visible.\n */\nfunction isValidKey(e: KeyboardEvent) {\n // Control and Shift keys trigger when navigating back to the tab with keyboard.\n return !(\n e.metaKey ||\n (!isMac() && e.altKey) ||\n e.ctrlKey ||\n e.key === 'Control' ||\n e.key === 'Shift' ||\n e.key === 'Meta'\n );\n}\n\nfunction handleKeyboardEvent(e: KeyboardEvent) {\n hasEventBeforeFocus = true;\n if (!(openLink as any).isOpening && isValidKey(e)) {\n currentModality = 'keyboard';\n currentPointerType = 'keyboard';\n triggerChangeHandlers('keyboard', e);\n }\n}\n\nfunction handlePointerEvent(e: PointerEvent | MouseEvent) {\n currentModality = 'pointer';\n currentPointerType = 'pointerType' in e ? (e.pointerType as PointerType) : 'mouse';\n if (e.type === 'mousedown' || e.type === 'pointerdown') {\n hasEventBeforeFocus = true;\n triggerChangeHandlers('pointer', e);\n }\n}\n\nfunction handleClickEvent(e: MouseEvent) {\n if (!(openLink as any).isOpening && isVirtualClick(e)) {\n hasEventBeforeFocus = true;\n currentModality = 'virtual';\n currentPointerType = 'virtual';\n }\n}\n\nfunction handleFocusEvent(e: FocusEvent) {\n // Firefox fires two extra focus events when the user first clicks into an iframe:\n // first on the window, then on the document. We ignore these events so they don't\n // cause keyboard focus rings to appear.\n let ownerWindow = getOwnerWindow(getEventTarget(e) as Element);\n let ownerDocument = getOwnerDocument(getEventTarget(e) as Element);\n if (\n getEventTarget(e) === ownerWindow ||\n getEventTarget(e) === ownerDocument ||\n ignoreFocusEvent ||\n !e.isTrusted\n ) {\n return;\n }\n\n // If a focus event occurs without a preceding keyboard or pointer event, switch to virtual modality.\n // This occurs, for example, when navigating a form with the next/previous buttons on iOS.\n if (!hasEventBeforeFocus && !hasBlurredWindowRecently) {\n currentModality = 'virtual';\n currentPointerType = 'virtual';\n triggerChangeHandlers('virtual', e);\n }\n\n hasEventBeforeFocus = false;\n hasBlurredWindowRecently = false;\n}\n\nfunction handleWindowBlur() {\n if (ignoreFocusEvent) {\n return;\n }\n\n // When the window is blurred, reset state. This is necessary when tabbing out of the window,\n // for example, since a subsequent focus event won't be fired.\n hasEventBeforeFocus = false;\n hasBlurredWindowRecently = true;\n}\n\n/**\n * Setup global event listeners to control when keyboard focus style should be visible.\n */\nfunction setupGlobalFocusEvents(element?: HTMLElement | null) {\n // eslint-disable-next-line no-restricted-globals\n if (typeof window === 'undefined' || typeof document === 'undefined') {\n return;\n }\n\n const windowObject = getOwnerWindow(element);\n const documentObject = getOwnerDocument(element);\n\n if (hasSetupGlobalListeners.get(windowObject)) {\n return;\n }\n\n // Programmatic focus() calls shouldn't affect the current input modality.\n // However, we need to detect other cases when a focus event occurs without\n // a preceding user event (e.g. screen reader focus). Overriding the focus\n // method on HTMLElement.prototype is a bit hacky, but works.\n // defineProperty (not assignment) so this works even if `focus` is currently\n // a getter-only accessor — e.g. when @testing-library/user-event's setup()\n // has instrumented it. Plain assignment throws in that case.\n let focus = windowObject.HTMLElement.prototype.focus;\n Reflect.defineProperty(windowObject.HTMLElement.prototype, 'focus', {\n configurable: true,\n writable: true,\n value: function () {\n hasEventBeforeFocus = true;\n focus.apply(this, arguments as unknown as [options?: FocusOptions | undefined]);\n }\n });\n\n documentObject.addEventListener('keydown', handleKeyboardEvent, true);\n documentObject.addEventListener('keyup', handleKeyboardEvent, true);\n documentObject.addEventListener('click', handleClickEvent, true);\n\n // Register focus events on the window so they are sure to happen\n // before React's event listeners (registered on the document).\n windowObject.addEventListener('focus', handleFocusEvent, true);\n windowObject.addEventListener('blur', handleWindowBlur, false);\n\n if (typeof PointerEvent !== 'undefined') {\n documentObject.addEventListener('pointerdown', handlePointerEvent, true);\n documentObject.addEventListener('pointermove', handlePointerEvent, true);\n documentObject.addEventListener('pointerup', handlePointerEvent, true);\n } else if (process.env.NODE_ENV === 'test') {\n documentObject.addEventListener('mousedown', handlePointerEvent, true);\n documentObject.addEventListener('mousemove', handlePointerEvent, true);\n documentObject.addEventListener('mouseup', handlePointerEvent, true);\n }\n\n // Add unmount handler\n windowObject.addEventListener(\n 'beforeunload',\n () => {\n tearDownWindowFocusTracking(element);\n },\n {once: true}\n );\n\n hasSetupGlobalListeners.set(windowObject, {focus});\n}\n\nconst tearDownWindowFocusTracking = (element, loadListener?: () => void) => {\n const windowObject = getOwnerWindow(element);\n const documentObject = getOwnerDocument(element);\n if (loadListener) {\n documentObject.removeEventListener('DOMContentLoaded', loadListener);\n }\n if (!hasSetupGlobalListeners.has(windowObject)) {\n return;\n }\n Reflect.defineProperty(windowObject.HTMLElement.prototype, 'focus', {\n configurable: true,\n writable: true,\n value: hasSetupGlobalListeners.get(windowObject)!.focus\n });\n\n documentObject.removeEventListener('keydown', handleKeyboardEvent, true);\n documentObject.removeEventListener('keyup', handleKeyboardEvent, true);\n documentObject.removeEventListener('click', handleClickEvent, true);\n\n windowObject.removeEventListener('focus', handleFocusEvent, true);\n windowObject.removeEventListener('blur', handleWindowBlur, false);\n\n if (typeof PointerEvent !== 'undefined') {\n documentObject.removeEventListener('pointerdown', handlePointerEvent, true);\n documentObject.removeEventListener('pointermove', handlePointerEvent, true);\n documentObject.removeEventListener('pointerup', handlePointerEvent, true);\n } else if (process.env.NODE_ENV === 'test') {\n documentObject.removeEventListener('mousedown', handlePointerEvent, true);\n documentObject.removeEventListener('mousemove', handlePointerEvent, true);\n documentObject.removeEventListener('mouseup', handlePointerEvent, true);\n }\n\n hasSetupGlobalListeners.delete(windowObject);\n};\n\n/**\n * EXPERIMENTAL\n * Adds a window (i.e. iframe) to the list of windows that are being tracked for focus visible.\n *\n * Sometimes apps render portions of their tree into an iframe. In this case, we cannot accurately\n * track if the focus is visible because we cannot see interactions inside the iframe. If you have\n * this in your application's architecture, then this function will attach event listeners inside\n * the iframe. You should call `addWindowFocusTracking` with an element from inside the window you\n * wish to add. We'll retrieve the relevant elements based on that. Note, you do not need to call\n * this for the default window, as we call it for you.\n *\n * When you are ready to stop listening, but you do not wish to unmount the iframe, you may call the\n * cleanup function returned by `addWindowFocusTracking`. Otherwise, when you unmount the iframe,\n * all listeners and state will be cleaned up automatically for you.\n *\n * @param element @default document.body - The element provided will be used to get the window to\n * add.\n * @returns A function to remove the event listeners and cleanup the state.\n */\nexport function addWindowFocusTracking(element?: HTMLElement | null): () => void {\n const documentObject = getOwnerDocument(element);\n let loadListener;\n if (documentObject.readyState !== 'loading') {\n setupGlobalFocusEvents(element);\n } else {\n loadListener = () => {\n setupGlobalFocusEvents(element);\n };\n documentObject.addEventListener('DOMContentLoaded', loadListener);\n }\n\n return () => tearDownWindowFocusTracking(element, loadListener);\n}\n\n// Server-side rendering does not have the document object defined\n// eslint-disable-next-line no-restricted-globals\nif (typeof document !== 'undefined') {\n addWindowFocusTracking();\n}\n\n/**\n * If true, keyboard focus is visible.\n */\nexport function isFocusVisible(): boolean {\n return currentModality !== 'pointer';\n}\n\nexport function getInteractionModality(): Modality | null {\n return currentModality;\n}\n\nexport function setInteractionModality(modality: Modality): void {\n currentModality = modality;\n currentPointerType = modality === 'pointer' ? 'mouse' : modality;\n triggerChangeHandlers(modality, null);\n}\n\n/** @private */\nexport function getPointerType(): PointerType {\n return currentPointerType;\n}\n\n/**\n * Keeps state of the current modality.\n */\nexport function useInteractionModality(): Modality | null {\n setupGlobalFocusEvents();\n\n let [modality, setModality] = useState(currentModality);\n useEffect(() => {\n let handler = () => {\n setModality(currentModality);\n };\n\n changeHandlers.add(handler);\n return () => {\n changeHandlers.delete(handler);\n };\n }, []);\n\n return useIsSSR() ? null : modality;\n}\n\nconst nonTextInputTypes = new Set([\n 'checkbox',\n 'radio',\n 'range',\n 'color',\n 'file',\n 'image',\n 'button',\n 'submit',\n 'reset'\n]);\n\n/**\n * If this is attached to text input component, return if the event is a focus event (Tab/Escape\n * keys pressed) so that focus visible style can be properly set.\n */\nfunction isKeyboardFocusEvent(isTextInput: boolean, modality: Modality, e: HandlerEvent) {\n let eventTarget = e ? (getEventTarget(e) as Element) : undefined;\n let document = getOwnerDocument(eventTarget);\n let ownerWindow = getOwnerWindow(eventTarget);\n const IHTMLInputElement =\n typeof ownerWindow !== 'undefined' ? ownerWindow.HTMLInputElement : HTMLInputElement;\n const IHTMLTextAreaElement =\n typeof ownerWindow !== 'undefined' ? ownerWindow.HTMLTextAreaElement : HTMLTextAreaElement;\n const IHTMLElement = typeof ownerWindow !== 'undefined' ? ownerWindow.HTMLElement : HTMLElement;\n const IKeyboardEvent =\n typeof ownerWindow !== 'undefined' ? ownerWindow.KeyboardEvent : KeyboardEvent;\n\n // For keyboard events that occur on a non-input element that will move focus into input element (aka ArrowLeft going from Datepicker button to the main input group)\n // we need to rely on the user passing isTextInput into here. This way we can skip toggling focus visiblity for said input element\n let activeElement = getActiveElement(document);\n isTextInput =\n isTextInput ||\n (activeElement instanceof IHTMLInputElement && !nonTextInputTypes.has(activeElement.type)) ||\n activeElement instanceof IHTMLTextAreaElement ||\n (activeElement instanceof IHTMLElement && activeElement.isContentEditable);\n return !(\n isTextInput &&\n modality === 'keyboard' &&\n e instanceof IKeyboardEvent &&\n !FOCUS_VISIBLE_INPUT_KEYS[e.key]\n );\n}\n\n/**\n * Manages focus visible state for the page, and subscribes individual components for updates.\n */\nexport function useFocusVisible(props: FocusVisibleProps = {}): FocusVisibleResult {\n let {isTextInput, autoFocus} = props;\n let [isFocusVisibleState, setFocusVisible] = useState(autoFocus || isFocusVisible());\n useFocusVisibleListener(\n isFocusVisible => {\n setFocusVisible(isFocusVisible);\n },\n [isTextInput],\n {isTextInput}\n );\n\n return {isFocusVisible: isFocusVisibleState};\n}\n\n/**\n * Listens for trigger change and reports if focus is visible (i.e., modality is not pointer).\n */\nexport function useFocusVisibleListener(\n fn: FocusVisibleHandler,\n deps: ReadonlyArray<any>,\n opts?: {enabled?: boolean; isTextInput?: boolean}\n): void {\n setupGlobalFocusEvents();\n\n useEffect(() => {\n if (opts?.enabled === false) {\n return;\n }\n let handler = (modality: Modality, e: HandlerEvent) => {\n // We want to early return for any keyboard events that occur inside text inputs EXCEPT for Tab and Escape\n if (!isKeyboardFocusEvent(!!opts?.isTextInput, modality, e)) {\n return;\n }\n fn(isFocusVisible());\n };\n changeHandlers.add(handler);\n return () => {\n changeHandlers.delete(handler);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, deps);\n}\n"],"names":[],"version":3,"file":"useFocusVisible.js.map"}
@@ -109,11 +109,18 @@ function $8f5a2122b0992be3$var$handleWindowBlur() {
109
109
  // However, we need to detect other cases when a focus event occurs without
110
110
  // a preceding user event (e.g. screen reader focus). Overriding the focus
111
111
  // method on HTMLElement.prototype is a bit hacky, but works.
112
+ // defineProperty (not assignment) so this works even if `focus` is currently
113
+ // a getter-only accessor — e.g. when @testing-library/user-event's setup()
114
+ // has instrumented it. Plain assignment throws in that case.
112
115
  let focus = windowObject.HTMLElement.prototype.focus;
113
- windowObject.HTMLElement.prototype.focus = function() {
114
- $8f5a2122b0992be3$var$hasEventBeforeFocus = true;
115
- focus.apply(this, arguments);
116
- };
116
+ Reflect.defineProperty(windowObject.HTMLElement.prototype, 'focus', {
117
+ configurable: true,
118
+ writable: true,
119
+ value: function() {
120
+ $8f5a2122b0992be3$var$hasEventBeforeFocus = true;
121
+ focus.apply(this, arguments);
122
+ }
123
+ });
117
124
  documentObject.addEventListener('keydown', $8f5a2122b0992be3$var$handleKeyboardEvent, true);
118
125
  documentObject.addEventListener('keyup', $8f5a2122b0992be3$var$handleKeyboardEvent, true);
119
126
  documentObject.addEventListener('click', $8f5a2122b0992be3$var$handleClickEvent, true);
@@ -145,7 +152,11 @@ const $8f5a2122b0992be3$var$tearDownWindowFocusTracking = (element, loadListener
145
152
  const documentObject = (0, $d447af545b77c9f1$export$b204af158042fbac)(element);
146
153
  if (loadListener) documentObject.removeEventListener('DOMContentLoaded', loadListener);
147
154
  if (!$8f5a2122b0992be3$export$d90243b58daecda7.has(windowObject)) return;
148
- windowObject.HTMLElement.prototype.focus = $8f5a2122b0992be3$export$d90243b58daecda7.get(windowObject).focus;
155
+ Reflect.defineProperty(windowObject.HTMLElement.prototype, 'focus', {
156
+ configurable: true,
157
+ writable: true,
158
+ value: $8f5a2122b0992be3$export$d90243b58daecda7.get(windowObject).focus
159
+ });
149
160
  documentObject.removeEventListener('keydown', $8f5a2122b0992be3$var$handleKeyboardEvent, true);
150
161
  documentObject.removeEventListener('keyup', $8f5a2122b0992be3$var$handleKeyboardEvent, true);
151
162
  documentObject.removeEventListener('click', $8f5a2122b0992be3$var$handleClickEvent, true);