{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAgDM,SAAS,0CAAoB,KAAuB;IACzD,IAAI,sBAAsB,CAAA,GAAA,gDAAqB,EAAE;IACjD,IAAI,CAAC,eAAe,iBAAiB,GAAG,CAAA,GAAA,qBAAO,EAAwB;IACvE,IAAI,CAAC,mBAAmB,qBAAqB,GAAG,CAAA,GAAA,qBAAO,EAAS,EAAE;IAElE,IAAI,WAAW;QACb,qBAAqB,EAAE;QACvB,oBAAoB,KAAK;IAC3B;IAEA,IAAI,cAAc,CAAC,YAAiB;QAClC,qBAAqB,CAAA;YACnB,IAAI,QAAQ,SAAS,MAAM,EACzB,OAAO;YAGT,OAAO;mBAAI,SAAS,KAAK,CAAC,GAAG;gBAAQ;aAAW;QAClD;IACF;IAEA,IAAI,eAAe,CAAC,YAAiB;QACnC,qBAAqB,CAAA;YACnB,IAAI,MAAM,QAAQ,CAAC,MAAM;YACzB,IAAI,QAAQ,YACV,OAAO,SAAS,KAAK,CAAC,GAAG;iBAEzB,OAAO;QAEX;IACF;IAEA,OAAO;uBACL;QACA,GAAG,mBAAmB;QACtB,MAAK,gBAAsC,IAAI;YAC7C,iBAAiB;YACjB,oBAAoB,IAAI;QAC1B;QACA,QAAO,gBAAsC,IAAI;YAC/C,iBAAiB;YACjB,oBAAoB,MAAM;QAC5B;QACA;YACE;QACF;2BACA;qBACA;sBACA;IACF;AACF","sources":["packages/react-stately/src/menu/useMenuTriggerState.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 {FocusStrategy, Key} from '@react-types/shared';\nimport {OverlayTriggerProps, OverlayTriggerState, useOverlayTriggerState} from '../overlays/useOverlayTriggerState';\nimport {useState} from 'react';\n\nexport type MenuTriggerType = 'press' | 'longPress';\n\nexport interface MenuTriggerProps extends OverlayTriggerProps {\n  /**\n   * How the menu is triggered.\n   * @default 'press'\n   */\n  trigger?: MenuTriggerType\n}\n\nexport interface MenuTriggerState extends OverlayTriggerState {\n  /** Controls which item will be auto focused when the menu opens. */\n  readonly focusStrategy: FocusStrategy | null,\n\n  /** Opens the menu. */\n  open(focusStrategy?: FocusStrategy | null): void,\n\n  /** Toggles the menu. */\n  toggle(focusStrategy?: FocusStrategy | null): void\n}\n\nexport interface RootMenuTriggerState extends MenuTriggerState {\n  /** Opens a specific submenu tied to a specific menu item at a specific level. */\n  openSubmenu: (triggerKey: Key, level: number) => void,\n\n  /** Closes a specific submenu tied to a specific menu item at a specific level. */\n  closeSubmenu: (triggerKey: Key, level: number) => void,\n\n  /** An array of open submenu trigger keys within the menu tree.\n   * The index of key within array matches the submenu level in the tree.\n   */\n  expandedKeysStack: Key[],\n\n  /** Closes the menu and all submenus in the menu tree. */\n  close: () => void\n}\n\n/**\n * Manages state for a menu trigger. Tracks whether the menu is currently open,\n * and controls which item will receive focus when it opens. Also tracks the open submenus within\n * the menu tree via their trigger keys.\n */\nexport function useMenuTriggerState(props: MenuTriggerProps): RootMenuTriggerState  {\n  let overlayTriggerState = useOverlayTriggerState(props);\n  let [focusStrategy, setFocusStrategy] = useState<FocusStrategy | null>(null);\n  let [expandedKeysStack, setExpandedKeysStack] = useState<Key[]>([]);\n\n  let closeAll = () => {\n    setExpandedKeysStack([]);\n    overlayTriggerState.close();\n  };\n\n  let openSubmenu = (triggerKey: Key, level: number) => {\n    setExpandedKeysStack(oldStack => {\n      if (level > oldStack.length) {\n        return oldStack;\n      }\n\n      return [...oldStack.slice(0, level), triggerKey];\n    });\n  };\n\n  let closeSubmenu = (triggerKey: Key, level: number) => {\n    setExpandedKeysStack(oldStack => {\n      let key = oldStack[level];\n      if (key === triggerKey) {\n        return oldStack.slice(0, level);\n      } else {\n        return oldStack;\n      }\n    });\n  };\n\n  return {\n    focusStrategy,\n    ...overlayTriggerState,\n    open(focusStrategy: FocusStrategy | null = null) {\n      setFocusStrategy(focusStrategy);\n      overlayTriggerState.open();\n    },\n    toggle(focusStrategy: FocusStrategy | null = null) {\n      setFocusStrategy(focusStrategy);\n      overlayTriggerState.toggle();\n    },\n    close() {\n      closeAll();\n    },\n    expandedKeysStack,\n    openSubmenu,\n    closeSubmenu\n  };\n}\n"],"names":[],"version":3,"file":"useMenuTriggerState.cjs.map"}