diff --git a/design/assets/base.html b/design/assets/base.html
index 7971e5d..fcc4166 100644
--- a/design/assets/base.html
+++ b/design/assets/base.html
@@ -68,8 +68,14 @@
.switcher[data-pager] .switcher-tabs { display: none; }
.pager { position: relative; flex: 0 1 auto; min-width: 0; display: flex; gap: 4px; }
.switcher.switcher .pager-now { min-width: 0; max-width: 340px; justify-content: flex-start; }
- .pager-name { overflow: hidden; text-overflow: ellipsis; }
+ /* the name and the place keep one width, the longest of all they can say (each cell's hidden .pager-fit, laid over
+ it), so ‹ and › stay put while you step; a name over 24ch ends in … and the name's title holds it whole */
+ .pager-cell { display: grid; grid-template-columns: minmax(0, 1fr); min-width: 0; }
+ .pager-cell > * { grid-area: 1 / 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; text-align: center; }
+ .pager-cell:first-child { max-width: 24ch; }
+ .pager-fit { visibility: hidden; height: 0; white-space: pre; }
.pager-of, .pager-caret { flex: none; color: var(--bar-muted); font-weight: 500; } .pager-of:empty { display: none; }
+ .pager-of, .pager-of + .pager-fit { font-variant-numeric: tabular-nums; }
.switcher.switcher :is(.pager-prev, .pager-next) { width: 28px; padding: 0; font-size: 17px; }
.pager-menu { position: absolute; z-index: 2; top: calc(100% + 6px); left: 0; display: grid; width: min(300px, calc(100vw - 24px));
max-height: min(60vh, 480px); overflow: auto; padding: 4px; background: var(--bar-bg); color: var(--bar-ink);
@@ -651,9 +657,12 @@
if (!p) { p = el('div', 'pager'); tabs.before(p); }
const key = (cls, text, name) => { const b = el('button', cls, text); b.type = 'button'; if (name) b.setAttribute('aria-label', name); return b; };
const prev = key('pager-prev', '\u2039', 'Previous frame'), next = key('pager-next', '\u203a', 'Next frame'), now = key('pager-now');
+ prev.title = 'Previous frame (\u2190, h or k)'; next.title = 'Next frame (\u2192, l or j)';
+ prev.setAttribute('aria-keyshortcuts', 'h k'); next.setAttribute('aria-keyshortcuts', 'l j');
now.setAttribute('aria-haspopup', 'menu'); now.setAttribute('aria-expanded', 'false');
const caret = el('span', 'pager-caret', '\u25be'); caret.setAttribute('aria-hidden', 'true');
- now.append(el('span', 'pager-name'), el('span', 'pager-of'), caret);
+ const n = all().length, cell = (cls, fit) => { const c = el('span', 'pager-cell'), f = el('span', 'pager-fit', fit.join('\n')); f.setAttribute('aria-hidden', 'true'); c.append(el('span', cls), f); return c; };
+ now.append(cell('pager-name', ['All ' + n + ' frames', ...all().map(label)]), cell('pager-of', [n + ' of ' + n]), caret);
const menu = el('div', 'pager-menu menu'); menu.setAttribute('role', 'menu'); menu.setAttribute('aria-label', 'Frames'); menu.hidden = true;
if ('popover' in menu) menu.popover = 'manual'; // opened in the top layer: a frame's own fixed bar or nav can't draw over it
if (all().length > 8) { const f = el('input', 'pager-filter'); f.type = 'search'; f.placeholder = 'Filter frames'; f.setAttribute('aria-label', 'Filter frames'); menu.append(f); }
@@ -676,6 +685,7 @@
const name = all_ ? 'All ' + dirs.length + ' frames' : label(cur), of = all_ ? '' : (dirs.indexOf(cur) + 1) + ' of ' + dirs.length;
const set = (x, t) => { if (x.textContent !== t) x.textContent = t; }; // unchanged: no mutation to answer
set(p.querySelector('.pager-name'), name); set(p.querySelector('.pager-of'), of);
+ const now = p.querySelector('.pager-now'); if (now.title !== name) now.title = name; // whole, where the name ends in …
p.querySelectorAll('.pager-item').forEach((b) => { const on = String(!all_ && b.dataset.for === (cur && cur.dataset.ssId)); if (b.getAttribute('aria-checked') !== on) b.setAttribute('aria-checked', on); });
}
function openMenu() {
@@ -741,7 +751,18 @@
else if ((e.key === 'Enter' || e.key === ' ') && i >= 0) { e.preventDefault(); shutMenu(true); t.click(); }
else if (e.key === 'Tab') shutMenu(false);
}
- window.ssPager = { click: pagerClick, key: pagerKey, filter: (e) => { if (e.target.matches && e.target.matches('.pager-filter')) filterMenu(e.target); }, place, rows };
+ // h or k steps to the frame before, l or j to the next, from anywhere on the page but a field, a menu or the
+ // Prototype bar, with no modifier held, and while no menu shows (one in a hidden frame doesn't count). Heard last (the
+ // document, bubbling), so a key a frame takes is left to it.
+ function hop(e) {
+ const p = pagerNow(), t = e.target, k = e.key;
+ if (!p || !/^[hjkl]$/.test(k) || e.defaultPrevented || e.metaKey || e.ctrlKey || e.altKey || e.shiftKey || e.isComposing
+ || document.body.getAttribute('data-ss-edit') === 'paper' || [...document.querySelectorAll('.menu:not([hidden])')].some((m) => m.getClientRects().length)) return; // a menu shown
+ if (t && (t.isContentEditable || (t.closest && t.closest('input,textarea,select,[contenteditable],[role=textbox],[role=menu],.menu,.tweaks,[data-ss-ui]')))) return;
+ e.preventDefault();
+ p.querySelector(k === 'h' || k === 'k' ? '.pager-prev' : '.pager-next').click();
+ }
+ window.ssPager = { click: pagerClick, key: pagerKey, filter: (e) => { if (e.target.matches && e.target.matches('.pager-filter')) filterMenu(e.target); }, place, rows, hop };
if (!window.ssPagerHeard) {
window.ssPagerHeard = true;
document.addEventListener('click', (e) => window.ssPager.click(e), true);
@@ -750,6 +771,7 @@
document.addEventListener('scroll', () => window.ssPager.place(), true); // the menu follows the pager
window.addEventListener('resize', () => window.ssPager.place());
}
+ if (!window.ssPagerHops) { window.ssPagerHops = true; document.addEventListener('keydown', (e) => window.ssPager.hop(e)); }
// The bar's line: the direction's data-line, or, while a direction (or one of its views) is open full page, the
// intro of its about block, so a phone, where the blocks hide, still says what it is for and how to try it.
const opened = () => {
diff --git a/design/assets/starter.html b/design/assets/starter.html
index f11ae20..afbec53 100644
--- a/design/assets/starter.html
+++ b/design/assets/starter.html
@@ -68,8 +68,14 @@
.switcher[data-pager] .switcher-tabs { display: none; }
.pager { position: relative; flex: 0 1 auto; min-width: 0; display: flex; gap: 4px; }
.switcher.switcher .pager-now { min-width: 0; max-width: 340px; justify-content: flex-start; }
- .pager-name { overflow: hidden; text-overflow: ellipsis; }
+ /* the name and the place keep one width, the longest of all they can say (each cell's hidden .pager-fit, laid over
+ it), so ‹ and › stay put while you step; a name over 24ch ends in … and the name's title holds it whole */
+ .pager-cell { display: grid; grid-template-columns: minmax(0, 1fr); min-width: 0; }
+ .pager-cell > * { grid-area: 1 / 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; text-align: center; }
+ .pager-cell:first-child { max-width: 24ch; }
+ .pager-fit { visibility: hidden; height: 0; white-space: pre; }
.pager-of, .pager-caret { flex: none; color: var(--bar-muted); font-weight: 500; } .pager-of:empty { display: none; }
+ .pager-of, .pager-of + .pager-fit { font-variant-numeric: tabular-nums; }
.switcher.switcher :is(.pager-prev, .pager-next) { width: 28px; padding: 0; font-size: 17px; }
.pager-menu { position: absolute; z-index: 2; top: calc(100% + 6px); left: 0; display: grid; width: min(300px, calc(100vw - 24px));
max-height: min(60vh, 480px); overflow: auto; padding: 4px; background: var(--bar-bg); color: var(--bar-ink);
@@ -624,9 +630,12 @@
if (!p) { p = el('div', 'pager'); tabs.before(p); }
const key = (cls, text, name) => { const b = el('button', cls, text); b.type = 'button'; if (name) b.setAttribute('aria-label', name); return b; };
const prev = key('pager-prev', '\u2039', 'Previous frame'), next = key('pager-next', '\u203a', 'Next frame'), now = key('pager-now');
+ prev.title = 'Previous frame (\u2190, h or k)'; next.title = 'Next frame (\u2192, l or j)';
+ prev.setAttribute('aria-keyshortcuts', 'h k'); next.setAttribute('aria-keyshortcuts', 'l j');
now.setAttribute('aria-haspopup', 'menu'); now.setAttribute('aria-expanded', 'false');
const caret = el('span', 'pager-caret', '\u25be'); caret.setAttribute('aria-hidden', 'true');
- now.append(el('span', 'pager-name'), el('span', 'pager-of'), caret);
+ const n = all().length, cell = (cls, fit) => { const c = el('span', 'pager-cell'), f = el('span', 'pager-fit', fit.join('\n')); f.setAttribute('aria-hidden', 'true'); c.append(el('span', cls), f); return c; };
+ now.append(cell('pager-name', ['All ' + n + ' frames', ...all().map(label)]), cell('pager-of', [n + ' of ' + n]), caret);
const menu = el('div', 'pager-menu menu'); menu.setAttribute('role', 'menu'); menu.setAttribute('aria-label', 'Frames'); menu.hidden = true;
if ('popover' in menu) menu.popover = 'manual'; // opened in the top layer: a frame's own fixed bar or nav can't draw over it
if (all().length > 8) { const f = el('input', 'pager-filter'); f.type = 'search'; f.placeholder = 'Filter frames'; f.setAttribute('aria-label', 'Filter frames'); menu.append(f); }
@@ -649,6 +658,7 @@
const name = all_ ? 'All ' + dirs.length + ' frames' : label(cur), of = all_ ? '' : (dirs.indexOf(cur) + 1) + ' of ' + dirs.length;
const set = (x, t) => { if (x.textContent !== t) x.textContent = t; }; // unchanged: no mutation to answer
set(p.querySelector('.pager-name'), name); set(p.querySelector('.pager-of'), of);
+ const now = p.querySelector('.pager-now'); if (now.title !== name) now.title = name; // whole, where the name ends in …
p.querySelectorAll('.pager-item').forEach((b) => { const on = String(!all_ && b.dataset.for === (cur && cur.dataset.ssId)); if (b.getAttribute('aria-checked') !== on) b.setAttribute('aria-checked', on); });
}
function openMenu() {
@@ -714,7 +724,18 @@
else if ((e.key === 'Enter' || e.key === ' ') && i >= 0) { e.preventDefault(); shutMenu(true); t.click(); }
else if (e.key === 'Tab') shutMenu(false);
}
- window.ssPager = { click: pagerClick, key: pagerKey, filter: (e) => { if (e.target.matches && e.target.matches('.pager-filter')) filterMenu(e.target); }, place, rows };
+ // h or k steps to the frame before, l or j to the next, from anywhere on the page but a field, a menu or the
+ // Prototype bar, with no modifier held, and while no menu shows (one in a hidden frame doesn't count). Heard last (the
+ // document, bubbling), so a key a frame takes is left to it.
+ function hop(e) {
+ const p = pagerNow(), t = e.target, k = e.key;
+ if (!p || !/^[hjkl]$/.test(k) || e.defaultPrevented || e.metaKey || e.ctrlKey || e.altKey || e.shiftKey || e.isComposing
+ || document.body.getAttribute('data-ss-edit') === 'paper' || [...document.querySelectorAll('.menu:not([hidden])')].some((m) => m.getClientRects().length)) return; // a menu shown
+ if (t && (t.isContentEditable || (t.closest && t.closest('input,textarea,select,[contenteditable],[role=textbox],[role=menu],.menu,.tweaks,[data-ss-ui]')))) return;
+ e.preventDefault();
+ p.querySelector(k === 'h' || k === 'k' ? '.pager-prev' : '.pager-next').click();
+ }
+ window.ssPager = { click: pagerClick, key: pagerKey, filter: (e) => { if (e.target.matches && e.target.matches('.pager-filter')) filterMenu(e.target); }, place, rows, hop };
if (!window.ssPagerHeard) {
window.ssPagerHeard = true;
document.addEventListener('click', (e) => window.ssPager.click(e), true);
@@ -723,6 +744,7 @@
document.addEventListener('scroll', () => window.ssPager.place(), true); // the menu follows the pager
window.addEventListener('resize', () => window.ssPager.place());
}
+ if (!window.ssPagerHops) { window.ssPagerHops = true; document.addEventListener('keydown', (e) => window.ssPager.hop(e)); }
// The bar's line: the direction's data-line, or, while a direction (or one of its views) is open full page, the
// intro of its about block, so a phone, where the blocks hide, still says what it is for and how to try it.
const opened = () => {
diff --git a/test/check.test.js b/test/check.test.js
index d641647..30ebbf7 100644
--- a/test/check.test.js
+++ b/test/check.test.js
@@ -248,7 +248,8 @@ function switcherListeners(already) {
test("the frame's listeners go in on a page an older starter set up, whose tab already has the number keys", () => {
const menu = ["document click", "document keydown"], exp = ["document click", "document keydown", "document ss:pdf-result", "window message"];
const pager = ["document click", "document input", "document keydown", "document scroll", "window resize"]; // the frame pager's menu, over 3 frames
- const put = (l) => [...l, ...menu, ...exp, ...pager].sort();
+ const hops = ["document keydown"]; // h j k l, through the pager
+ const put = (l) => [...l, ...menu, ...exp, ...pager, ...hops].sort();
const fresh = switcherListeners({});
assert.deepEqual(fresh, put(["document click", "document ss:canvas", "window hashchange", "window keydown", "window keydown"]));
// An older starter's tab: its number-key listener is in, so only the frame's are added on the push.
@@ -260,11 +261,13 @@ test("the frame's listeners go in on a page an older starter set up, whose tab a
// A tab from before the cards' menus: the menu's tap and keys go in on the push.
assert.deepEqual(switcherListeners({ ssViewKeys: true, ssFrameKeys: true, ssFrameHeard: true, ssPillTaps: true }), put(["window hashchange"]));
// A tab from before Export: its menu's tap and keys, and Spacesheep's answer to a PDF, go in on the push.
- assert.deepEqual(switcherListeners({ ssViewKeys: true, ssFrameKeys: true, ssFrameHeard: true, ssPillTaps: true, ssMenus: true }), [...exp, ...pager, "window hashchange"].sort());
+ assert.deepEqual(switcherListeners({ ssViewKeys: true, ssFrameKeys: true, ssFrameHeard: true, ssPillTaps: true, ssMenus: true }), [...exp, ...pager, ...hops, "window hashchange"].sort());
// A tab from before the pager: its menu's tap, keys and filter go in on the push.
- assert.deepEqual(switcherListeners({ ssViewKeys: true, ssFrameKeys: true, ssFrameHeard: true, ssPillTaps: true, ssMenus: true, ssExportHeard: true }), [...pager, "window hashchange"].sort());
+ assert.deepEqual(switcherListeners({ ssViewKeys: true, ssFrameKeys: true, ssFrameHeard: true, ssPillTaps: true, ssMenus: true, ssExportHeard: true }), [...pager, ...hops, "window hashchange"].sort());
+ // A tab from before h j k l: their listener goes in on the push.
+ assert.deepEqual(switcherListeners({ ssViewKeys: true, ssFrameKeys: true, ssFrameHeard: true, ssPillTaps: true, ssMenus: true, ssExportHeard: true, ssPagerHeard: true }), [...hops, "window hashchange"].sort());
// This starter's tab, pushed again: nothing twice.
- assert.deepEqual(switcherListeners({ ssViewKeys: true, ssFrameKeys: true, ssFrameHeard: true, ssPillTaps: true, ssMenus: true, ssExportHeard: true, ssPagerHeard: true }), ["window hashchange"]);
+ assert.deepEqual(switcherListeners({ ssViewKeys: true, ssFrameKeys: true, ssFrameHeard: true, ssPillTaps: true, ssMenus: true, ssExportHeard: true, ssPagerHeard: true, ssPagerHops: true }), ["window hashchange"]);
});
// The switcher's script on a stand-in page with three directions: what its bar's pill and tabs show.
@@ -374,6 +377,7 @@ function pagerPage(frames, older) {
querySelector(sel) { return this.all().find((e) => e.matches(sel)) || null; }
querySelectorAll(sel) { return this.all().filter((e) => e.matches(sel)); }
contains(x) { return x === this || this.all().includes(x); }
+ getClientRects() { for (let e = this; e; e = e.parentElement) if (e.hidden) return []; return [{}]; } // none under a hidden box, as display: none
closest(sel) { for (let e = this; e; e = e.parentElement) if (e.matches && e.matches(sel)) return e; return null; }
}
const dirs = frames.map(([slug, name, group]) => new El("section", { ssId: `direction-${slug}`, ssLabel: name, line: name, ...(group ? { ssGroup: group } : {}) }));
@@ -396,11 +400,11 @@ function pagerPage(frames, older) {
for (const src of older ? [older, BASE] : [BASE]) vm.runInContext(script(src), win); // a live update runs the newer script in the same tab
const canvas = (open) => { win.ss = { canvas: { zoom: open ? 1 : 0.2, open } }; (heard["ss:canvas"] || []).forEach((f) => f()); };
// The window's listeners first, as the capture phase reaches the window before the document.
- const fire = (n, target, key) => { let stop = false; const e = { target, key, detail: 1, preventDefault() {}, stopPropagation() { stop = true; } };
+ const fire = (n, target, key, mods = {}) => { let stop = false; const e = { target, key, detail: 1, ...mods, preventDefault() {}, stopPropagation() { stop = true; } };
for (const f of [...(winHeard[n] || []), ...(heard[n] || [])]) if (!stop) f(e); };
const pager = () => bar.querySelector(".pager");
return { bar, tabs, dirs, pager, canvas, fire, location, doc, win, backs: () => backs, mutate: () => watchers.forEach((f) => f([])),
- says: () => pager().querySelector(".pager-now").textContent.replace("▾", "").trim(),
+ says: () => pager().querySelector(".pager-name").textContent + pager().querySelector(".pager-of").textContent,
menu: () => pager().querySelector(".pager-menu").children.filter((x) => !x.hidden).map((x) => (x.matches(".pager-group") ? `# ${x.textContent}` : x.matches(".pager-filter") ? "filter" : x.textContent)) };
}
@@ -471,6 +475,40 @@ test("Esc on a control in the Prototype panel stays in the panel, with a frame o
assert.equal(page.backs(), 1, "the head's Esc goes Back");
});
+test("the pager's name and place keep one width, the longest they can say, so its arrows stay put; h k and l j step it, but not in a field or a menu, or with a modifier", () => {
+ const page = pagerPage(PAGER_FRAMES), now = page.pager().querySelector(".pager-now");
+ const cells = now.children.filter((x) => x.className === "pager-cell");
+ assert.deepEqual(cells.map((c) => c.children.map((x) => x.className)), [["pager-name", "pager-fit"], ["pager-of", "pager-fit"]], "each cell has a hidden twin under it");
+ assert.deepEqual(cells[0].children[1].textContent.split("\n"), ["All 13 frames", ...PAGER_FRAMES.map(([, name]) => name)], "which holds every name the pager can say");
+ assert.equal(cells[1].children[1].textContent, "13 of 13", "and the longest place");
+ assert.ok(cells.every((c) => c.children[1].getAttribute("aria-hidden") === "true"), "neither is read out");
+ assert.match(BASE, /\.pager-cell > \* \{ grid-area: 1 \/ 1;[^}]*text-align: center; \}/, "laid over one another, the name centred in the widest");
+ assert.match(BASE, /\.pager-cell:first-child \{ max-width: 24ch; \}/);
+ assert.match(BASE, /\.pager-of, \.pager-of \+ \.pager-fit \{ font-variant-numeric: tabular-nums; \}/, "the place and its twin in even figures: 10 of 13 is as wide as 13 of 13");
+ page.location.hash = "#direction-ledger"; page.canvas("direction-ledger");
+ page.pager().querySelector('.pager-item[data-for="direction-ledger"]').click();
+ assert.equal(now.title, "Ledger", "the name's title holds it whole");
+ const next = page.pager().querySelector(".pager-next"), prev = page.pager().querySelector(".pager-prev");
+ assert.deepEqual([prev.title, next.title], ["Previous frame (←, h or k)", "Next frame (→, l or j)"], "the arrows name their keys");
+ const body = new next.constructor("main"), at = () => page.location.hash;
+ page.fire("keydown", body, "l"); assert.equal(at(), "#direction-ask-first", "l: the next");
+ page.fire("keydown", body, "j"); assert.equal(at(), "#direction-header-import", "j: the next");
+ page.fire("keydown", body, "k"); page.fire("keydown", body, "h"); assert.equal(at(), "#direction-ledger", "k, h: the one before");
+ page.fire("keydown", next, "l"); assert.equal(at(), "#direction-ask-first", "from the › just clicked too");
+ for (const tag of ["input", "textarea", "select"]) { const f = new next.constructor(tag); page.fire("keydown", f, "l"); assert.equal(at(), "#direction-ask-first", `typing in a ${tag}`); }
+ const tweaks = new next.constructor("details"), field = new next.constructor("button"); tweaks.className = "tweaks"; tweaks.append(field);
+ page.fire("keydown", field, "l"); assert.equal(at(), "#direction-ask-first", "in the Prototype bar");
+ for (const m of ["metaKey", "ctrlKey", "altKey", "shiftKey"]) { page.fire("keydown", body, "l", { [m]: true }); assert.equal(at(), "#direction-ask-first", m); }
+ page.fire("keydown", body, "l", { defaultPrevented: true }); assert.equal(at(), "#direction-ask-first", "a key the frame took");
+ // A frame's own menu, not [hidden] but in a box that is (a frame not shown): it shows nowhere, so l still steps.
+ const box = new next.constructor("div"), its = new next.constructor("div"); box.hidden = true; its.className = "menu"; box.append(its); page.bar.append(box);
+ page.fire("keydown", body, "l"); assert.equal(at(), "#direction-header-import", "a menu in a hidden box doesn't hold the keys");
+ page.fire("keydown", body, "h"); box.hidden = false;
+ page.fire("keydown", body, "l"); assert.equal(at(), "#direction-ask-first", "the same menu shown does");
+ box.remove();
+ page.fire("click", now); page.fire("keydown", body, "l"); assert.equal(at(), "#direction-ask-first", "with the pager's menu open");
+});
+
test("a frame moved to another group redraws the pager's menu under it", () => {
const page = pagerPage(PAGER_FRAMES);
page.canvas(null);