// fixtures/editor-inert.mjs — the editor while a change waits for its // font (editor-fonts.mjs): the stage, the strip, the inspector and the // menus go inert, like a short modal. Kept apart so editor-fonts.mjs // stays the gate itself. // // While the editor is inert, focus is on the page itself, and there a // key that would have edited is the browser's: Backspace goes back in // history in WebKit (Docs' review 8, which lost the waiting paste), // Space and the arrows scroll. Those keys do nothing during the wait. // A real control outside the inert parts keeps them, and so does Tab. // Leaving the page while a change waits asks first. const HELD_KEYS = new Set(['Backspace', ' ', 'Spacebar', 'ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'PageUp', 'PageDown', 'Home', 'End']) const holdKeys = e => { if (!HELD_KEYS.has(e.key)) return const t = e.target if (!t || t === document.body || t === document.documentElement || (t.closest && t.closest('[inert]'))) e.preventDefault() } const holdUnload = e => { e.preventDefault() e.returnValue = '' } /** setInert(on) for the editor under root; onInert() runs as it goes inert. */ export function createInert (root, onInert) { const inertParts = () => [ root.querySelector('[slides-stage-pane]'), root.querySelector('[slides-strip-nav]'), root.querySelector('[slides-inspector]'), root.querySelector('[slides-deck-dialog]'), root.querySelector('[slides-menubar]'), root.querySelector('[slides-history]'), root.querySelector('[slides-head-title]') ].filter(Boolean) let focusBack = null let inertOn = false return function setInert (on) { if (on === inertOn) return inertOn = on const listen = on ? 'addEventListener' : 'removeEventListener' globalThis[listen]('keydown', holdKeys) globalThis[listen]('beforeunload', holdUnload) const parts = inertParts() if (on) { const active = document.activeElement focusBack = active && parts.some(el => el.contains(active)) ? active : null } for (const el of parts) el.inert = on const pane = root.querySelector('[slides-stage-pane]') if (pane) pane.setAttribute('aria-busy', on ? 'true' : 'false') if (on) onInert() else if (focusBack && focusBack.isConnected && (!document.activeElement || document.activeElement === document.body)) focusBack.focus() } }