╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ script.js ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
222 wasmInstance.exports._onKeyDown(event.keyCode); 223 wasmInstance.exports._tick(minRows(), maxCols()); 224 }); 225 226 // submit on mousedown rather than waiting for click: the focusin this 227 // same mousedown fires ticks the wasm, and a resulting overlay rebuild 228 // would detach the button before its click could land. the form is 229 // guaranteed live at mousedown time. 230 document.addEventListener("mousedown", (event) => { 231 if (event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return; 232 const btn = event.target.closest ? event.target.closest("button[type=submit][data-focus-id]") : null; 233 if (!btn || !btn.form) return; 234 // empty-action forms are handled by their onsubmit on the click path 235 if (!btn.form.getAttribute("action")) return; 236 // if the button survives to receive the click, don't submit twice 237 btn.addEventListener("click", (e) => e.preventDefault(), { once: true }); 238 btn.form.requestSubmit(btn); 239 }); 240 241 // listeners on document (not #grid) since the form lives outside #grid; 242 // input/focus events from form elements still bubble up to document. 243 document.addEventListener("input", (event) => { 244 const t = event.target; 245 if (!t || (t.tagName !== "INPUT" && t.tagName !== "TEXTAREA") || !t.dataset.focusId) return; 246 sendTextInputValue(Number(t.dataset.focusId), t.value); 247 }); 248 249 document.addEventListener("focusin", (event) => { 250 const t = event.target; 251 if (!t || !t.dataset || !t.dataset.focusId) return; 252 // sync the wasm focus to wherever the browser moved focus 253 wasmInstance.exports._setFocus(Number(t.dataset.focusId)); 254 // a click's mousedown fires this focusin before the click event. ticking 255 // here would rebuild #grid and destroy the node before its click lands, 256 // swallowing the navigation and forcing a second click — so don't 257 // re-render for a grid element. overlay controls live outside #grid and 258 // survive the diff, so they still tick. 259 if (!grid.contains(t)) wasmInstance.exports._tick(minRows(), maxCols()); 260 }); 261 262 grid.addEventListener("click", (event) => { 263 const span = event.target.closest(".clickable"); 264 if (!span) return; 265 // leave modified / non-left clicks (open-in-new-tab, etc.) to the browser 266 if (event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return; 267 // wasm routes the click: an in-page link just moves focus and re-renders, 268 // a cross-page one calls _navigate. suppress the <a>'s own navigation so 269 // an in-page link doesn't also trigger a redundant full page load. 270 event.preventDefault(); 271 const focusId = Number(span.dataset.focusId); 272 wasmInstance.exports._onMouseClick(focusId); 273 wasmInstance.exports._tick(minRows(), maxCols()); 274 }); 275 276 let resizeTimer = null; 277 window.addEventListener("resize", () => { 278 clearTimeout(resizeTimer); 279 resizeTimer = setTimeout(() => { 280 wasmInstance.exports._tick(minRows(), maxCols()); 281 }, 100); 282 }); 283 }); 284