@owdproject/core
Version:
Nuxt Desktop module for browser desktop experiences (windows, shell, apps)
31 lines (26 loc) • 800 B
text/typescript
import { useEventListener } from '@vueuse/core'
import { isDebugMode } from '../utils/utilDebug'
/**
* Blocks the browser context menu on non-input elements (typical desktop shell behaviour).
* Debug builds skip blocking so DevTools stay usable when {@link isDebugMode} is true.
*/
export function useBlockNonInputContextMenu() {
useEventListener(
document,
'contextmenu',
(event: MouseEvent) => {
if (isDebugMode()) return
const target = event.target as HTMLElement | null
if (!target) return
const tag = target.tagName?.toLowerCase()
const isInput =
tag === 'input' ||
tag === 'textarea' ||
Boolean(target.isContentEditable)
if (!isInput) {
event.preventDefault()
}
},
{ passive: false },
)
}