╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ script.js ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
215 wasmInstance.exports._onKeyDown(event.keyCode); 216 wasmInstance.exports._tick(minRows(), maxCols()); 217 }); 218 219 // listeners on document (not #grid) since the form lives outside #grid; 220 // input/focus events from form elements still bubble up to document. 221 document.addEventListener("input", (event) => { 222 const t = event.target; 223 if (!t || t.tagName !== "INPUT" || !t.dataset.focusId) return; 224 sendTextInputValue(Number(t.dataset.focusId), t.value); 225 }); 226 227 document.addEventListener("focusin", (event) => { 228 const t = event.target; 229 if (!t || !t.dataset || !t.dataset.focusId) return; 230 // sync the wasm focus to wherever the browser moved focus 231 wasmInstance.exports._setFocus(Number(t.dataset.focusId)); 232 // a click's mousedown fires this focusin before the click event. ticking 233 // here would rebuild #grid and destroy the node before its click lands, 234 // swallowing the navigation and forcing a second click — so don't 235 // re-render for a grid element. overlay controls live outside #grid and 236 // survive the diff, so they still tick. 237 if (!grid.contains(t)) wasmInstance.exports._tick(minRows(), maxCols()); 238 }); 239 240 grid.addEventListener("click", (event) => { 241 const span = event.target.closest(".clickable"); 242 if (!span) return; 243 // leave modified / non-left clicks (open-in-new-tab, etc.) to the browser 244 if (event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return; 245 // wasm routes the click: an in-page link just moves focus and re-renders, 246 // a cross-page one calls _navigate. suppress the <a>'s own navigation so 247 // an in-page link doesn't also trigger a redundant full page load. 248 event.preventDefault(); 249 const focusId = Number(span.dataset.focusId); 250 wasmInstance.exports._onMouseClick(focusId); 251 wasmInstance.exports._tick(minRows(), maxCols()); 252 }); 253 254 let resizeTimer = null; 255 window.addEventListener("resize", () => { 256 clearTimeout(resizeTimer); 257 resizeTimer = setTimeout(() => { 258 wasmInstance.exports._tick(minRows(), maxCols()); 259 }, 100); 260 }); 261 }); 262