Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | 3x | // Escape at the root of select confirms closing the window. Cancel keeps the library and cursor.
/** What the player picked in the exit menu. */
export type ExitMenuChoice = 'leave' | 'cancel';
/** The choice a closed exit menu's `returnValue` names: Leave only when its button closed it. */
export function exitMenuChoice(returnValue: string): ExitMenuChoice {
return returnValue === 'leave' ? 'leave' : 'cancel';
}
/** Opens the exit menu and calls `onChoice` once with what the player picked. A menu already open is left as it is. */
export function showExitMenu(onChoice: (choice: ExitMenuChoice) => void): void {
const dialog = document.querySelector<HTMLDialogElement>('#exit-menu');
if (dialog === null || dialog.open) return;
dialog.returnValue = '';
// The dialog owns keyboard navigation; its keys must not reach the select screen behind it.
dialog.onkeydown = (event) => event.stopPropagation();
dialog.addEventListener('close', () => onChoice(exitMenuChoice(dialog.returnValue)), { once: true });
dialog.showModal();
}
|