Drive keys (canvas GridKeys): a screen key's "key" in the profile clicks it (F1 F2 F3 / F5 − + 3 F T N; "keypad" K1–K8 / E3 kept for the keypad), the menus' own buttons too (1 2 3 the scopes / presets, H hide all / all off); in an open menu ↑ ↓ move the row (the keypad's encoder will send the same arrows), Enter its first button, Space its eye, + adds it, ⌫ up a folder, Esc closes. The key in each button's corner and the row in purple with ⏎ ␣ +, from the first key pressed on (a touch-only screen stays clean)
CI / check (push) Successful in 23s
CI / deploy (push) Successful in 18s

This commit is contained in:
randy committed 2026-12-03 12:27:45 +01:00
1 parent d39e3b5edd
commit 1ee79fff66
6 files changed
+128 -18

No files matched your search

+13 -6
View File
@@ -30,6 +30,13 @@ export function cellButton(cls, html, title, action) {
return el;
}
// A hardware key for a button: pressed, it clicks it; its label in the corner (driving.js, the keys)
export function bindKey(el, key) {
el.dataset.key = key;
el.dataset.label = key === "-" ? "−" : key.length === 1 ? key.toUpperCase() : key;
return el;
}
export const emptyRow = (text) => Object.assign(document.createElement("p"), { className: "drive-panel__empty", textContent: text });
function panel(cls, label, inner) {
@@ -56,7 +63,7 @@ export function pointsMenu(ctx) {
<div class="drive-points__bar"></div>
<div class="drive-panel__list drive-points__list"></div>
<div class="drive-panel__foot"></div>
<button type="button" class="drive-panel__wide" data-action="hide-all">Hide all</button>`);
<button type="button" class="drive-panel__wide" data-action="hide-all" data-key="h" data-label="H">Hide all</button>`);
const input = el.querySelector("input");
const bar = el.querySelector(".drive-points__bar");
const list = el.querySelector(".drive-points__list");
@@ -189,8 +196,8 @@ export function pointsMenu(ctx) {
el.querySelector(".drive-panel__note").textContent = "folders";
renderFolder();
} else {
bar.replaceChildren(...[["near", "Near the car"], ["ahead", "Ahead"], ["shown", "Shown"]].map(([id, label]) => {
const chip = cellButton("scope", label, label, () => { scope = id; render(); });
bar.replaceChildren(...[["near", "Near the car"], ["ahead", "Ahead"], ["shown", "Shown"]].map(([id, label], i) => {
const chip = bindKey(cellButton("scope", label, label, () => { scope = id; render(); }), String(i + 1));
chip.setAttribute("aria-pressed", String(scope === id));
return chip;
}), cellButton("mode", `<span class="drive-key__icon">▣</span><span class="drive-key__label">Folders</span>`, "Folders", () => { scope = "folder"; input.value = ""; render(); }));
@@ -223,7 +230,7 @@ export function layersMenu(ctx) {
<div class="drive-layers__source"></div>
<div class="drive-panel__list drive-layers__list"></div>
<div class="drive-panel__foot"></div>
<button type="button" class="drive-panel__wide" data-action="all-off">All off</button>`);
<button type="button" class="drive-panel__wide" data-action="all-off" data-key="h" data-label="H">All off</button>`);
const list = el.querySelector(".drive-layers__list");
let order = [];
let keeping = false;
@@ -251,7 +258,7 @@ export function layersMenu(ctx) {
if (el.hidden) return;
const presets = loadPresets();
const current = presetOn(presets);
el.querySelector(".drive-layers__presets").replaceChildren(...PRESETS.map(([id, icon, label]) => {
el.querySelector(".drive-layers__presets").replaceChildren(...PRESETS.map(([id, icon, label], i) => {
const b = cellButton("preset", `<span class="drive-key__icon">${icon}</span><span class="drive-key__label">${keeping ? `Save as ${label}` : label}</span>`, label, () => {
if (keeping) {
presets[id] = layers().filter((l) => l.toggle.checked).map((l) => l.name);
@@ -263,7 +270,7 @@ export function layersMenu(ctx) {
render();
});
b.setAttribute("aria-pressed", String(!keeping && current === id));
return b;
return bindKey(b, String(i + 1));
}), (() => {
const keep = cellButton("mode", `<span class="drive-key__icon">${keeping ? "✕" : "+"}</span><span class="drive-key__label">${keeping ? "Cancel" : "Keep"}</span>`,
keeping ? "Cancel" : "Keep what is on as a preset", () => { keeping = !keeping; render(); });
+62 -1
View File
@@ -5,7 +5,7 @@ import { formatDuration } from "/js/route.js";
import { isLoggedIn } from "/js/auth.js";
import { watchDashboard, maneuverSvg, distance } from "/js/dashboard.js";
import { formatSunInfo } from "/js/sun.js";
import { pointsMenu, layersMenu, terrainMenu, elevationHtml, cellButton, emptyRow as empty, escapeHtml } from "/js/drive_menus.js";
import { pointsMenu, layersMenu, terrainMenu, elevationHtml, cellButton, bindKey, emptyRow as empty, escapeHtml } from "/js/drive_menus.js";
// Driving mode: the grid of docs/design.adoc ("Layout: a grid, not floating
// panels"; the Design canvas' Grid) — the page becomes cells, the map one
@@ -250,6 +250,7 @@ export function setupDriving(map, nightButton, routePanel, gpxPanel) {
}
if (panel !== tripPanel && results) backToStops(); // the pins go with the search
openPanel = panel;
row = 0;
tripPanel.hidden = panel !== tripPanel;
menuPanel.hidden = panel !== menuPanel;
for (const menu of menus) {
@@ -374,6 +375,7 @@ export function setupDriving(map, nightButton, routePanel, gpxPanel) {
el.disabled = NOT_YET.has(cell.action) || !keyAction[cell.action];
el.addEventListener("click", () => keyAction[cell.action]?.());
if (cell.action === "zoomIn" || cell.action === "zoomOut") el.classList.add("drive-key--big");
if (cell.key) bindKey(el, cell.key); // "keypad" too, for when the keypad is on the bus
} else {
el = document.createElement("div");
}
@@ -546,6 +548,65 @@ export function setupDriving(map, nightButton, routePanel, gpxPanel) {
map.resize(); // the grid came or went
}
toggle.addEventListener("click", () => set(!document.documentElement.classList.contains("driving")));
// Keys (canvas GridKeys): a screen key's "key" in the profile clicks it, a
// menu's [data-key] buttons too (1 2 3, H); in an open menu ↑ ↓ move the row
// (the keypad's encoder will send the same arrows), Enter its first button,
// Space its eye, + adds it, ⌫ up a folder, Esc closes. The labels in the
// corners show from the first key pressed on, so a touch-only screen stays clean.
// ponytail: keyboard only; the keypad's keys and its heartbeat switching the
// labels to "keypad" wait for the keypad on the bus (and the diagnostics' mapping)
const KEYS_SEEN = "maptool.driveKeys";
let row = 0;
try { if (localStorage.getItem(KEYS_SEEN)) document.documentElement.classList.add("drive-keys"); } catch { /* nothing kept */ }
const norm = (k) => (k.length === 1 ? k.toLowerCase() : k);
const visible = (b) => b.offsetParent && !b.disabled;
const rowsOf = (panel) => {
const rows = new Map();
for (const b of panel.querySelectorAll("button:not(.drive-panel__close)")) {
if (!visible(b)) continue;
const top = Math.round(b.getBoundingClientRect().top);
rows.set(top, [...(rows.get(top) || []), b]);
}
return [...rows].sort((a, b) => a[0] - b[0]).map(([, r]) => r);
};
const markRow = (scroll) => {
for (const b of document.querySelectorAll(".drive-focus")) b.classList.remove("drive-focus", "drive-focus--main");
if (!openPanel || !document.documentElement.classList.contains("drive-keys")) return [];
const rows = rowsOf(openPanel);
row = Math.max(0, Math.min(row, rows.length - 1));
const current = rows[row] || [];
for (const b of current) b.classList.add("drive-focus");
current[0]?.classList.add("drive-focus--main");
if (scroll) current[0]?.scrollIntoView({ block: "nearest" });
return current;
};
let marking = 0; // the menus re-render their rows: the highlight follows, once a frame
new MutationObserver(() => { marking ||= requestAnimationFrame(() => { marking = 0; markRow(false); }); }).observe(app, { childList: true, subtree: true });
document.addEventListener("keydown", (e) => {
if (!document.documentElement.classList.contains("driving") || e.ctrlKey || e.altKey || e.metaKey) return;
const key = norm(e.key);
const move = key === "ArrowUp" ? -1 : key === "ArrowDown" ? 1 : 0;
if (e.target.matches?.("input, textarea, select")) {
if (key === "Escape" || move) e.target.blur(); else return; // typing a search
}
if (!document.documentElement.classList.contains("drive-keys")) {
document.documentElement.classList.add("drive-keys");
try { localStorage.setItem(KEYS_SEEN, "1"); } catch { /* private window: not kept */ }
}
const current = markRow(false);
const press = (b) => (b && visible(b) ? (b.click(), true) : false);
const bound = (scope) => [...(scope?.querySelectorAll("[data-key]") || [])].find((b) => norm(b.dataset.key) === key && visible(b));
let done = false;
if (key === "Escape") done = !!openPanel && (open(null), true);
else if (openPanel && move) { row += move; markRow(true); done = true; }
else if (openPanel && key === "Enter") done = press(current[0]);
else if (openPanel && key === " ") done = press(current.find((b) => b.classList.contains("drive-panel__eye")));
else if (openPanel && key === "Backspace") done = press(openPanel.querySelector(".drive-panel__up"));
if (!done && openPanel && key === "+") done = press(current.find((b) => b.classList.contains("drive-panel__add")));
if (!done) done = press(bound(openPanel) || bound(app));
if (done) e.preventDefault(); // F1, F5, / are the browser's otherwise
});
let saved = null;
try { saved = localStorage.getItem(KEY); } catch { /* nothing kept */ }
set(saved === "on");