╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ script.js ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
189 // Enter (submit), typing, Tab — handled natively by the browser 190 return; 191 } 192 } 193 if (["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight", "PageUp", "PageDown", "Home", "End"].includes(event.key)) { 194 event.preventDefault(); 195 } 196 wasmInstance.exports._onKeyDown(event.keyCode); 197 wasmInstance.exports._tick(minRows(), maxCols()); 198 }); 199 200 // listeners on document (not #grid) since the form lives outside #grid; 201 // input/focus events from form elements still bubble up to document. 202 document.addEventListener("input", (event) => { 203 const t = event.target; 204 if (!t || t.tagName !== "INPUT" || !t.dataset.focusId) return; 205 sendTextInputValue(Number(t.dataset.focusId), t.value); 206 }); 207 208 document.addEventListener("focusin", (event) => { 209 const t = event.target; 210 if (!t || !t.dataset || !t.dataset.focusId) return; 211 // sync the wasm focus to wherever the browser moved focus 212 wasmInstance.exports._setFocus(Number(t.dataset.focusId)); 213 // a click's mousedown fires this focusin before the click event. ticking 214 // here would rebuild #grid and destroy the node before its click lands, 215 // swallowing the navigation and forcing a second click — so don't 216 // re-render for a grid element. overlay controls live outside #grid and 217 // survive the diff, so they still tick. 218 if (!grid.contains(t)) wasmInstance.exports._tick(minRows(), maxCols()); 219 }); 220 221 grid.addEventListener("click", (event) => { 222 const span = event.target.closest(".clickable"); 223 if (!span) return; 224 // leave modified / non-left clicks (open-in-new-tab, etc.) to the browser 225 if (event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return; 226 // wasm routes the click: an in-page link just moves focus and re-renders, 227 // a cross-page one calls _navigate. suppress the <a>'s own navigation so 228 // an in-page link doesn't also trigger a redundant full page load. 229 event.preventDefault(); 230 const focusId = Number(span.dataset.focusId); 231 wasmInstance.exports._onMouseClick(focusId); 232 wasmInstance.exports._tick(minRows(), maxCols()); 233 }); 234 235 let resizeTimer = null; 236 window.addEventListener("resize", () => { 237 clearTimeout(resizeTimer); 238 resizeTimer = setTimeout(() => { 239 wasmInstance.exports._tick(minRows(), maxCols()); 240 }, 100); 241 }); 242 }); 243