╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ script.js ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
268 document.activeElement.blur(); 269 } else if (tag === "INPUT" || tag === "BUTTON" || tag === "TEXTAREA") { 270 // Enter (submit / newline), typing, Tab, and a textarea's 271 // arrows — handled natively by the browser 272 return; 273 } 274 } 275 if ((event.key === "ArrowUp" || event.key === "ArrowDown") && scrollFocusedWidget(event.key === "ArrowDown")) { 276 event.preventDefault(); 277 return; 278 } 279 if ((event.key === "PageUp" || event.key === "PageDown") && pageFocusedScroll(event.key === "PageDown")) { 280 event.preventDefault(); 281 return; 282 } 283 if (["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight", "PageUp", "PageDown", "Home", "End"].includes(event.key)) { 284 event.preventDefault(); 285 } 286 wasmInstance.exports._onKeyDown(event.keyCode); 287 wasmInstance.exports._tick(minRows(), maxCols()); 288 }); 289 290 // submit on mousedown rather than waiting for click: the focusin this 291 // same mousedown fires ticks the wasm, and a resulting overlay rebuild 292 // would detach the button before its click could land. the form is 293 // guaranteed live at mousedown time. 294 document.addEventListener("mousedown", (event) => { 295 if (event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return; 296 const btn = event.target.closest ? event.target.closest("button[type=submit][data-focus-id]") : null; 297 if (!btn || !btn.form) return; 298 // empty-action forms are handled by their onsubmit on the click path 299 if (!btn.form.getAttribute("action")) return; 300 // if the button survives to receive the click, don't submit twice 301 btn.addEventListener("click", (e) => e.preventDefault(), { once: true }); 302 btn.form.requestSubmit(btn); 303 }); 304 305 // listeners on document (not #grid) since the form lives outside #grid; 306 // input/focus events from form elements still bubble up to document. 307 document.addEventListener("input", (event) => { 308 const t = event.target; 309 if (!t || (t.tagName !== "INPUT" && t.tagName !== "TEXTAREA") || !t.dataset.focusId) return; 310 sendTextInputValue(Number(t.dataset.focusId), t.value); 311 }); 312 313 document.addEventListener("click", (event) => { 314 const t = event.target; 315 if (t && t.tagName === "INPUT" && t.readOnly) t.select(); 316 }); 317 318 document.addEventListener("focusin", (event) => { 319 const t = event.target; 320 if (!t || !t.dataset || !t.dataset.focusId) return; 321 // sync the wasm focus to wherever the browser moved focus 322 wasmInstance.exports._setFocus(Number(t.dataset.focusId)); 323 // a click's mousedown fires this focusin before the click event. ticking 324 // here would rebuild #grid and destroy the node before its click lands, 325 // swallowing the navigation and forcing a second click — so don't 326 // re-render for a grid element. overlay controls live outside #grid and 327 // survive the diff, so they still tick. 328 if (!grid.contains(t)) wasmInstance.exports._tick(minRows(), maxCols()); 329 }); 330 331 grid.addEventListener("click", (event) => { 332 const span = event.target.closest(".clickable"); 333 if (!span) return; 334 // leave modified / non-left clicks (open-in-new-tab, etc.) to the browser 335 if (event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return; 336 // wasm routes the click: an in-page link just moves focus and re-renders, 337 // a cross-page one calls _navigate. suppress the <a>'s own navigation so 338 // an in-page link doesn't also trigger a redundant full page load. 339 event.preventDefault(); 340 const focusId = Number(span.dataset.focusId); 341 wasmInstance.exports._onMouseClick(focusId); 342 wasmInstance.exports._tick(minRows(), maxCols()); 343 }); 344 345 let resizeTimer = null; 346 window.addEventListener("resize", () => { 347 clearTimeout(resizeTimer); 348 resizeTimer = setTimeout(() => { 349 wasmInstance.exports._tick(minRows(), maxCols()); 350 }, 100); 351 }); 352 }); 353