╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ script.js ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
384 return; 385 } else if (tag === "INPUT" && !document.activeElement.form && !document.activeElement.readOnly && 386 (event.key === "Tab" && !event.shiftKey || 387 event.key === "ArrowRight" && caretAtEnd(document.activeElement))) { 388 // an input outside a form (a search box) reaches the widgets 389 // beside it: Tab, and ArrowRight once the caret is at the end. 390 // blurred first, so the next key isn't the input's; the tick 391 // refocuses it if the TUI focus stayed. 392 event.preventDefault(); 393 document.activeElement.blur(); 394 wasmInstance.exports._onKeyDown(event.keyCode); 395 wasmInstance.exports._tick(minRows(), maxCols()); 396 return; 397 } else if (tag === "INPUT" && (event.key === "ArrowUp" || event.key === "ArrowDown")) { 398 // up/down moves between widgets; left/right stay in the input 399 document.activeElement.blur(); 400 } else if (tag === "BUTTON" && isArrow) { 401 // arrows navigate away from a focused submit button 402 document.activeElement.blur(); 403 } else if (tag === "INPUT" || tag === "BUTTON" || tag === "TEXTAREA") { 404 // Enter (submit / newline), typing, Tab, and a textarea's 405 // arrows — handled natively by the browser 406 return; 407 } 408 } 409 if ((event.key === "ArrowUp" || event.key === "ArrowDown") && scrollFocusedWidget(event.key === "ArrowDown")) { 410 event.preventDefault(); 411 return; 412 } 413 if ((event.key === "PageUp" || event.key === "PageDown") && pageFocusedScroll(event.key === "PageDown")) { 414 event.preventDefault(); 415 return; 416 } 417 if (["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight", "PageUp", "PageDown", "Home", "End"].includes(event.key)) { 418 event.preventDefault(); 419 } 420 wasmInstance.exports._onKeyDown(event.keyCode); 421 wasmInstance.exports._tick(minRows(), maxCols()); 422 }); 423 424 // delegated listeners survive cell-layer replacement. the controls 425 // themselves are retained inside #grid. 426 document.addEventListener("input", (event) => { 427 const t = event.target; 428 if (!t || (t.tagName !== "INPUT" && t.tagName !== "TEXTAREA") || !t.dataset.focusId) return; 429 sendTextInputValue(Number(t.dataset.focusId), t.value); 430 }); 431 432 document.addEventListener("focusin", (event) => { 433 const t = event.target; 434 if (!t || !t.dataset || !t.dataset.focusId) return; 435 // sync the wasm focus to wherever the browser moved focus 436 wasmInstance.exports._setFocus(Number(t.dataset.focusId)); 437 // keyed controls survive a redraw before click. cell links live in the 438 // replaceable backdrop, so their click handler redraws after activation. 439 if (nodeKey(t)?.startsWith("control:")) wasmInstance.exports._tick(minRows(), maxCols()); 440 }); 441 442 grid.addEventListener("click", (event) => { 443 if (event.target.matches("input[readonly]")) { 444 wasmInstance.exports._tick(minRows(), maxCols()); 445 return; 446 } 447 // a link inside a cell's text opens in a new tab on its own 448 if (event.target.closest("a.cell-link")) return; 449 const span = event.target.closest(".clickable"); 450 if (!span) return; 451 // leave modified / non-left clicks (open-in-new-tab, etc.) to the browser 452 if (event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return; 453 // wasm routes the click: an in-page link updates focus and re-renders, 454 // a cross-page one calls _navigate. suppress the <a>'s own navigation so 455 // an in-page link doesn't also trigger a redundant full page load. 456 event.preventDefault(); 457 const focusId = Number(span.dataset.focusId); 458 wasmInstance.exports._onMouseClick(focusId); 459 wasmInstance.exports._tick(minRows(), maxCols()); 460 }); 461 462 let resizeTimer = null; 463 window.addEventListener("resize", () => { 464 clearTimeout(resizeTimer); 465 resizeTimer = setTimeout(() => { 466 wasmInstance.exports._tick(minRows(), maxCols()); 467 }, 100); 468 }); 469 }); 470