╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ script.js ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
194 if (["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight", "PageUp", "PageDown", "Home", "End"].includes(event.key)) { 195 event.preventDefault(); 196 } 197 wasmInstance.exports._onKeyDown(event.keyCode); 198 wasmInstance.exports._tick(minRows(), maxCols()); 199 }); 200 201 // listeners on document (not #grid) since the form lives outside #grid; 202 // input/focus events from form elements still bubble up to document. 203 document.addEventListener("input", (event) => { 204 const t = event.target; 205 if (!t || t.tagName !== "INPUT" || !t.dataset.focusId) return; 206 sendTextInputValue(Number(t.dataset.focusId), t.value); 207 }); 208 209 document.addEventListener("focusin", (event) => { 210 const t = event.target; 211 if (!t || !t.dataset || !t.dataset.focusId) return; 212 // sync the wasm focus to wherever the browser moved focus 213 wasmInstance.exports._setFocus(Number(t.dataset.focusId)); 214 // a click's mousedown fires this focusin before the click event. ticking 215 // here would rebuild #grid and destroy the node before its click lands, 216 // swallowing the navigation and forcing a second click — so don't 217 // re-render for a grid element. overlay controls live outside #grid and 218 // survive the diff, so they still tick. 219 if (!grid.contains(t)) wasmInstance.exports._tick(minRows(), maxCols()); 220 }); 221 222 grid.addEventListener("click", (event) => { 223 const span = event.target.closest(".clickable"); 224 if (!span) return; 225 // leave modified / non-left clicks (open-in-new-tab, etc.) to the browser 226 if (event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return; 227 // wasm routes the click: an in-page link just moves focus and re-renders, 228 // a cross-page one calls _navigate. suppress the <a>'s own navigation so 229 // an in-page link doesn't also trigger a redundant full page load. 230 event.preventDefault(); 231 const focusId = Number(span.dataset.focusId); 232 wasmInstance.exports._onMouseClick(focusId); 233 wasmInstance.exports._tick(minRows(), maxCols()); 234 }); 235 236 let resizeTimer = null; 237 window.addEventListener("resize", () => { 238 clearTimeout(resizeTimer); 239 resizeTimer = setTimeout(() => { 240 wasmInstance.exports._tick(minRows(), maxCols()); 241 }, 100); 242 }); 243 }); 244