╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ script.js ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
412 event.preventDefault(); 413 return; 414 } 415 if (["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight", "PageUp", "PageDown", "Home", "End"].includes(event.key)) { 416 event.preventDefault(); 417 } 418 wasmInstance.exports._onKeyDown(event.keyCode); 419 wasmInstance.exports._tick(minRows(), maxCols()); 420 }); 421 422 // delegated listeners survive cell-layer replacement. the controls 423 // themselves are retained inside #grid. 424 document.addEventListener("input", (event) => { 425 const t = event.target; 426 if (!t || (t.tagName !== "INPUT" && t.tagName !== "TEXTAREA") || !t.dataset.focusId) return; 427 sendTextInputValue(Number(t.dataset.focusId), t.value); 428 }); 429 430 document.addEventListener("focusin", (event) => { 431 const t = event.target; 432 if (!t || !t.dataset || !t.dataset.focusId) return; 433 // sync the wasm focus to wherever the browser moved focus 434 wasmInstance.exports._setFocus(Number(t.dataset.focusId)); 435 // keyed controls survive a redraw before click. cell links live in the 436 // replaceable backdrop, so their click handler redraws after activation. 437 if (nodeKey(t)?.startsWith("control:")) wasmInstance.exports._tick(minRows(), maxCols()); 438 }); 439 440 grid.addEventListener("click", (event) => { 441 if (event.target.matches("input[readonly]")) { 442 wasmInstance.exports._tick(minRows(), maxCols()); 443 return; 444 } 445 // a link inside a cell's text opens in a new tab on its own 446 if (event.target.closest("a.cell-link")) return; 447 const span = event.target.closest(".clickable"); 448 if (!span) return; 449 // leave modified / non-left clicks (open-in-new-tab, etc.) to the browser 450 if (event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return; 451 // wasm routes the click: an in-page link updates focus and re-renders, 452 // a cross-page one calls _navigate. suppress the <a>'s own navigation so 453 // an in-page link doesn't also trigger a redundant full page load. 454 event.preventDefault(); 455 const focusId = Number(span.dataset.focusId); 456 wasmInstance.exports._onMouseClick(focusId); 457 wasmInstance.exports._tick(minRows(), maxCols()); 458 }); 459 460 let resizeTimer = null; 461 window.addEventListener("resize", () => { 462 clearTimeout(resizeTimer); 463 resizeTimer = setTimeout(() => { 464 wasmInstance.exports._tick(minRows(), maxCols()); 465 }, 100); 466 }); 467 }); 468