mirror of
https://github.com/expo/explore.git
synced 2026-11-15 17:32:23 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
47f37988a5 | ||
|
|
1a5a95af63 |
No files matched your search
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@expo/explore",
|
||||
"version": "0.19.3",
|
||||
"version": "0.19.4",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@expo/explore",
|
||||
"version": "0.19.3",
|
||||
"version": "0.19.4",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@expo/repack-app": "0.10.1",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@expo/explore",
|
||||
"version": "0.19.3",
|
||||
"version": "0.19.4",
|
||||
"description": "Source-driven mobile app maps, deterministic CI capture, and visual reviews",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
|
||||
@@ -406,10 +406,13 @@ test("the Screens tree folds by row, by keyboard, and all at once, and remembers
|
||||
await tree.getByRole("button", { name: "Expand all" }).click();
|
||||
await expect.poll(() => rows.count()).toBe(expandedRows);
|
||||
|
||||
// Section headings name the folder, with the path beneath.
|
||||
const onboarding = page.getByRole("region", { name: "Onboarding" });
|
||||
await expect(onboarding.getByRole("heading", { level: 2 })).toHaveText("Onboarding");
|
||||
await expect(onboarding.locator(".screens-section-head .path")).toHaveText("app/onboarding");
|
||||
// The tree names the folders, so the page beside it is one grid without section headings, in the tree's order.
|
||||
await expect(page.locator(".screens-page .screens-section-head")).toHaveCount(0);
|
||||
await expect(page.locator(".screens-page .screens-grid")).toHaveCount(1);
|
||||
const treeOrder = await tree.locator(".screens-tree-row[data-screen-id]").evaluateAll(rows => rows.map(row => row.dataset.screenId));
|
||||
const gridOrder = await page.locator(".screens-page .screens-cell").evaluateAll(cells => cells.map(cell => cell.dataset.screenId));
|
||||
assert.ok(gridOrder.length > 1);
|
||||
assert.deepEqual(gridOrder, treeOrder);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
|
||||
+96
-2
@@ -1309,7 +1309,100 @@ for (const canvas of ["map", "screens"] as const) {
|
||||
});
|
||||
}
|
||||
|
||||
test("reuses the Map screenshot card visual in Screens, with the route at the card's left edge", async ({ page }) => {
|
||||
test("← and → step through the Screens cards in page order, with focus, and leave the tree's arrows alone", async ({ page }) => {
|
||||
await serveWorkspace(page);
|
||||
await page.goto("/screens");
|
||||
const grid = page.getByRole("main", { name: "Screens" });
|
||||
await grid.getByRole("button", { name: /^All/ }).click();
|
||||
const cells = grid.locator(".screens-grid .screens-cell");
|
||||
const ids = await cells.evaluateAll(elements => elements.map(element => element.getAttribute("data-screen-id")!));
|
||||
expect(ids.length).toBeGreaterThan(2);
|
||||
const card = (id: string) => grid.locator(`.screens-cell[data-screen-id="${id}"] .screen-screenshot-card`);
|
||||
const target = (id: string) => grid.locator(`.screens-cell[data-screen-id="${id}"] .screen-screenshot-target`);
|
||||
|
||||
// With nothing selected, → starts at the first card.
|
||||
await expect(grid.locator(".screen-screenshot-card.selected")).toHaveCount(0);
|
||||
await page.keyboard.press("ArrowRight");
|
||||
await expect(card(ids[0]!)).toHaveClass(/selected/);
|
||||
await expect(target(ids[0]!)).toBeFocused();
|
||||
await page.keyboard.press("ArrowRight");
|
||||
await expect(card(ids[1]!)).toHaveClass(/selected/);
|
||||
await expect(target(ids[1]!)).toBeFocused();
|
||||
await page.keyboard.press("ArrowRight");
|
||||
await expect(card(ids[2]!)).toHaveClass(/selected/);
|
||||
await page.keyboard.press("ArrowLeft");
|
||||
await expect(card(ids[1]!)).toHaveClass(/selected/);
|
||||
await expect(card(ids[2]!)).not.toHaveClass(/selected/);
|
||||
|
||||
// ↓ and ↑ move a row, to the card in the same column.
|
||||
const tops = await cells.evaluateAll(elements => elements.map(element => Math.round(element.getBoundingClientRect().top)));
|
||||
const columns = tops.filter(top => top === tops[0]).length;
|
||||
if (ids.length > 1 + columns) {
|
||||
await page.keyboard.press("ArrowDown");
|
||||
await expect(card(ids[1 + columns]!)).toHaveClass(/selected/);
|
||||
await expect(target(ids[1 + columns]!)).toBeFocused();
|
||||
await page.keyboard.press("ArrowUp");
|
||||
await expect(card(ids[1]!)).toHaveClass(/selected/);
|
||||
}
|
||||
|
||||
// Held, → keeps stepping, as in Compare, and stops on release.
|
||||
const selectedAt = async () => ids.indexOf((await grid.locator(".screens-cell:has(.screen-screenshot-card.selected)").getAttribute("data-screen-id"))!);
|
||||
const from = await selectedAt();
|
||||
await page.keyboard.down("ArrowRight");
|
||||
await expect.poll(selectedAt, { timeout: 4000 }).toBeGreaterThanOrEqual(Math.min(ids.length - 1, from + 3));
|
||||
await page.keyboard.up("ArrowRight");
|
||||
const released = await selectedAt();
|
||||
await page.waitForTimeout(500);
|
||||
expect(await selectedAt()).toBe(released);
|
||||
|
||||
// Return opens the pick in the Inspector, from the card or from anywhere on the page.
|
||||
const inspector = page.getByRole("complementary", { name: "Inspector panel" });
|
||||
await expect(inspector).toBeHidden();
|
||||
await page.keyboard.press("Enter");
|
||||
await expect(inspector).toBeVisible();
|
||||
await page.keyboard.press("Escape");
|
||||
await expect(inspector).toBeHidden();
|
||||
await page.evaluate(() => (document.activeElement as HTMLElement | null)?.blur());
|
||||
await page.keyboard.press("Enter");
|
||||
await expect(inspector).toBeVisible();
|
||||
await page.keyboard.press("Escape");
|
||||
await expect(inspector).toBeHidden();
|
||||
|
||||
// In the tree, ← and → fold and unfold rows; they do not step the cards.
|
||||
const picked = await selectedAt();
|
||||
const row = grid.locator(".screens-tree-row").first();
|
||||
await row.focus();
|
||||
await page.keyboard.press("ArrowLeft");
|
||||
await expect(card(ids[picked]!)).toHaveClass(/selected/);
|
||||
});
|
||||
|
||||
test("→ steps the Screens cards right after Screens is opened from the toolbar, and from a pick that Changed hides", async ({ page }) => {
|
||||
await serveWorkspace(page);
|
||||
await page.goto("/map");
|
||||
await page.getByRole("group", { name: "Canvas view" }).getByRole("button", { name: "Screens", exact: true }).click();
|
||||
const grid = page.getByRole("main", { name: "Screens" });
|
||||
const cells = grid.locator(".screens-grid .screens-cell");
|
||||
await expect(cells.first()).toBeVisible();
|
||||
// Focus is still on the toolbar's Screens button.
|
||||
await page.keyboard.press("ArrowRight");
|
||||
await expect(cells.first().locator(".screen-screenshot-card")).toHaveClass(/selected/);
|
||||
|
||||
// Pick a screen that Changed hides, then show Changed: → goes to the next changed card after it in the tree.
|
||||
await grid.getByRole("button", { name: /^All/ }).click();
|
||||
const all = await cells.evaluateAll(elements => elements.map(element => element.getAttribute("data-screen-id")!));
|
||||
await grid.getByRole("button", { name: /^Changed/ }).click();
|
||||
const changed = await cells.evaluateAll(elements => elements.map(element => element.getAttribute("data-screen-id")!));
|
||||
const hidden = all.find((id, position) => !changed.includes(id) && all.slice(position + 1).some(next => changed.includes(next)));
|
||||
test.skip(!hidden, "the fixture has no unchanged screen before a changed one");
|
||||
await grid.getByRole("button", { name: /^All/ }).click();
|
||||
await grid.locator(`.screens-cell[data-screen-id="${hidden}"] .screen-screenshot-target`).click();
|
||||
await grid.getByRole("button", { name: /^Changed/ }).click();
|
||||
const expected = all.slice(all.indexOf(hidden!) + 1).find(id => changed.includes(id))!;
|
||||
await page.keyboard.press("ArrowRight");
|
||||
await expect(grid.locator(`.screens-cell[data-screen-id="${expected}"] .screen-screenshot-card`)).toHaveClass(/selected/);
|
||||
});
|
||||
|
||||
test("reuses the Map screenshot card in Screens, with the route under the screenshot at the card's left edge", async ({ page }) => {
|
||||
await serveWorkspace(page);
|
||||
await page.goto("/screens");
|
||||
|
||||
@@ -1337,8 +1430,9 @@ test("reuses the Map screenshot card visual in Screens, with the route at the ca
|
||||
};
|
||||
});
|
||||
expect(layout.flexDirection).toBe("column");
|
||||
// The card is the Map's, so the heading still comes first in the markup; Screens shows it as the card's footer.
|
||||
expect(layout.headingBeforeImage).toBe(true);
|
||||
expect(layout.headingTop).toBeLessThan(layout.imageTop);
|
||||
expect(layout.headingTop).toBeGreaterThan(layout.imageTop);
|
||||
expect(layout.titleLeftDelta).toBeLessThan(1);
|
||||
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import test from "node:test";
|
||||
|
||||
const { tsImport } = await import("tsx/esm/api");
|
||||
const { indexMap } = await tsImport("../../viewer/src/utils/model.ts", import.meta.url);
|
||||
const { screenTree } = await tsImport("../../viewer/src/utils/screen-tree.ts", import.meta.url);
|
||||
const { screenTree, treeScreenOrder } = await tsImport("../../viewer/src/utils/screen-tree.ts", import.meta.url);
|
||||
|
||||
const at = (second) => `2026-10-13T00:00:${String(second).padStart(2, "0")}.000Z`;
|
||||
function screen(id, title, depth, extra = {}) {
|
||||
@@ -49,6 +49,20 @@ test("with route files, sections follow the app directory and the tabs lead", ()
|
||||
assert.deepEqual(folders, ["(tabs)/"]);
|
||||
});
|
||||
|
||||
test("the screens' order is the tree's, depth first: a nested folder's screens come right after their parent's", () => {
|
||||
// The folders are found as settings, feed, settings/security: sections keep that order, while the tree nests
|
||||
// security under settings. The Screens grid and its arrow keys follow the tree, as the sidebar reads.
|
||||
const screens = [screen("profile", "A profile", 1), screen("feed", "B feed", 1), screen("security", "C security", 1), screen("loose", "D loose", 1)];
|
||||
const routeFiles = new Map([
|
||||
["profile", "app/settings/profile.tsx"],
|
||||
["feed", "app/feed/index.tsx"],
|
||||
["security", "app/settings/security/index.tsx"],
|
||||
]);
|
||||
const tree = screenTree(screens, indexMap(map({ screens })), routeFiles);
|
||||
assert.deepEqual(tree.sections.flatMap(section => section.screenIds), ["profile", "feed", "security", "loose"]);
|
||||
assert.deepEqual(treeScreenOrder(tree), ["profile", "security", "feed", "loose"]);
|
||||
});
|
||||
|
||||
test("a black-box exploration groups by the tab each screen was opened from", () => {
|
||||
const screens = [
|
||||
screen("seq", "Sequencer", 0),
|
||||
|
||||
@@ -15,6 +15,21 @@ test("hints print modifiers in Apple's ⌥⇧⌘ order and as Ctrl+Alt+Shift els
|
||||
assert.equal(formatShortcut(SHORTCUTS.camera.fit, true), "⇧1");
|
||||
assert.equal(formatShortcut({ code: "KeyT", key: "T", mod: true, alt: true }, false), "Ctrl+Alt+T");
|
||||
assert.equal(formatShortcut(SHORTCUTS.edit.redo, false), "Ctrl+Shift+Z");
|
||||
// The Control key itself prints as ⌃ on a Mac, where ⌘ would be a different key.
|
||||
assert.equal(formatShortcut(SHORTCUTS.canvasByNumber.screens, true), "⌃2");
|
||||
assert.equal(formatShortcut(SHORTCUTS.canvasByNumber.screens, false), "Ctrl+2");
|
||||
});
|
||||
|
||||
test("Ctrl+1, Ctrl+2 and Ctrl+3 reach Map, Screens and Compare with Control alone, never ⌘ (the browser's tab keys)", () => {
|
||||
assert.equal(matchesShortcut(key("Digit1", { ctrlKey: true }), SHORTCUTS.canvasByNumber.map), true);
|
||||
assert.equal(matchesShortcut(key("Digit2", { ctrlKey: true }), SHORTCUTS.canvasByNumber.screens), true);
|
||||
assert.equal(matchesShortcut(key("Digit3", { ctrlKey: true }), SHORTCUTS.canvasByNumber.compare), true);
|
||||
assert.equal(matchesShortcut(key("Digit1", { metaKey: true }), SHORTCUTS.canvasByNumber.map), false);
|
||||
assert.equal(matchesShortcut(key("Digit1", { ctrlKey: true, metaKey: true }), SHORTCUTS.canvasByNumber.map), false);
|
||||
assert.equal(matchesShortcut(key("Digit1", { ctrlKey: true, shiftKey: true }), SHORTCUTS.canvasByNumber.map), false);
|
||||
// Compare's 1, 2, 3 (Split, Swipe, Flip) stay plain digits.
|
||||
assert.equal(matchesShortcut(key("Digit1", { ctrlKey: true }), SHORTCUTS.compare.split), false);
|
||||
assert.equal(matchesShortcut(key("Digit1"), SHORTCUTS.canvasByNumber.map), false);
|
||||
});
|
||||
|
||||
test("a chord matches only its own modifiers, on either ⌘ or Ctrl", () => {
|
||||
@@ -35,7 +50,8 @@ test("no two shortcuts share a chord", () => {
|
||||
const seen = new Map();
|
||||
for (const [group, entries] of Object.entries(SHORTCUTS)) {
|
||||
for (const [name, shortcut] of Object.entries(entries)) {
|
||||
const chord = `${shortcut.code}:${Boolean(shortcut.mod)}:${Boolean(shortcut.alt)}:${Boolean(shortcut.shift)}`;
|
||||
// Off Apple keyboards ⌘ is Ctrl, so a Control chord clashes with the same ⌘ chord.
|
||||
const chord = `${shortcut.code}:${Boolean(shortcut.mod || shortcut.ctrl)}:${Boolean(shortcut.alt)}:${Boolean(shortcut.shift)}`;
|
||||
const clash = seen.get(chord);
|
||||
assert.ok(!clash, `${group}.${name} repeats ${clash}`);
|
||||
seen.set(chord, `${group}.${name}`);
|
||||
|
||||
+5
-1
@@ -46,6 +46,7 @@ import {
|
||||
type ThemePreference,
|
||||
} from "./utils/navigation";
|
||||
import {
|
||||
CANVAS_NUMBER_KEYS,
|
||||
matchesShortcut,
|
||||
modalOpen,
|
||||
SHORTCUTS,
|
||||
@@ -142,7 +143,10 @@ const LEGACY_COLLAPSED_STORAGE_KEY = "expo-explore:panel-collapsed";
|
||||
const RIGHT_COLLAPSED_STORAGE_KEY = "expo-explore:right-panel-collapsed";
|
||||
// The shell's keyboard map, paired with what each key selects. Read as lists so a key and the
|
||||
// thing it reaches stay one entry.
|
||||
const CANVAS_KEYS = Object.entries(SHORTCUTS.canvas) as [CanvasView, Shortcut][];
|
||||
const CANVAS_KEYS = [
|
||||
...Object.entries(SHORTCUTS.canvas),
|
||||
...(CANVAS_NUMBER_KEYS ? Object.entries(SHORTCUTS.canvasByNumber) : []),
|
||||
] as [CanvasView, Shortcut][];
|
||||
|
||||
/** Before data loads there is no comparison to assume. A workspace reparses the URL on arrival. */
|
||||
const EMPTY_ROUTE_CONTEXT: RouteContext = {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useEffect } from "react";
|
||||
import { createPortal } from "react-dom";
|
||||
import { X } from "lucide-react";
|
||||
import { formatShortcut, SHORTCUTS, type Shortcut } from "../../utils/shortcuts";
|
||||
import { CANVAS_NUMBER_KEYS, formatShortcut, SHORTCUTS, type Shortcut } from "../../utils/shortcuts";
|
||||
import type { CanvasView } from "../../utils/navigation";
|
||||
import { useModalDialog } from "../../hooks/use-modal-dialog";
|
||||
|
||||
@@ -63,6 +63,9 @@ export function shortcutGroups(context: ShortcutContext): Group[][] {
|
||||
label: context.hasChanges ? "Map, Screens, Compare" : "Map, Screens",
|
||||
keys: sections.map((section) => SHORTCUTS.canvas[section]),
|
||||
},
|
||||
...(CANVAS_NUMBER_KEYS
|
||||
? [{ label: "The same, by their place in the toolbar", keys: sections.map((section) => SHORTCUTS.canvasByNumber[section]) }]
|
||||
: []),
|
||||
{ label: "Search screens", keys: [SHORTCUTS.app.search] },
|
||||
...(context.handoff ? [{ label: "Hand off to AI", keys: [SHORTCUTS.app.handoff] }] : []),
|
||||
...(context.hasChanges ? [{ label: "Changed screens menu", keys: [SHORTCUTS.app.changes] }] : []),
|
||||
@@ -83,9 +86,17 @@ export function shortcutGroups(context: ShortcutContext): Group[][] {
|
||||
{ label: "Close the inspector, then deselect", keys: ["Esc"] },
|
||||
],
|
||||
};
|
||||
const screensGroup: Group = {
|
||||
title: "Screens",
|
||||
rows: [
|
||||
{ label: "Move through the screens", keys: ["←", "→", "↑", "↓"] },
|
||||
{ label: "Close the inspector, then deselect", keys: ["Esc"] },
|
||||
],
|
||||
};
|
||||
const here: Group[] = context.canvas === "compare"
|
||||
? [reviewGroup(context)]
|
||||
: [...(context.review ? [reviewGroup(context)] : []), ...(context.canvas === "map" ? [mapGroup] : []), CAMERA];
|
||||
: [...(context.review ? [reviewGroup(context)] : []), ...(context.canvas === "map" ? [mapGroup] : []),
|
||||
...(context.canvas === "screens" ? [screensGroup] : []), CAMERA];
|
||||
return [here, [goTo, view]];
|
||||
}
|
||||
|
||||
|
||||
@@ -184,6 +184,91 @@ button.screens-tree-row:hover { color: var(--text); background: var(--panel-hove
|
||||
.screens-cell-via { overflow: hidden; color: var(--tertiary); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.screens-cell-elsewhere { color: var(--modified); font-size: 11px; font-weight: 600; }
|
||||
|
||||
/* ── Desktop grid ── */
|
||||
/* One evenly spaced grid. Each screen is a card: the screenshot in a grey well and the route under it, with the
|
||||
status as the tree's dot before it, the way file browsers show documents. Nothing is framed in the status colour,
|
||||
so the page reads as a list of screens rather than a canvas of them. */
|
||||
.screens-page:not(.phone) .screens-sections { display: block; padding-top: 0; }
|
||||
.screens-page:not(.phone) .screens-grid { gap: 12px; }
|
||||
/* Wide enough for a 28-character route after the dot, in the footer's 10.5px mono with room to spare: Linux's
|
||||
fonts set it at about 183px. Five cards fit beside the tree at 1440px. */
|
||||
.screens-page:not(.phone) .screens-cell { width: 216px; }
|
||||
.screens-page:not(.phone) .screens-cell .screen-screenshot-card {
|
||||
overflow: hidden;
|
||||
gap: 0;
|
||||
border: 1px solid var(--border-subtle);
|
||||
border-radius: 12px;
|
||||
background: var(--surface);
|
||||
transition: border-color 120ms ease, box-shadow 120ms ease;
|
||||
}
|
||||
.screens-page:not(.phone) .screens-cell .screen-screenshot-card:has(.screen-screenshot-target:hover) { border-color: color-mix(in srgb, var(--accent) 55%, var(--border-subtle)); }
|
||||
.screens-page:not(.phone) .screens-cell .screen-screenshot-card.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
|
||||
/* The status is laid out against the card, not the screenshot, so it can sit in the footer. */
|
||||
.screens-page:not(.phone) .screens-cell :is(.screen-screenshot-slot, .diff-frame) { position: static; }
|
||||
.screens-page:not(.phone) .screens-cell .screen-screenshot-slot { order: 1; height: 236px; flex: none; padding: 12px 0; background: var(--element); }
|
||||
.screens-page:not(.phone) .screens-cell .screen-screenshot-card.selected .screen-screenshot-slot { background: var(--accent-soft); }
|
||||
.screens-page:not(.phone) .screens-cell .screen-node-image img,
|
||||
.screens-page:not(.phone) .screens-cell .screen-node-image > .image-placeholder,
|
||||
.screens-page:not(.phone) .screens-cell .screen-screenshot-card .diff-frame .screen-node-image img,
|
||||
.screens-page:not(.phone) .screens-cell .screen-screenshot-card .diff-frame .screen-node-image > .image-placeholder {
|
||||
border-color: transparent;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 1px 3px rgb(0 0 0 / 0.14);
|
||||
}
|
||||
/* The image box hugs the screenshot, so its corners and shadow are the screenshot's and no box shows around it. */
|
||||
/* The screenshot fits the well both ways at its own proportions (styles.css's max-width and max-height), so a
|
||||
landscape capture is framed as itself, not letterboxed inside a portrait-sized box. */
|
||||
.screens-page:not(.phone) .screens-cell .screen-node-image img { width: auto; height: auto; background: transparent; }
|
||||
/* No screenshot: the well has a size here, so the placeholder fits it the way styles.css fits it to a Map slot,
|
||||
at the screenshot's proportions, rather than by the cell's width as a phone's cell does (phone.css). */
|
||||
.screens-page:not(.phone) .screens-cell .screen-node-image:has(> .image-placeholder) { container-type: size; }
|
||||
.screens-page:not(.phone) .screens-cell .screen-node-image > .image-placeholder {
|
||||
width: min(
|
||||
100cqw - 2 * var(--frame-border),
|
||||
(100cqh - 2 * var(--frame-border)) * var(--screenshot-width) / var(--screenshot-height),
|
||||
var(--screenshot-width) * 1px
|
||||
);
|
||||
height: min(
|
||||
100cqh - 2 * var(--frame-border),
|
||||
(100cqw - 2 * var(--frame-border)) * var(--screenshot-height) / var(--screenshot-width),
|
||||
var(--screenshot-height) * 1px
|
||||
);
|
||||
aspect-ratio: auto;
|
||||
}
|
||||
/* A selected card's button is pressed, and a focused pressed button brightens (styles.css). Here that would wash out
|
||||
the screenshot and, as a filter, become the box the status is placed in, lifting it into the well. Keyboard focus
|
||||
rings the card instead. */
|
||||
.screens-page:not(.phone) .screens-cell .screen-screenshot-target:focus-visible { filter: none; outline: 0; }
|
||||
.screens-page:not(.phone) .screens-cell .screen-screenshot-card:has(.screen-screenshot-target:focus-visible) {
|
||||
box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 42%, transparent);
|
||||
}
|
||||
.screens-page:not(.phone) .screens-cell .screen-screenshot-card.selected:has(.screen-screenshot-target:focus-visible) {
|
||||
box-shadow: 0 0 0 1px var(--accent), 0 0 0 4px color-mix(in srgb, var(--accent) 32%, transparent);
|
||||
}
|
||||
.screens-page:not(.phone) .screens-cell .screen-node-heading { order: 2; min-height: 0; padding: 10px 6px 10px 8px; }
|
||||
.screens-page:not(.phone) .screens-cell .screen-screenshot-card:has(.diff-label) .screen-node-heading { padding-left: 20px; }
|
||||
.screens-page:not(.phone) .screens-cell .screen-node-title { font-size: 10.5px; line-height: 14px; }
|
||||
.screens-page:not(.phone) .screens-cell .screen-screenshot-card.selected .screen-node-title { color: var(--accent-strong); font-weight: 600; }
|
||||
/* The status is the tree's dot before the route, in the status colour (a square for accessibility only); the word
|
||||
stays in the label's accessible name. */
|
||||
.screens-page:not(.phone) .screens-cell .screen-screenshot-card .diff-label {
|
||||
top: auto;
|
||||
bottom: 13.5px;
|
||||
left: 8px;
|
||||
width: 7px;
|
||||
height: 7px;
|
||||
overflow: hidden;
|
||||
padding: 0;
|
||||
border-radius: 50%;
|
||||
color: transparent;
|
||||
background: var(--diff);
|
||||
box-shadow: none;
|
||||
font-size: 0;
|
||||
transform: none;
|
||||
}
|
||||
.screens-page:not(.phone) .screens-cell .diff-accessibility-only .diff-label { border-radius: 2px; }
|
||||
.screens-page:not(.phone) .screens-cell :is(.screens-cell-via, .screens-cell-elsewhere) { padding-inline: 2px; }
|
||||
|
||||
/* ── Phone ── */
|
||||
/* The space under the top bar is a block, not padding: both engines inset a sticky child's rest
|
||||
position by the scroll container's padding, which pushed the section bar a bar's height too low. */
|
||||
|
||||
@@ -5,9 +5,11 @@ import { primaryScreenshotForScreen, screenshotSize } from "../../utils/screen-i
|
||||
import { diffClass, type BuildDiff, type DiffStatus } from "../../utils/build-diff";
|
||||
import { focusStatusOf, isCapturedChange } from "../../utils/changed-screens";
|
||||
import { displayPathForScreen, screenLabel } from "../../utils/screen-path";
|
||||
import { screenTree, treeIndex, treeNodeKey, type ScreenTree, type ScreenTreeNode } from "../../utils/screen-tree";
|
||||
import { screenTree, treeIndex, treeNodeKey, treeScreenOrder, type ScreenTree, type ScreenTreeNode } from "../../utils/screen-tree";
|
||||
import type { Appearance } from "../../utils/appearance";
|
||||
import type { FocusRequest, FocusStatus } from "../../utils/navigation";
|
||||
import { shortcutsLive } from "../../utils/shortcuts";
|
||||
import { HOLD_INITIAL_DELAY_MS, holdIntervalMs } from "../../utils/key-hold";
|
||||
import { ScreenScreenshotCard } from "../canvas/screen-screenshot-card";
|
||||
import { useCanvasVisibleFrame } from "../canvas/visible-frame-provider";
|
||||
import { PhoneSheet } from "../phone/phone-chrome";
|
||||
@@ -75,6 +77,26 @@ function cardId(id: string): string {
|
||||
return `screens-card-${id.replace(/[^A-Za-z0-9_-]/g, "_")}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* The card in the row above or below a screen's, nearest it across: read from where the cards sit, so it follows the
|
||||
* grid however many columns the page has room for. A short last row still takes ↓ from the row above it.
|
||||
*/
|
||||
function cardInNextRow(from: string, ids: readonly string[], down: boolean): string | undefined {
|
||||
const box = (id: string) => document.getElementById(cardId(id))?.getBoundingClientRect();
|
||||
const here = box(from);
|
||||
if (!here) return undefined;
|
||||
const centre = (rect: DOMRect) => rect.left + rect.width / 2;
|
||||
const rows = ids.flatMap(id => {
|
||||
const rect = box(id);
|
||||
return rect && (down ? rect.top >= here.bottom - 1 : rect.bottom <= here.top + 1) ? [{ id, rect }] : [];
|
||||
});
|
||||
if (!rows.length) return undefined;
|
||||
const nearestTop = down ? Math.min(...rows.map(row => row.rect.top)) : Math.max(...rows.map(row => row.rect.top));
|
||||
const row = rows.filter(candidate => Math.abs(candidate.rect.top - nearestTop) < 1);
|
||||
return row.reduce((best, candidate) =>
|
||||
Math.abs(centre(candidate.rect) - centre(here)) < Math.abs(centre(best.rect) - centre(here)) ? candidate : best).id;
|
||||
}
|
||||
|
||||
function sectionAnchor(id: string): string {
|
||||
return `screens-section-${id.replace(/[^A-Za-z0-9_-]/g, "_")}`;
|
||||
}
|
||||
@@ -168,6 +190,7 @@ function TreeRows(props: {
|
||||
<button type="button" style={style}
|
||||
className={`screens-tree-row${node.tab ? " tab" : ""}${props.visible.has(screen.id) ? "" : " filtered"}`}
|
||||
aria-current={props.selectedScreenId === screen.id ? "true" : undefined}
|
||||
data-screen-id={screen.id}
|
||||
aria-expanded={key ? open : undefined}
|
||||
data-tree-key={key}
|
||||
onClick={() => props.onSelect(screen.id)}>
|
||||
@@ -202,8 +225,8 @@ function Legend(props: { others: Appearance[] }) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Screens as a page that scrolls: a section per route folder (or per tab, when there are no route
|
||||
* files), with the tree of them beside it on desktop and behind a Tree button on a phone.
|
||||
* Screens as a page that scrolls. On desktop, one grid of every screen in the order of the tree beside it; on a
|
||||
* phone, a section per route folder (or per tab, when there are no route files), with the tree behind a Tree button.
|
||||
*/
|
||||
export function ScreensView(props: ScreensViewProps) {
|
||||
const tree: ScreenTree = useMemo(
|
||||
@@ -222,6 +245,9 @@ export function ScreensView(props: ScreensViewProps) {
|
||||
const sections = tree.sections
|
||||
.map(section => ({ ...section, screenIds: section.screenIds.filter(id => shown.has(id)) }))
|
||||
.filter(section => section.screenIds.length > 0);
|
||||
// The desktop grid reads in the tree's order, not the sections' (screen-tree.ts).
|
||||
const treeOrder = useMemo(() => treeScreenOrder(tree), [tree]);
|
||||
const order = props.phone ? sections.flatMap(section => section.screenIds) : treeOrder.filter(id => shown.has(id));
|
||||
const others = [...new Set([...(props.changedElsewhere?.values() ?? [])].flat())];
|
||||
|
||||
// Folding. All keeps the reader's folds and remembers them per report. Changed folds separately, starting
|
||||
@@ -321,12 +347,118 @@ export function ScreensView(props: ScreensViewProps) {
|
||||
requestAnimationFrame(() => document.getElementById(cardId(id))?.scrollIntoView({ block: "center", behavior: "smooth" }));
|
||||
};
|
||||
|
||||
// On desktop the arrow keys move through the cards: ← and → in their order on the page (`order`), as the arrows step
|
||||
// through screens in Compare, and ↑ and ↓ to the card above or below, by where the cards sit, so they follow the grid
|
||||
// at any width. A step picks the screen as the tree does, leaving the Inspector as it is, and focus follows it; with
|
||||
// nothing picked, → and ↓ start at the first card, and a pick that Changed hides steps from where it sits in the tree.
|
||||
// The tree's rows keep their arrow keys, and so do the Inspector's controls. Phones are left as they were.
|
||||
// Held, an arrow keeps stepping as Compare's do (key-hold.ts). Return opens the picked screen in the Inspector, as a
|
||||
// click on its card does; on the card itself the button already does.
|
||||
const orderRef = useRef(order);
|
||||
orderRef.current = order;
|
||||
const treeOrderRef = useRef(treeOrder);
|
||||
treeOrderRef.current = treeOrder;
|
||||
const selectedRef = useRef(selected);
|
||||
selectedRef.current = selected;
|
||||
const pickRef = useRef(props.onPickScreen ?? props.onSelectScreen);
|
||||
pickRef.current = props.onPickScreen ?? props.onSelectScreen;
|
||||
const openRef = useRef(props.onSelectScreen);
|
||||
openRef.current = props.onSelectScreen;
|
||||
useEffect(() => {
|
||||
if (props.phone) return;
|
||||
/** The card an arrow moves to from `from` (the pick, or the last card a hold stepped to). */
|
||||
const next = (code: string, from: string | undefined): string | undefined => {
|
||||
const ids = orderRef.current;
|
||||
const vertical = code === "ArrowUp" || code === "ArrowDown";
|
||||
const forward = code === "ArrowRight" || code === "ArrowDown";
|
||||
if (from && ids.includes(from)) return vertical ? cardInNextRow(from, ids, forward) : ids[ids.indexOf(from) + (forward ? 1 : -1)];
|
||||
if (from && treeOrderRef.current.includes(from)) {
|
||||
// Picked, but hidden by Changed: the nearest shown card past it in the tree's order.
|
||||
const shownIds = new Set(ids);
|
||||
const all = treeOrderRef.current;
|
||||
const at = all.indexOf(from);
|
||||
return (forward ? all.slice(at + 1) : all.slice(0, at).reverse()).find(candidate => shownIds.has(candidate));
|
||||
}
|
||||
return forward ? ids[0] : ids[ids.length - 1];
|
||||
};
|
||||
const go = (id: string) => {
|
||||
pickRef.current(id);
|
||||
requestAnimationFrame(() => document.getElementById(cardId(id))?.querySelector<HTMLElement>(".screen-screenshot-target")?.focus({ preventScroll: true }));
|
||||
};
|
||||
let hold: { code: string; at: string; timer: ReturnType<typeof setTimeout> } | undefined;
|
||||
const endHold = () => {
|
||||
if (hold) clearTimeout(hold.timer);
|
||||
hold = undefined;
|
||||
};
|
||||
const beginHold = (code: string, at: string) => {
|
||||
endHold();
|
||||
let step = 1;
|
||||
const tick = () => {
|
||||
const id = hold && next(code, hold.at);
|
||||
if (!hold || !id) { endHold(); return; }
|
||||
go(id);
|
||||
hold = { code, at: id, timer: setTimeout(tick, holdIntervalMs(step)) };
|
||||
step += 1;
|
||||
};
|
||||
hold = { code, at, timer: setTimeout(tick, HOLD_INITIAL_DELAY_MS) };
|
||||
};
|
||||
const onKeyDown = (event: globalThis.KeyboardEvent) => {
|
||||
const arrow = ["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].includes(event.code);
|
||||
if (!arrow && event.key !== "Enter") return;
|
||||
// The browser's own repeat of a held arrow would scroll the page under the hold.
|
||||
if (event.repeat && hold?.code === event.code) { event.preventDefault(); return; }
|
||||
if (event.metaKey || event.ctrlKey || event.altKey || event.shiftKey || event.defaultPrevented || !shortcutsLive(event)) return;
|
||||
const target = event.target instanceof Element ? event.target : null;
|
||||
if (!arrow) {
|
||||
// Return on a button or a link presses it; elsewhere on the page it opens the pick.
|
||||
const selectedId = selectedRef.current;
|
||||
if (target?.closest("button, a, [role=\"button\"]") || !target?.closest("body") || !selectedId || !orderRef.current.includes(selectedId)) return;
|
||||
if (target !== document.body && !target.closest(".screens-page")) return;
|
||||
event.preventDefault();
|
||||
openRef.current(selectedId);
|
||||
return;
|
||||
}
|
||||
// The page, or the bottom toolbar that Screens was just opened from; its buttons have no arrow keys of their own.
|
||||
const onPage = !target || target === document.body || target.closest(".screens-page, .canvas-toolbar") !== null;
|
||||
if (!onPage || target?.closest(".screens-tree-list")) return;
|
||||
const id = next(event.code, selectedRef.current);
|
||||
if (!id) return;
|
||||
event.preventDefault();
|
||||
go(id);
|
||||
beginHold(event.code, id);
|
||||
};
|
||||
const onKeyUp = (event: globalThis.KeyboardEvent) => {
|
||||
if (hold && event.code === hold.code) endHold();
|
||||
};
|
||||
window.addEventListener("keydown", onKeyDown);
|
||||
window.addEventListener("keyup", onKeyUp);
|
||||
window.addEventListener("blur", endHold);
|
||||
return () => {
|
||||
endHold();
|
||||
window.removeEventListener("keydown", onKeyDown);
|
||||
window.removeEventListener("keyup", onKeyUp);
|
||||
window.removeEventListener("blur", endHold);
|
||||
};
|
||||
}, [props.phone]);
|
||||
|
||||
// The Inspector floats over the right edge; the page keeps its content clear of it.
|
||||
const { visibleFrame } = useCanvasVisibleFrame();
|
||||
const style = !props.phone && visibleFrame
|
||||
? ({ "--screens-right-inset": `calc(100% - ${visibleFrame.x + visibleFrame.width}px)` } as CSSProperties)
|
||||
: undefined;
|
||||
|
||||
const cell = (id: string) => {
|
||||
const screen = props.index.screens.get(id);
|
||||
return screen ? (
|
||||
<ScreenCell key={id} screen={screen} index={props.index} diff={props.diff}
|
||||
elsewhere={isChanged(props.diff, id) ? undefined : props.changedElsewhere?.get(id)}
|
||||
via={tree.via.get(id)}
|
||||
selected={props.selectedScreenId === id}
|
||||
dimmed={Boolean(props.focus?.length) && !props.focus!.some((state) => state === focusStatusOf(props.diff?.screens.get(id)))}
|
||||
onSelect={() => props.onSelectScreen(id)} />
|
||||
) : null;
|
||||
};
|
||||
|
||||
const treeRows = (
|
||||
<ul className="screens-tree-list" onKeyDown={onTreeKey}>
|
||||
<TreeRows nodes={tree.tree} depth={0} index={props.index} diff={props.diff} elsewhere={props.changedElsewhere}
|
||||
@@ -378,28 +510,20 @@ export function ScreensView(props: ScreensViewProps) {
|
||||
</aside>
|
||||
)}
|
||||
<div className="screens-sections">
|
||||
{sections.map(section => (
|
||||
{props.phone ? sections.map(section => (
|
||||
<section key={section.id} id={sectionAnchor(section.id)} className="screens-section" aria-label={section.name ?? section.title}>
|
||||
<header className="screens-section-head">
|
||||
<h2>{section.name ?? section.title}</h2>
|
||||
{section.path ? <span className="path">{breakAfterSlashes(section.title)}</span>
|
||||
: section.subtitle ? <span>{section.subtitle}</span> : null}
|
||||
</header>
|
||||
<div className="screens-grid">
|
||||
{section.screenIds.map(id => {
|
||||
const screen = props.index.screens.get(id);
|
||||
return screen ? (
|
||||
<ScreenCell key={id} screen={screen} index={props.index} diff={props.diff}
|
||||
elsewhere={isChanged(props.diff, id) ? undefined : props.changedElsewhere?.get(id)}
|
||||
via={tree.via.get(id)}
|
||||
selected={props.selectedScreenId === id}
|
||||
dimmed={Boolean(props.focus?.length) && !props.focus!.some((state) => state === focusStatusOf(props.diff?.screens.get(id)))}
|
||||
onSelect={() => props.onSelectScreen(id)} />
|
||||
) : null;
|
||||
})}
|
||||
</div>
|
||||
<div className="screens-grid">{section.screenIds.map(cell)}</div>
|
||||
</section>
|
||||
))}
|
||||
)) : (
|
||||
// On desktop the tree beside the page already shows the folders, so every screen sits in one evenly
|
||||
// spaced grid in the tree's order, without headings between them.
|
||||
<div className="screens-grid">{order.map(cell)}</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
* or a spinner accelerates. The browser's own key repeat is ignored (its rate is a fixed OS setting),
|
||||
* so the hold is timed here and ends on key up, blur, or the end of the list.
|
||||
*/
|
||||
export const HOLD_INITIAL_DELAY_MS = 400;
|
||||
export const HOLD_FIRST_INTERVAL_MS = 300;
|
||||
export const HOLD_INITIAL_DELAY_MS = 250;
|
||||
export const HOLD_FIRST_INTERVAL_MS = 200;
|
||||
export const HOLD_FLOOR_INTERVAL_MS = 70;
|
||||
const HOLD_DECAY = 0.8;
|
||||
|
||||
|
||||
@@ -228,6 +228,22 @@ export type ScreenTreeIndex = {
|
||||
parents: Map<string, string>;
|
||||
};
|
||||
|
||||
/**
|
||||
* Every screen in the order the tree lists it: depth first, so a subfolder's screens follow its parent folder's own,
|
||||
* where sections list folders in the order they were found. A screen the tree leaves out comes last.
|
||||
*/
|
||||
export function treeScreenOrder(tree: ScreenTree): string[] {
|
||||
const ids: string[] = [];
|
||||
const walk = (nodes: readonly ScreenTreeNode[]) => {
|
||||
for (const node of nodes) {
|
||||
if (node.kind === "screen") ids.push(node.screenId);
|
||||
walk(node.children);
|
||||
}
|
||||
};
|
||||
walk(tree.tree);
|
||||
return [...new Set([...ids, ...tree.sections.flatMap(section => section.screenIds)])];
|
||||
}
|
||||
|
||||
export function treeIndex(tree: readonly ScreenTreeNode[]): ScreenTreeIndex {
|
||||
const index: ScreenTreeIndex = { keys: [], screensUnder: new Map(), ancestors: new Map(), parents: new Map() };
|
||||
const walk = (nodes: readonly ScreenTreeNode[], above: string[]): string[] => nodes.flatMap((node) => {
|
||||
|
||||
@@ -7,6 +7,8 @@ export type Shortcut = {
|
||||
code: string;
|
||||
/** ⌘ on Apple keyboards, Ctrl everywhere else. */
|
||||
mod?: boolean;
|
||||
/** The Control key itself on every keyboard, for chords whose ⌘ form the browser keeps (⌘1–⌘9 switch tabs). */
|
||||
ctrl?: boolean;
|
||||
/** ⌥ on Apple keyboards, Alt everywhere else. */
|
||||
alt?: boolean;
|
||||
shift?: boolean;
|
||||
@@ -17,6 +19,12 @@ export type Shortcut = {
|
||||
const APPLE = typeof navigator !== "undefined"
|
||||
&& /Mac|iPhone|iPad|iPod/.test(navigator.platform || navigator.userAgent);
|
||||
|
||||
/**
|
||||
* Whether Ctrl+1–3 reach the page. On Apple keyboards ⌃ is free (the browser's tab keys are ⌘1–9); elsewhere the
|
||||
* browser keeps Ctrl+1–8 for its tabs, so those keys are neither handled nor printed there.
|
||||
*/
|
||||
export const CANVAS_NUMBER_KEYS = APPLE;
|
||||
|
||||
function mod(code: string, key: string): Shortcut {
|
||||
return { code, key, mod: true };
|
||||
}
|
||||
@@ -25,6 +33,10 @@ function modShift(code: string, key: string): Shortcut {
|
||||
return { code, key, mod: true, shift: true };
|
||||
}
|
||||
|
||||
function ctrl(code: string, key: string): Shortcut {
|
||||
return { code, key, ctrl: true };
|
||||
}
|
||||
|
||||
function shift(code: string, key: string): Shortcut {
|
||||
return { code, key, shift: true };
|
||||
}
|
||||
@@ -68,6 +80,12 @@ export const SHORTCUTS = {
|
||||
screens: plain("KeyS", "S"),
|
||||
compare: plain("KeyC", "C"),
|
||||
},
|
||||
/** The canvases by their place in the toolbar, as tabs are numbered elsewhere. Apple keyboards only (CANVAS_NUMBER_KEYS). */
|
||||
canvasByNumber: {
|
||||
map: ctrl("Digit1", "1"),
|
||||
screens: ctrl("Digit2", "2"),
|
||||
compare: ctrl("Digit3", "3"),
|
||||
},
|
||||
/** Compare only. The arrows walk changed screens; J and K walk the changed areas of one. */
|
||||
compare: {
|
||||
previousScreen: plain("ArrowLeft", "←"),
|
||||
@@ -92,10 +110,10 @@ export const SHORTCUTS = {
|
||||
/** The hint, in the idiom of the keyboard reading it: Apple's ⌥⇧⌘ order, or Ctrl+Alt+Shift. */
|
||||
export function formatShortcut(shortcut: Shortcut, apple = APPLE): string {
|
||||
if (apple) {
|
||||
return `${shortcut.alt ? "⌥" : ""}${shortcut.shift ? "⇧" : ""}${shortcut.mod ? "⌘" : ""}${shortcut.key}`;
|
||||
return `${shortcut.ctrl ? "⌃" : ""}${shortcut.alt ? "⌥" : ""}${shortcut.shift ? "⇧" : ""}${shortcut.mod ? "⌘" : ""}${shortcut.key}`;
|
||||
}
|
||||
const parts: string[] = [];
|
||||
if (shortcut.mod) parts.push("Ctrl");
|
||||
if (shortcut.mod || shortcut.ctrl) parts.push("Ctrl");
|
||||
if (shortcut.alt) parts.push("Alt");
|
||||
if (shortcut.shift) parts.push("Shift");
|
||||
parts.push(shortcut.key);
|
||||
@@ -104,7 +122,9 @@ export function formatShortcut(shortcut: Shortcut, apple = APPLE): string {
|
||||
|
||||
export function matchesShortcut(event: KeyboardEvent, shortcut: Shortcut): boolean {
|
||||
if (event.code !== shortcut.code) return false;
|
||||
if ((event.metaKey || event.ctrlKey) !== Boolean(shortcut.mod)) return false;
|
||||
if (shortcut.ctrl) {
|
||||
if (!event.ctrlKey || event.metaKey) return false;
|
||||
} else if ((event.metaKey || event.ctrlKey) !== Boolean(shortcut.mod)) return false;
|
||||
if (event.shiftKey !== Boolean(shortcut.shift)) return false;
|
||||
return event.altKey === Boolean(shortcut.alt);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user