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AAI,KACN;oBAAA,IAAI,EAAE,OAAO,IAAI,EAAE,GAAG,KAAK,SAAS;wBAClC,sBAAsB,OAAO,GAAG;wBAChC,IAAI,SAAS,EAAE,aAAa;wBAC5B,EAAE,eAAe;wBACjB,WAAW;4BACT,IAAI,CAAC,sBAAsB,OAAO,EAAE;gCAClC,IAAI,OAAO,OAAO,qBAAqB;gCACvC,cAAc;4CACZ;oCACA,GAAG,KAAK,KAAK,GAAG;oCAChB,GAAG,KAAK,MAAM,GAAG;gCACnB;4BACF,OACE,sBAAsB,OAAO,GAAG;wBAEpC,GAAG;oBACL;gBAAA;YAEJ;QACF;IACF;AACF","sources":["packages/react-aria/src/interactions/useContextMenu.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 {HTMLAttributes, useRef} from 'react';\nimport {isIOS, isMac} from '../utils/platform';\nimport {mergeProps} from '../utils/mergeProps';\nimport {useLongPress} from './useLongPress';\n\nexport interface ContextMenuEvent {\n  /** The target element on which the event was triggered. */\n  target: Element;\n  /** X position relative to the target. */\n  x: number;\n  /** Y position relative to the target. */\n  y: number;\n}\n\nexport interface ContextMenuProps {\n  /** Event that is called when a context menu is triggered. */\n  onContextMenu?: (e: ContextMenuEvent) => void;\n}\n\nexport interface ContextMenuAria {\n  /** Props to spread on the target element. */\n  contextMenuProps: HTMLAttributes<HTMLElement>;\n}\n\n/**\n * Handles context menu events across mouse, touch, keyboard, and screen reader interactions.\n */\nexport function useContextMenu(props: ContextMenuProps): ContextMenuAria {\n  // How to trigger context menu events on various platforms:\n  // - macOS\n  //   - Mouse right click\n  //   - Control + click\n  //   - Control + Enter (does not fire the contextmenu event in certain WebKit / Chrome versions - https://bugs.webkit.org/show_bug.cgi?id=302049, https://issues.chromium.org/issues/369897039)\n  //   - Control + Option + Shift + M with VoiceOver\n  // - Windows / Linux\n  //   - Mouse right click\n  //   - Shift + F10\n  //   - Long press on a touch screen\n  // - iOS\n  //   - Long press (does not fire contextmenu event - https://bugs.webkit.org/show_bug.cgi?id=213953)\n  // - Android\n  //   - Long press\n\n  let {onContextMenu} = props;\n  let firedContextMenuEvent = useRef(false);\n\n  // iOS does not fire the contextmenu event, so use long press.\n  let {longPressProps} = useLongPress({\n    onLongPressStart() {\n      firedContextMenuEvent.current = false;\n    },\n    onLongPress(e) {\n      if (!firedContextMenuEvent.current) {\n        onContextMenu?.({target: e.target, x: e.x, y: e.y});\n      } else {\n        firedContextMenuEvent.current = false;\n      }\n    }\n  });\n\n  if (!onContextMenu) {\n    return {\n      contextMenuProps: {}\n    };\n  }\n\n  return {\n    // oxlint-disable-next-line react/react-compiler - it says we are reading a ref during render but that's not true...\n    contextMenuProps: mergeProps(isIOS() ? longPressProps : {}, {\n      onContextMenu(e) {\n        e.stopPropagation();\n        e.preventDefault();\n        firedContextMenuEvent.current = true;\n\n        let rect = e.currentTarget.getBoundingClientRect();\n        onContextMenu({\n          target: e.currentTarget,\n          x: e.clientX - rect.x,\n          y: e.clientY - rect.y\n        });\n      },\n      onKeyDown(e) {\n        // macOS has a default keyboard shortcut to show the contextmenu: Ctrl + Enter.\n        // However, some versions of Safari and Chrome do not trigger the contextmenu event.\n        // Fixed in https://github.com/WebKit/WebKit/pull/62278 (currently in WekKit nightly) and\n        // https://github.com/chromium/chromium/commit/268c876c191cd4712c2d1043aab9760fb71d9be5 (Chrome 147).\n        // Remove this workaround once those are broadly available.\n        // An additional bug still occurs when the target has a border-radius: https://bugs.webkit.org/show_bug.cgi?id=317496\n        if (isMac()) {\n          if (e.ctrlKey && e.key === 'Enter') {\n            firedContextMenuEvent.current = false;\n            let target = e.currentTarget;\n            e.stopPropagation();\n            setTimeout(() => {\n              if (!firedContextMenuEvent.current) {\n                let rect = target.getBoundingClientRect();\n                onContextMenu({\n                  target,\n                  x: rect.width / 2,\n                  y: rect.height / 2\n                });\n              } else {\n                firedContextMenuEvent.current = false;\n              }\n            }, 10);\n          }\n        }\n      }\n    } satisfies HTMLAttributes<HTMLElement>)\n  };\n}\n"],"names":[],"version":3,"file":"useContextMenu.cjs.map"}