{"ast":null,"code":"import _classCallCheck from \"@babel/runtime/helpers/classCallCheck\";\nimport _createClass from \"@babel/runtime/helpers/createClass\";\nimport { useSelectableCollection, useSelectableItem } from \"@react-aria/selection\";\nimport { usePress } from \"@react-aria/interactions\";\nimport { useLocale } from \"@react-aria/i18n\";\nimport { mergeProps, useId, useLabels } from \"@react-aria/utils\";\nimport { useMemo } from \"react\";\nimport _babelRuntimeHelpersEsmExtends from \"@babel/runtime/helpers/esm/extends\";\nvar $ace72fda23df319bd9db38f00073d9$export$TabsKeyboardDelegate = function () {\n  function $ace72fda23df319bd9db38f00073d9$export$TabsKeyboardDelegate(collection, direction, orientation, disabledKeys) {\n    _classCallCheck(this, $ace72fda23df319bd9db38f00073d9$export$TabsKeyboardDelegate);\n    if (disabledKeys === void 0) {\n      disabledKeys = new Set();\n    }\n    this.collection = void 0;\n    this.flipDirection = void 0;\n    this.disabledKeys = void 0;\n    this.orientation = void 0;\n    this.collection = collection;\n    this.flipDirection = direction === 'rtl' && orientation === 'horizontal';\n    this.orientation = orientation;\n    this.disabledKeys = disabledKeys;\n  }\n  _createClass($ace72fda23df319bd9db38f00073d9$export$TabsKeyboardDelegate, [{\n    key: \"getKeyLeftOf\",\n    value: function getKeyLeftOf(key) {\n      if (this.flipDirection) {\n        return this.getNextKey(key);\n      } else {\n        if (this.orientation === 'horizontal') {\n          return this.getPreviousKey(key);\n        }\n        return null;\n      }\n    }\n  }, {\n    key: \"getKeyRightOf\",\n    value: function getKeyRightOf(key) {\n      if (this.flipDirection) {\n        return this.getPreviousKey(key);\n      } else {\n        if (this.orientation === 'horizontal') {\n          return this.getNextKey(key);\n        }\n        return null;\n      }\n    }\n  }, {\n    key: \"getKeyAbove\",\n    value: function getKeyAbove(key) {\n      if (this.orientation === 'vertical') {\n        return this.getPreviousKey(key);\n      }\n      return null;\n    }\n  }, {\n    key: \"getKeyBelow\",\n    value: function getKeyBelow(key) {\n      if (this.orientation === 'vertical') {\n        return this.getNextKey(key);\n      }\n      return null;\n    }\n  }, {\n    key: \"getFirstKey\",\n    value: function getFirstKey() {\n      var key = this.collection.getFirstKey();\n      if (this.disabledKeys.has(key)) {\n        key = this.getNextKey(key);\n      }\n      return key;\n    }\n  }, {\n    key: \"getLastKey\",\n    value: function getLastKey() {\n      var key = this.collection.getLastKey();\n      if (this.disabledKeys.has(key)) {\n        key = this.getPreviousKey(key);\n      }\n      return key;\n    }\n  }, {\n    key: \"getNextKey\",\n    value: function getNextKey(key) {\n      do {\n        key = this.collection.getKeyAfter(key);\n        if (key == null) {\n          key = this.collection.getFirstKey();\n        }\n      } while (this.disabledKeys.has(key));\n      return key;\n    }\n  }, {\n    key: \"getPreviousKey\",\n    value: function getPreviousKey(key) {\n      do {\n        key = this.collection.getKeyBefore(key);\n        if (key == null) {\n          key = this.collection.getLastKey();\n        }\n      } while (this.disabledKeys.has(key));\n      return key;\n    }\n  }]);\n  return $ace72fda23df319bd9db38f00073d9$export$TabsKeyboardDelegate;\n}();\nvar $a98339edf5b490c874cb7f3b44b70$var$tabsIds = new WeakMap();\nexport function useTabs(props, state, ref) {\n  var _props$orientation = props.orientation,\n    orientation = _props$orientation === void 0 ? 'horizontal' : _props$orientation,\n    _props$keyboardActiva = props.keyboardActivation,\n    keyboardActivation = _props$keyboardActiva === void 0 ? 'automatic' : _props$keyboardActiva;\n  var collection = state.collection,\n    manager = state.selectionManager,\n    disabledKeys = state.disabledKeys,\n    selectedKey = state.selectedKey;\n  var _useLocale = useLocale(),\n    direction = _useLocale.direction;\n  var delegate = useMemo(function () {\n    return new $ace72fda23df319bd9db38f00073d9$export$TabsKeyboardDelegate(collection, direction, orientation, disabledKeys);\n  }, [collection, disabledKeys, orientation, direction]);\n  var _useSelectableCollect = useSelectableCollection({\n      ref: ref,\n      selectionManager: manager,\n      keyboardDelegate: delegate,\n      selectOnFocus: keyboardActivation === 'automatic',\n      disallowEmptySelection: true\n    }),\n    collectionProps = _useSelectableCollect.collectionProps;\n  var tabsId = useId();\n  $a98339edf5b490c874cb7f3b44b70$var$tabsIds.set(state, tabsId);\n  var tabListLabelProps = useLabels(_babelRuntimeHelpersEsmExtends({}, props, {\n    id: tabsId\n  }));\n  return {\n    tabListProps: _babelRuntimeHelpersEsmExtends({}, mergeProps(collectionProps, tabListLabelProps), {\n      role: 'tablist',\n      'aria-orientation': orientation,\n      tabIndex: undefined\n    }),\n    tabPanelProps: {\n      id: $a98339edf5b490c874cb7f3b44b70$var$generateId(state, selectedKey, 'tabpanel'),\n      'aria-labelledby': $a98339edf5b490c874cb7f3b44b70$var$generateId(state, selectedKey, 'tab'),\n      tabIndex: 0,\n      role: 'tabpanel'\n    }\n  };\n}\nexport function useTab(props, state, ref) {\n  var item = props.item,\n    propsDisabled = props.isDisabled;\n  var key = item.key;\n  var manager = state.selectionManager,\n    selectedKey = state.selectedKey;\n  var isSelected = key === selectedKey;\n  var _useSelectableItem = useSelectableItem({\n      selectionManager: manager,\n      key: key,\n      ref: ref\n    }),\n    itemProps = _useSelectableItem.itemProps;\n  var isDisabled = propsDisabled || state.disabledKeys.has(key);\n  var _usePress = usePress(_babelRuntimeHelpersEsmExtends({}, itemProps, {\n      isDisabled: isDisabled\n    })),\n    pressProps = _usePress.pressProps;\n  var tabId = $a98339edf5b490c874cb7f3b44b70$var$generateId(state, key, 'tab');\n  var tabPanelId = $a98339edf5b490c874cb7f3b44b70$var$generateId(state, key, 'tabpanel');\n  var tabIndex = pressProps.tabIndex;\n  if (isSelected && !isDisabled) {\n    tabIndex = 0;\n  }\n  return {\n    tabProps: _babelRuntimeHelpersEsmExtends({}, pressProps, {\n      id: tabId,\n      'aria-selected': isSelected,\n      'aria-disabled': isDisabled || undefined,\n      'aria-controls': isSelected ? tabPanelId : undefined,\n      tabIndex: isDisabled ? undefined : tabIndex,\n      role: 'tab'\n    })\n  };\n}\nfunction $a98339edf5b490c874cb7f3b44b70$var$generateId(state, key, role) {\n  if (typeof key === 'string') {\n    key = key.replace(/\\s+/g, '');\n  }\n  var baseId = $a98339edf5b490c874cb7f3b44b70$var$tabsIds.get(state);\n  return baseId + \"-\" + role + \"-\" + key;\n}","map":{"version":3,"sources":["packages/@react-aria/tabs/src/TabsKeyboardDelegate.ts","packages/@react-aria/tabs/src/useTabs.ts"],"names":["TabsKeyboardDelegate","collection","flipDirection","disabledKeys","orientation","constructor","direction","Set","getKeyLeftOf","key","getNextKey","getPreviousKey","getKeyRightOf","getKeyAbove","getKeyBelow","getFirstKey","has","getLastKey","getKeyAfter","getKeyBefore","tabsIds","WeakMap","useTabs","props","state","ref","keyboardActivation","selectionManager","manager","selectedKey","useLocale","delegate","useMemo","collectionProps","useSelectableCollection","keyboardDelegate","selectOnFocus","disallowEmptySelection","tabsId","useId","set","tabListLabelProps","useLabels","id","tabListProps","mergeProps","role","tabIndex","undefined","tabPanelProps","generateId","useTab","item","isDisabled","propsDisabled","isSelected","itemProps","useSelectableItem","pressProps","usePress","tabId","tabPanelId","tabProps","replace","baseId","get"],"mappings":";;;;;;;;IAeaA,2DAAN;EAMLK,SAAAA,4DAAYJ,UAAD,EAA4BK,SAA5B,EAAkDF,WAAlD,EAA4ED,YAA5E,EAAgH;IAAA,eAAA,OAAA,2DAAA;IAAA,IAApCA,YAAoC,KAAA,KAAA,CAAA,EAAA;MAApCA,YAAoC,GAAX,IAAII,GAAJ,CAAA,CAAW;IAAA;IAAA,IAAA,CALnHN,UAKmH,GAAA,KAAA,CAAA;IAAA,IAAA,CAJnHC,aAImH,GAAA,KAAA,CAAA;IAAA,IAAA,CAHnHC,YAGmH,GAAA,KAAA,CAAA;IAAA,IAAA,CAFnHC,WAEmH,GAAA,KAAA,CAAA;IACzH,IAAA,CAAKH,UAAL,GAAkBA,UAAlB;IACA,IAAA,CAAKC,aAAL,GAAqBI,SAAS,KAAK,KAAdA,IAAuBF,WAAW,KAAK,YAA5D;IACA,IAAA,CAAKA,WAAL,GAAmBA,WAAnB;IACA,IAAA,CAAKD,YAAL,GAAoBA,YAApB;EACD;EAAA,YAAA,CAAA,2DAAA;IAA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AAAA,UAAAA;EACL,IAAIE,KAAK,GAAGV,6CAAU,CAAC1B,KAAD,EAAQf,GAAR,EAAa,KAAb,CAAtB;EACA,IAAIoD,UAAU,GAAGX,6CAAU,CAAC1B,KAAD,EAAQf,GAAR,EAAa,UAAb,CAA3B;EACA,IAAKsC,QAAAA,GAAYW,UAjBR,CAiBJX,QAAAA;EAGL,IAAIQ,UAAU,IAAI,CAACF,UAAnB,EAA+B;IAC7BN,QAAQ,GAAG,CAAXA;EACD;EAED,OAAO;IACLe,QAAQ,EAAA,8BAAA,CAAA,CAAA,CAAA,EACHJ,UADG,EAAA;MAENf,EAAE,EAAEiB,KAFE;MAGN,eAAA,EAAiBL,UAHX;MAIN,eAAA,EAAiBF,UAAU,IAAIL,SAJzB;MAKN,eAAA,EAAiBO,UAAU,GAAGM,UAAH,GAAgBb,SALrC;MAMND,QAAQ,EAAEM,UAAU,GAAGL,SAAH,GAAeD,QAN7B;MAOND,IAAI,EAAE;IAPA,CAAA;EADH,CAAP;AAWD;AAED,SAASI,6CAAT,CAAuB1B,KAAvB,EAAwDf,GAAxD,EAAkEqC,IAAlE,EAAgF;EAC9E,IAAI,OAAOrC,GAAP,KAAe,QAAnB,EAA6B;IAC3BA,GAAG,GAAGA,GAAG,CAACsD,OAAJtD,CAAY,MAAZA,EAAoB,EAApBA,CAANA;EACD;EAED,IAAIuD,MAAM,GAAG5C,0CAAO,CAAC6C,GAAR7C,CAAYI,KAAZJ,CAAb;EACA,OAAU4C,MAAV,GAAA,GAAA,GAAoBlB,IAApB,GAAA,GAAA,GAA4BrC,GAA5B;AACD","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 {Collection, Direction, KeyboardDelegate, Orientation} from '@react-types/shared';\nimport {Key} from 'react';\n\nexport class TabsKeyboardDelegate<T> implements KeyboardDelegate {\n  private collection: Collection<T>;\n  private flipDirection: boolean;\n  private disabledKeys: Set<Key>;\n  private orientation: Orientation;\n\n  constructor(collection: Collection<T>, direction: Direction, orientation: Orientation, disabledKeys: Set<Key> = new Set()) {\n    this.collection = collection;\n    this.flipDirection = direction === 'rtl' && orientation === 'horizontal';\n    this.orientation = orientation;\n    this.disabledKeys = disabledKeys;\n  }\n\n  getKeyLeftOf(key: Key) {\n    if (this.flipDirection) {\n      return this.getNextKey(key);\n    } else {\n      if (this.orientation === 'horizontal') {\n        return this.getPreviousKey(key);\n      }\n      return null;\n    }\n  }\n\n  getKeyRightOf(key: Key) {\n    if (this.flipDirection) {\n      return this.getPreviousKey(key);\n    } else {\n      if (this.orientation === 'horizontal') {\n        return this.getNextKey(key);\n      }\n      return null;\n    }\n  }\n\n  getKeyAbove(key: Key) {\n    if (this.orientation === 'vertical') {\n      return this.getPreviousKey(key);\n    }\n    return null;\n  }\n\n  getKeyBelow(key: Key) {\n    if (this.orientation === 'vertical') {\n      return this.getNextKey(key);\n    }\n    return null;\n  }\n\n  getFirstKey() {\n    let key = this.collection.getFirstKey();\n    if (this.disabledKeys.has(key)) {\n      key = this.getNextKey(key);\n    }\n    return key;\n  }\n\n  getLastKey() {\n    let key = this.collection.getLastKey();\n    if (this.disabledKeys.has(key)) {\n      key = this.getPreviousKey(key);\n    }\n    return key;\n  }\n\n  getNextKey(key) {\n    do {\n      key = this.collection.getKeyAfter(key);\n      if (key == null) {\n        key = this.collection.getFirstKey();\n      }\n    } while (this.disabledKeys.has(key));\n    return key;\n  }\n\n  getPreviousKey(key) {\n    do {\n      key = this.collection.getKeyBefore(key);\n      if (key == null) {\n        key = this.collection.getLastKey();\n      }\n    } while (this.disabledKeys.has(key));\n    return key;\n  }\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaTabProps, AriaTabsProps} from '@react-types/tabs';\nimport {HTMLAttributes, Key, RefObject, useMemo} from 'react';\nimport {mergeProps, useId, useLabels} from '@react-aria/utils';\nimport {SingleSelectListState} from '@react-stately/list';\nimport {TabsKeyboardDelegate} from './TabsKeyboardDelegate';\nimport {TabsState} from '@react-stately/tabs';\nimport {useLocale} from '@react-aria/i18n';\nimport {usePress} from '@react-aria/interactions';\nimport {useSelectableCollection, useSelectableItem} from '@react-aria/selection';\n\ninterface TabsAria {\n  /** Props for the tablist container. */\n  tabListProps: HTMLAttributes<HTMLElement>,\n  /** Props for the associated tabpanel element. */\n  tabPanelProps: HTMLAttributes<HTMLElement>\n}\n\nconst tabsIds = new WeakMap<SingleSelectListState<unknown>, string>();\n\nexport function useTabs<T>(props: AriaTabsProps<T>, state: TabsState<T>, ref): TabsAria {\n  let {\n    orientation = 'horizontal',\n    keyboardActivation = 'automatic'\n  } = props;\n  let {\n    collection,\n    selectionManager: manager,\n    disabledKeys,\n    selectedKey\n  } = state;\n  let {direction} = useLocale();\n  let delegate = useMemo(() => new TabsKeyboardDelegate(\n    collection,\n    direction,\n    orientation,\n    disabledKeys), [collection, disabledKeys, orientation, direction]);\n\n  let {collectionProps} = useSelectableCollection({\n    ref,\n    selectionManager: manager,\n    keyboardDelegate: delegate,\n    selectOnFocus: keyboardActivation === 'automatic',\n    disallowEmptySelection: true\n  });\n\n  // Compute base id for all tabs\n  let tabsId = useId();\n  tabsIds.set(state, tabsId);\n\n  let tabListLabelProps = useLabels({...props, id: tabsId});\n\n  return {\n    tabListProps: {\n      ...mergeProps(collectionProps, tabListLabelProps),\n      role: 'tablist',\n      'aria-orientation': orientation,\n      tabIndex: undefined\n    },\n    tabPanelProps: {\n      id: generateId(state, selectedKey, 'tabpanel'),\n      'aria-labelledby': generateId(state, selectedKey, 'tab'),\n      tabIndex: 0,\n      role: 'tabpanel'\n    }\n  };\n}\n\ninterface TabAria {\n  /** Props for the tab element. */\n  tabProps: HTMLAttributes<HTMLElement>\n}\n\nexport function useTab<T>(\n  props: AriaTabProps<T>,\n  state: SingleSelectListState<T>,\n  ref: RefObject<HTMLElement>\n): TabAria {\n  let {item, isDisabled: propsDisabled} = props;\n  let {key} = item;\n  let {selectionManager: manager, selectedKey} = state;\n\n  let isSelected = key === selectedKey;\n\n  let {itemProps} = useSelectableItem({\n    selectionManager: manager,\n    key,\n    ref\n  });\n  let isDisabled = propsDisabled || state.disabledKeys.has(key);\n\n  let {pressProps} = usePress({...itemProps, isDisabled});\n  let tabId = generateId(state, key, 'tab');\n  let tabPanelId = generateId(state, key, 'tabpanel');\n  let {tabIndex} = pressProps;\n\n  // selected tab should have tabIndex=0, when it initializes\n  if (isSelected && !isDisabled) {\n    tabIndex = 0;\n  }\n\n  return {\n    tabProps: {\n      ...pressProps,\n      id: tabId,\n      'aria-selected': isSelected,\n      'aria-disabled': isDisabled || undefined,\n      'aria-controls': isSelected ? tabPanelId : undefined,\n      tabIndex: isDisabled ? undefined : tabIndex,\n      role: 'tab'\n    }\n  };\n}\n\nfunction generateId<T>(state: SingleSelectListState<T>, key: Key, role: string) {\n  if (typeof key === 'string') {\n    key = key.replace(/\\s+/g, '');\n  }\n\n  let baseId = tabsIds.get(state);\n  return `${baseId}-${role}-${key}`;\n}\n"]},"metadata":{},"sourceType":"module"}