╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ script.js ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
395 396 // delegated listeners survive cell-layer replacement. the controls 397 // themselves are retained inside #grid. 398 document.addEventListener("input", (event) => { 399 const t = event.target; 400 if (!t || (t.tagName !== "INPUT" && t.tagName !== "TEXTAREA") || !t.dataset.focusId) return; 401 sendTextInputValue(Number(t.dataset.focusId), t.value); 402 }); 403 404 document.addEventListener("focusin", (event) => { 405 const t = event.target; 406 if (!t || !t.dataset || !t.dataset.focusId) return; 407 // sync the wasm focus to wherever the browser moved focus 408 wasmInstance.exports._setFocus(Number(t.dataset.focusId)); 409 // keyed controls survive a redraw before click. cell links live in the 410 // replaceable backdrop, so their click handler redraws after activation. 411 if (nodeKey(t)?.startsWith("control:")) wasmInstance.exports._tick(minRows(), maxCols()); 412 }); 413 414 grid.addEventListener("click", (event) => { 415 if (event.target.matches("input[readonly]")) { 416 wasmInstance.exports._tick(minRows(), maxCols()); 417 return; 418 } 419 const span = event.target.closest(".clickable"); 420 if (!span) return; 421 // leave modified / non-left clicks (open-in-new-tab, etc.) to the browser 422 if (event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return; 423 // wasm routes the click: an in-page link updates focus and re-renders, 424 // a cross-page one calls _navigate. suppress the <a>'s own navigation so 425 // an in-page link doesn't also trigger a redundant full page load. 426 event.preventDefault(); 427 const focusId = Number(span.dataset.focusId); 428 wasmInstance.exports._onMouseClick(focusId); 429 wasmInstance.exports._tick(minRows(), maxCols()); 430 }); 431 432 let resizeTimer = null; 433 window.addEventListener("resize", () => { 434 clearTimeout(resizeTimer); 435 resizeTimer = setTimeout(() => { 436 wasmInstance.exports._tick(minRows(), maxCols()); 437 }, 100); 438 }); 439 }); 440