{"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 { filterDOMProps, mergeProps } from '@react-aria/utils';\nimport { listIds } from \"./utils\";\nimport { useId } from '@react-aria/utils';\nimport { useLabel } from '@react-aria/label';\nimport { useSelectableList } from '@react-aria/selection';\nimport { mapDomPropsToRN, useMapDomPropsToRN } from '@react-native-aria/utils';\nexport function useListBox(props, state, ref) {\n  var domProps = filterDOMProps(props, {\n    labelable: true\n  });\n\n  var _useSelectableList = useSelectableList(_objectSpread(_objectSpread({}, props), {}, {\n    ref: ref,\n    selectionManager: state.selectionManager,\n    collection: state.collection,\n    disabledKeys: state.disabledKeys\n  })),\n      listProps = _useSelectableList.listProps;\n\n  var id = useId(props.id);\n  listIds.set(state, id);\n\n  var _useLabel = useLabel(_objectSpread(_objectSpread({}, props), {}, {\n    id: id,\n    labelElementType: 'span'\n  })),\n      _labelProps = _useLabel.labelProps,\n      fieldProps = _useLabel.fieldProps;\n\n  var labelProps = mapDomPropsToRN(_labelProps);\n\n  var _listBoxProps = mergeProps(domProps, state.selectionManager.selectionMode === 'multiple' ? {\n    'aria-multiselectable': 'true'\n  } : {}, _objectSpread({\n    role: 'listbox'\n  }, mergeProps(fieldProps, listProps)));\n\n  var listBoxProps = useMapDomPropsToRN(_listBoxProps, ref);\n  return {\n    labelProps: labelProps,\n    listBoxProps: listBoxProps\n  };\n}","map":{"version":3,"sources":["useListBox.web.ts"],"names":["domProps","filterDOMProps","labelable","listProps","useSelectableList","ref","selectionManager","state","collection","disabledKeys","id","useId","props","listIds","labelProps","fieldProps","useLabel","labelElementType","mapDomPropsToRN","_listBoxProps","mergeProps","role","listBoxProps","useMapDomPropsToRN"],"mappings":";;;;;;AAaA,SAAA,cAAA,EAAA,UAAA,QAAA,mBAAA;AAGA,SAAA,OAAA;AAEA,SAAA,KAAA,QAAA,mBAAA;AACA,SAAA,QAAA,QAAA,mBAAA;AACA,SAAA,iBAAA,QAAA,uBAAA;AACA,SAAA,eAAA,EAAA,kBAAA,QAAA,0BAAA;AA+BA,OAAO,SAAA,UAAA,CAAA,KAAA,EAAA,KAAA,EAAA,GAAA,EAIQ;AACb,MAAIA,QAAQ,GAAGC,cAAc,CAAA,KAAA,EAAQ;AAAEC,IAAAA,SAAS,EAAE;AAAb,GAAR,CAA7B;;AADa,2BAEOE,iBAAiB,iCAAC,KAAD;AAEnCC,IAAAA,GAFoC,EAEpCA,GAFmC;AAGnCC,IAAAA,gBAAgB,EAAEC,KAAK,CAHa,gBAAD;AAInCC,IAAAA,UAAU,EAAED,KAAK,CAJmB,UAAD;AAKnCE,IAAAA,YAAY,EAAEF,KAAK,CAACE;AALe,KAFxB;AAAA,MAEPN,SAFO,sBAEPA,SAFO;;AAUb,MAAIO,EAAE,GAAGC,KAAK,CAACC,KAAK,CAApB,EAAc,CAAd;AACAC,EAAAA,OAAO,CAAPA,GAAAA,CAAAA,KAAAA,EAAAA,EAAAA;;AAXa,kBAaiCG,QAAQ,iCAAC,KAAD;AAEpDN,IAAAA,EAFqD,EAErDA,EAFoD;AAKpDO,IAAAA,gBAAgB,EAAE;AALkC,KAbzC;AAAA,MAaT,WAbS,aAaPH,UAbO;AAAA,MAakBC,UAblB,aAakBA,UAblB;;AAqBb,MAAMD,UAAU,GAAGI,eAAe,CAAlC,WAAkC,CAAlC;;AAEA,MAAMC,aAAa,GAAGC,UAAU,CAAA,QAAA,EAE9B,KAAK,CAAL,gBAAA,CAAA,aAAA,KAAA,UAAA,GACI;AACE,4BAAwB;AAD1B,GADJ,GAF8B,EAAA;AAQ5BC,IAAAA,IAAI,EADN;AAP8B,KASzBD,UAAU,CAAA,UAAA,EAAA,SAAA,CATe,EAAhC;;AAaA,MAAME,YAAY,GAAGC,kBAAkB,CAAA,aAAA,EAAvC,GAAuC,CAAvC;AAEA,SAAO;AACLT,IAAAA,UADK,EACLA,UADK;AAELQ,IAAAA,YAAAA,EAAAA;AAFK,GAAP;AAID","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 { AriaListBoxProps } from '@react-types/listbox';\nimport { filterDOMProps, mergeProps } from '@react-aria/utils';\nimport { HTMLAttributes, ReactNode, RefObject } from 'react';\nimport { KeyboardDelegate } from '@react-types/shared';\nimport { listIds } from './utils';\nimport { ListState } from '@react-stately/list';\nimport { useId } from '@react-aria/utils';\nimport { useLabel } from '@react-aria/label';\nimport { useSelectableList } from '@react-aria/selection';\nimport { mapDomPropsToRN, useMapDomPropsToRN } from '@react-native-aria/utils';\n\ninterface ListBoxAria {\n  /** Props for the listbox element. */\n  listBoxProps: HTMLAttributes<HTMLElement>;\n  /** Props for the listbox's visual label element (if any). */\n  labelProps: HTMLAttributes<HTMLElement>;\n}\n\ninterface AriaListBoxOptions<T> extends Omit<AriaListBoxProps<T>, 'children'> {\n  /** Whether the listbox uses virtual scrolling. */\n  isVirtualized?: boolean;\n\n  /**\n   * An optional keyboard delegate implementation for type to select,\n   * to override the default.\n   */\n  keyboardDelegate?: KeyboardDelegate;\n\n  /**\n   * An optional visual label for the listbox.\n   */\n  label?: ReactNode;\n}\n\n/**\n * Provides the behavior and accessibility implementation for a listbox component.\n * A listbox displays a list of options and allows a user to select one or more of them.\n * @param props - Props for the listbox.\n * @param state - State for the listbox, as returned by `useListState`.\n */\nexport function useListBox<T>(\n  props: AriaListBoxOptions<T>,\n  state: ListState<T>,\n  ref: RefObject<HTMLElement>\n): ListBoxAria {\n  let domProps = filterDOMProps(props, { labelable: true });\n  let { listProps } = useSelectableList({\n    ...props,\n    ref,\n    selectionManager: state.selectionManager,\n    collection: state.collection,\n    disabledKeys: state.disabledKeys,\n  });\n\n  let id = useId(props.id);\n  listIds.set(state, id);\n\n  let { labelProps: _labelProps, fieldProps } = useLabel({\n    ...props,\n    id,\n    // listbox is not an HTML input element so it\n    // shouldn't be labeled by a <label> element.\n    labelElementType: 'span',\n  });\n\n  const labelProps = mapDomPropsToRN(_labelProps);\n\n  const _listBoxProps = mergeProps(\n    domProps,\n    state.selectionManager.selectionMode === 'multiple'\n      ? {\n          'aria-multiselectable': 'true',\n        }\n      : {},\n    {\n      role: 'listbox',\n      ...mergeProps(fieldProps, listProps),\n    }\n  );\n\n  const listBoxProps = useMapDomPropsToRN(_listBoxProps, ref);\n\n  return {\n    labelProps,\n    listBoxProps,\n  };\n}\n"]},"metadata":{},"sourceType":"module"}