web-player: unify primitive link/button rendering, add onEscape action and self-contained AccountMenu
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import type { Action } from 'svelte/action';
|
||||
|
||||
export const onEscape: Action<HTMLElement, (() => void) | undefined> = (_node, handler) => {
|
||||
function onKeydown(event: KeyboardEvent) {
|
||||
if (event.key === 'Escape') handler?.();
|
||||
}
|
||||
window.addEventListener('keydown', onKeydown);
|
||||
|
||||
return {
|
||||
update(next) {
|
||||
handler = next;
|
||||
},
|
||||
destroy() {
|
||||
window.removeEventListener('keydown', onKeydown);
|
||||
}
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user