2026-04-08 14:01:19 +02:00
|
|
|
import { useEffect, useEffectEvent } from 'react'
|
|
|
|
|
import { handleAppKeyboardEvent } from './appKeyboardShortcuts'
|
|
|
|
|
import type { KeyboardActions } from './appKeyboardShortcuts'
|
2026-02-20 19:59:05 +01:00
|
|
|
|
2026-04-08 14:01:19 +02:00
|
|
|
export type { KeyboardActions } from './appKeyboardShortcuts'
|
2026-02-22 18:42:33 +01:00
|
|
|
|
2026-04-08 14:01:19 +02:00
|
|
|
export function useAppKeyboard(actions: KeyboardActions) {
|
|
|
|
|
const onKeyDown = useEffectEvent((event: KeyboardEvent) => {
|
|
|
|
|
handleAppKeyboardEvent(actions, event)
|
|
|
|
|
})
|
2026-02-22 18:42:33 +01:00
|
|
|
|
2026-02-23 08:53:43 +01:00
|
|
|
useEffect(() => {
|
2026-04-08 14:01:19 +02:00
|
|
|
const handleWindowKeyDown = (event: KeyboardEvent) => {
|
|
|
|
|
onKeyDown(event)
|
2026-02-23 08:53:43 +01:00
|
|
|
}
|
2026-02-21 18:45:25 +01:00
|
|
|
|
2026-04-09 13:16:35 +02:00
|
|
|
window.addEventListener('keydown', handleWindowKeyDown, true)
|
|
|
|
|
return () => window.removeEventListener('keydown', handleWindowKeyDown, true)
|
2026-04-08 14:01:19 +02:00
|
|
|
}, [])
|
2026-02-20 19:59:05 +01:00
|
|
|
}
|