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ACA,OAAO;QACL,eAAe,MAAM,UAAU,GAC3B,CAAC,IACD;uBACE;qBACA;QACF;IACN;AACF","sources":["packages/react-aria/src/interactions/useKeyboard.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 {chain} from '../utils/chain';\nimport {createEventHandler} from './createEventHandler';\nimport {\n  createKeyboardShortcutHandler,\n  KeyboardShortcutBindings\n} from './createKeyboardShortcutHandler';\nimport {DOMAttributes, KeyboardEvents} from '@react-types/shared';\nimport {getEventTarget, nodeContains} from '../utils/shadowdom/DOMFunctions';\nimport {KeyboardEvent as ReactKeyboardEvent} from 'react';\n\nexport interface KeyboardProps extends KeyboardEvents {\n  /** Whether the keyboard events should be disabled. */\n  isDisabled?: boolean;\n  /** Keyboard shortcuts to handle. */\n  shortcuts?: KeyboardShortcutBindings;\n  /** Whether to allow repeating keys. Only affects shortcuts. */\n  allowRepeats?: boolean;\n  /** Whether to allow composing keys. Only affects shortcuts. */\n  allowComposing?: boolean;\n}\n\nexport interface KeyboardResult {\n  /** Props to spread onto the target element. */\n  keyboardProps: DOMAttributes;\n}\n\n/**\n * Handles keyboard interactions for a focusable element.\n */\nexport function useKeyboard(props: KeyboardProps): KeyboardResult {\n  let {shortcuts, allowRepeats = false, allowComposing = false} = props;\n  let onKeyDown;\n  let onKeyUp;\n  if (shortcuts) {\n    let shortcutHandler = createKeyboardShortcutHandler(shortcuts);\n    let shortcutOnKeyDown = createEventHandler<ReactKeyboardEvent<any>>(e => {\n      // If keyboard event didn't originate from a child of the current target,\n      // then it's a React event coming through a portal. We should ignore it.\n      if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n        e.continuePropagation();\n        return;\n      }\n      if (\n        (e.nativeEvent?.repeat && !allowRepeats) ||\n        (e.nativeEvent?.isComposing && !allowComposing)\n      ) {\n        e.continuePropagation();\n        return;\n      }\n\n      shortcutHandler(e);\n    });\n    let shortcutOnKeyUp = createEventHandler<ReactKeyboardEvent<any>>(e => {\n      // If keyboard event didn't originate from a child of the current target,\n      // then it's a React event coming through a portal. We should ignore it.\n      if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n        e.continuePropagation();\n        return;\n      }\n      if (\n        (e.nativeEvent?.repeat && !allowRepeats) ||\n        (e.nativeEvent?.isComposing && !allowComposing)\n      ) {\n        e.continuePropagation();\n        return;\n      }\n      // implement shortcut handler on keyup, what should the map be called? or should it be another syntax on shortcuts?\n      e.continuePropagation();\n    });\n    onKeyDown = props.onKeyDown ? chain(props.onKeyDown, shortcutOnKeyDown) : shortcutOnKeyDown;\n    onKeyUp = props.onKeyUp ? chain(props.onKeyUp, shortcutOnKeyUp) : shortcutOnKeyUp;\n  } else {\n    onKeyDown = createEventHandler(props.onKeyDown);\n    onKeyUp = createEventHandler(props.onKeyUp);\n  }\n  return {\n    keyboardProps: props.isDisabled\n      ? {}\n      : {\n          onKeyDown,\n          onKeyUp\n        }\n  };\n}\n"],"names":[],"version":3,"file":"useKeyboard.mjs.map"}