(
hotkey: string,
functionOrUrl: React.MouseEventHandler<HTMLButtonElement> | string,
{signal}: SignalAsOptions = {},
)
| 3 | import {isMac} from './index.js'; |
| 4 | |
| 5 | export function registerHotkey( |
| 6 | hotkey: string, |
| 7 | functionOrUrl: React.MouseEventHandler<HTMLButtonElement> | string, |
| 8 | {signal}: SignalAsOptions = {}, |
| 9 | ): void { |
| 10 | const element = typeof functionOrUrl === 'string' |
| 11 | ? <a hidden href={functionOrUrl} data-hotkey={hotkey} /> |
| 12 | : <button hidden type="button" data-hotkey={hotkey} onClick={functionOrUrl} />; |
| 13 | |
| 14 | document.body.prepend(element); |
| 15 | |
| 16 | signal?.addEventListener('abort', () => { |
| 17 | element.remove(); |
| 18 | }); |
| 19 | } |
| 20 | |
| 21 | /** Safely add a hotkey to an element, preserving any existing ones and avoiding duplicates */ |
| 22 | export function addHotkey(button: HTMLAnchorElement | HTMLButtonElement | undefined, hotkey: string): void { |
no test coverage detected