{"ast":null,"code":"import _defineProperty from \"@babel/runtime/helpers/defineProperty\";\n\nfunction ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }\n\nfunction _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }\n\nimport { getItemCount } from '@react-stately/collections';\nimport { getItemId } from \"./utils\";\nimport { isFocusVisible } from '@react-aria/interactions';\nimport { useHover, usePress } from '@react-native-aria/interactions';\nimport { isMac, isWebKit, mergeProps, useSlotId } from '@react-aria/utils';\nimport { useSelectableItem } from '@react-aria/selection';\nimport { useMapDomPropsToRN } from '@react-native-aria/utils';\nexport function useOption(props, state, ref) {\n  var isSelected = props.isSelected,\n      isDisabled = props.isDisabled,\n      key = props.key,\n      shouldSelectOnPressUp = props.shouldSelectOnPressUp,\n      shouldFocusOnHover = props.shouldFocusOnHover,\n      isVirtualized = props.isVirtualized,\n      shouldUseVirtualFocus = props.shouldUseVirtualFocus;\n  var labelId = useSlotId();\n  var descriptionId = useSlotId();\n  var _optionProps = {\n    'role': 'option',\n    'aria-disabled': isDisabled,\n    'aria-selected': isSelected\n  };\n\n  if (!(isMac() && isWebKit())) {\n    _optionProps['aria-label'] = props['aria-label'];\n    _optionProps['aria-labelledby'] = labelId;\n    _optionProps['aria-describedby'] = descriptionId;\n  }\n\n  if (isVirtualized) {\n    _optionProps['aria-posinset'] = state.collection.getItem(key).index + 1;\n    _optionProps['aria-setsize'] = getItemCount(state.collection);\n  }\n\n  var _useSelectableItem = useSelectableItem({\n    selectionManager: state.selectionManager,\n    key: key,\n    ref: ref,\n    shouldSelectOnPressUp: shouldSelectOnPressUp,\n    isVirtualized: isVirtualized,\n    shouldUseVirtualFocus: shouldUseVirtualFocus\n  }),\n      itemProps = _useSelectableItem.itemProps;\n\n  var _usePress = usePress(_objectSpread(_objectSpread({}, itemProps), {}, {\n    isDisabled: isDisabled,\n    preventFocusOnPress: shouldUseVirtualFocus\n  })),\n      pressProps = _usePress.pressProps;\n\n  var _useHover = useHover({\n    isDisabled: isDisabled || !shouldFocusOnHover,\n    onHoverStart: function onHoverStart() {\n      if (!isFocusVisible()) {\n        state.selectionManager.setFocused(true);\n        state.selectionManager.setFocusedKey(key);\n      }\n    }\n  }, ref),\n      hoverProps = _useHover.hoverProps;\n\n  var onMouseDown = function onMouseDown(e) {\n    return e.stopPropagation();\n  };\n\n  _optionProps = _objectSpread(_objectSpread(_objectSpread({}, _optionProps), mergeProps(pressProps, hoverProps)), {}, {\n    id: getItemId(state, key),\n    onMouseDown: onMouseDown\n  });\n  var optionProps = useMapDomPropsToRN(_optionProps, ref);\n  return {\n    optionProps: optionProps,\n    labelProps: {\n      nativeID: labelId\n    },\n    descriptionProps: {\n      nativeID: descriptionId\n    }\n  };\n}","map":{"version":3,"sources":["useOption.web.ts"],"names":["shouldUseVirtualFocus","labelId","useSlotId","descriptionId","_optionProps","isSelected","isMac","isWebKit","props","state","getItemCount","itemProps","useSelectableItem","selectionManager","key","ref","shouldSelectOnPressUp","isVirtualized","pressProps","usePress","isDisabled","preventFocusOnPress","hoverProps","useHover","onHoverStart","isFocusVisible","onMouseDown","e","mergeProps","id","getItemId","optionProps","useMapDomPropsToRN","labelProps","nativeID","descriptionProps"],"mappings":";;;;;;AAAA,SAAA,YAAA,QAAA,4BAAA;AACA,SAAA,SAAA;AAEA,SAAA,cAAA,QAAA,0BAAA;AACA,SAAA,QAAA,EAAA,QAAA,QAAA,iCAAA;A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EjC;AADA,KAFP;AAKLkC,IAAAA,gBAAgB,EAAE;AAChBD,MAAAA,QAAQ,EAAE/B;AADM;AALb,GAAP;AASD","sourcesContent":["import { getItemCount } from '@react-stately/collections';\nimport { getItemId } from './utils';\nimport { Key, RefObject } from 'react';\nimport { isFocusVisible } from '@react-aria/interactions';\nimport { useHover, usePress } from '@react-native-aria/interactions';\nimport { isMac, isWebKit, mergeProps, useSlotId } from '@react-aria/utils';\nimport { ListState } from '@react-stately/list';\nimport { useSelectableItem } from '@react-aria/selection';\nimport { useMapDomPropsToRN } from '@react-native-aria/utils';\n\ninterface OptionAria {\n  /** Props for the option element. */\n  optionProps: any;\n\n  /** Props for the main text element inside the option. */\n  labelProps: any;\n\n  /** Props for the description text element inside the option, if any. */\n  descriptionProps: any;\n}\n\ninterface AriaOptionProps {\n  /** Whether the option is disabled. */\n  'isDisabled'?: boolean;\n\n  /** Whether the option is selected. */\n  'isSelected'?: boolean;\n\n  /** A screen reader only label for the option. */\n  'aria-label'?: string;\n\n  /** The unique key for the option. */\n  'key'?: Key;\n\n  /** Whether selection should occur on press up instead of press down. */\n  'shouldSelectOnPressUp'?: boolean;\n\n  /** Whether the option should be focused when the user hovers over it. */\n  'shouldFocusOnHover'?: boolean;\n\n  /** Whether the option is contained in a virtual scrolling listbox. */\n  'isVirtualized'?: boolean;\n\n  /** Whether the option should use virtual focus instead of being focused directly. */\n  'shouldUseVirtualFocus'?: boolean;\n}\n\n/**\n * Provides the behavior and accessibility implementation for an option in a listbox.\n * See `useListBox` for more details about listboxes.\n * @param props - Props for the option.\n * @param state - State for the listbox, as returned by `useListState`.\n */\nexport function useOption<T>(\n  props: AriaOptionProps,\n  state: ListState<T>,\n  ref: RefObject<HTMLElement>\n): OptionAria {\n  let {\n    isSelected,\n    isDisabled,\n    key,\n    shouldSelectOnPressUp,\n    shouldFocusOnHover,\n    isVirtualized,\n    shouldUseVirtualFocus,\n  } = props;\n\n  let labelId = useSlotId();\n  let descriptionId = useSlotId();\n\n  let _optionProps: any = {\n    'role': 'option',\n    'aria-disabled': isDisabled,\n    'aria-selected': isSelected,\n  };\n\n  // Safari with VoiceOver on macOS misreads options with aria-labelledby or aria-label as simply \"text\".\n  // We should not map slots to the label and description on Safari and instead just have VoiceOver read the textContent.\n  // https://bugs.webkit.org/show_bug.cgi?id=209279\n  if (!(isMac() && isWebKit())) {\n    _optionProps['aria-label'] = props['aria-label'];\n    _optionProps['aria-labelledby'] = labelId;\n    _optionProps['aria-describedby'] = descriptionId;\n  }\n\n  if (isVirtualized) {\n    //@ts-ignore\n    _optionProps['aria-posinset'] = state.collection.getItem(key).index + 1;\n    _optionProps['aria-setsize'] = getItemCount(state.collection);\n  }\n\n  let { itemProps } = useSelectableItem({\n    selectionManager: state.selectionManager,\n    //@ts-ignore\n    key,\n    ref,\n    shouldSelectOnPressUp,\n    isVirtualized,\n    shouldUseVirtualFocus,\n  });\n\n  let { pressProps } = usePress({\n    ...itemProps,\n    isDisabled,\n    preventFocusOnPress: shouldUseVirtualFocus,\n  });\n\n  let { hoverProps } = useHover(\n    {\n      isDisabled: isDisabled || !shouldFocusOnHover,\n      onHoverStart() {\n        if (!isFocusVisible()) {\n          state.selectionManager.setFocused(true);\n          //@ts-ignore\n          state.selectionManager.setFocusedKey(key);\n        }\n      },\n    },\n    ref\n  );\n\n  // Putting this as a last resort, after several hours of debugging.\n  // Why?\n  // tabListProps adds onMouseDown with preventDefault in useSelectableCollection.ts (React Aria) and react-native-web uses onClick for onPress.\n  // This results in tab button not getting focused when clicked\n  // See this example - https://codesandbox.io/s/issue-i-know-but-dont-know-why-1-ydyw5?file=/src/App.js\n  const onMouseDown = (e: any) => e.stopPropagation();\n\n  _optionProps = {\n    ..._optionProps,\n    ...mergeProps(pressProps, hoverProps),\n    //@ts-ignore\n    id: getItemId(state, key),\n    onMouseDown,\n  };\n\n  const optionProps = useMapDomPropsToRN(_optionProps, ref);\n\n  return {\n    optionProps,\n    labelProps: {\n      nativeID: labelId,\n    },\n    descriptionProps: {\n      nativeID: descriptionId,\n    },\n  };\n}\n"]},"metadata":{},"sourceType":"module"}