Compare commits

...
Author SHA1 Message Date
Brent Vatne 906ee5e7a1 More menu: keep its keys from the canvas behind it, follow the bar, add an Inspector row, offer full screen only where it is allowed
←/→ on any row and Esc are the menu's own, so Compare neither steps its screen nor clears its
area; ? from the menu opens the shortcuts as the row does, so focus returns to More. An anchored
menu follows its trigger when it moves without a scroll or resize. Full screen also needs
document.fullscreenEnabled. A window too short for the menu scrolls it.
2026-10-19 08:53:04 -07:00
Brent Vatne fa970beac3 Inspector: widen only as far as leaves the bottom bar room beside it, so the bar and its More never hide
The cap, window width less the bar's measured width and a 12px gap either side (never below
320px), joins #34's min(800px, half the window) for drags, keys, the saved width and resizes;
the separator's aria-valuemax follows it.
2026-10-19 08:53:04 -07:00
Brent Vatne f4e58bd849 Merge remote-tracking branch 'origin/main' into @brent/bottom-bar-menu
# Conflicts:
#	viewer/src/components/canvas/toolbar.tsx
#	viewer/src/styles.css
2026-10-18 22:43:18 -07:00
Brent Vatne 650c5fae2f Viewer chrome: theme, full screen and keyboard shortcuts move into a "…" menu in the bottom bar; the top right keeps only the Map's camera
The bottom bar's keyboard button becomes More, a menu of uniform rows (icon, label, control, key): Theme with an Auto / Light / Dark switch (T), Full screen (F, a new key) where the browser has it, and Keyboard shortcuts (?). The top right loses the theme and full screen buttons on every canvas and the Inspector's panel toggle; the Inspector opens from a selection, Return or I.
2026-10-18 22:39:59 -07:00
devin-ai-integration[bot]andbrent b281c734f4 Viewer: make the Inspector resizable from its left edge (#34)
Co-authored-by: brent <[email protected]>
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-10-18 22:39:36 -07:00
Brent Vatne c99c26f9bb Release 0.20.0-next.0; prereleases publish under the next tag (#36) 2026-10-18 22:09:03 -07:00
25 changed files with 1425 additions and 344 deletions

No files matched your search

+7 -1
View File
@@ -61,7 +61,13 @@ jobs:
env:
# npm cannot generate provenance for a private repository.
NPM_CONFIG_PROVENANCE: "false"
run: npm publish --access public
VERSION: ${{ steps.version.outputs.version }}
shell: bash
# A prerelease (0.20.0-next.0) goes to the next tag, so latest keeps the last release.
run: |
set -euo pipefail
if [[ "$VERSION" == *-* ]]; then tag=next; else tag=latest; fi
npm publish --access public --tag "$tag"
- name: Tag the release
if: steps.version.outputs.publish == 'true'
env:
+1 -1
View File
@@ -580,7 +580,7 @@ npm test
- `npm test` rebuilds the CLI and the Viewer first, because the node tests run the compiled `dist/`. After one `npm run build`, `npm run test:node` skips the rebuild.
- The agent runtimes and `eas-cli` are optional dependencies that only capture needs. Do not install with `--omit=optional`, which also drops esbuild's platform package.
- To release, bump `version` in `package.json` and merge to main. The [publish workflow](.github/workflows/publish.yml) publishes any version npm does not have yet.
- To release, bump `version` in `package.json` and merge to main. The [publish workflow](.github/workflows/publish.yml) publishes any version npm does not have yet. A prerelease version such as `0.20.0-next.0` goes to the `next` tag, so `latest` stays on the last release.
```sh
npx playwright install chromium
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "@expo/explore",
"version": "0.19.8",
"version": "0.20.0-next.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@expo/explore",
"version": "0.19.8",
"version": "0.20.0-next.0",
"license": "MIT",
"dependencies": {
"@expo/repack-app": "0.10.1",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@expo/explore",
"version": "0.19.8",
"version": "0.20.0-next.0",
"description": "Source-driven mobile app maps, deterministic CI capture, and visual reviews",
"license": "MIT",
"type": "module",
+8
View File
@@ -242,6 +242,14 @@ test("Compare steps through changed screens and their changed areas", { timeout:
await expect(outlines.nth(1)).toHaveClass(/active/);
await page.keyboard.press("k");
await expect(outlines.nth(0)).toHaveClass(/active/);
// Esc in the bottom bar's More menu closes the menu and only the menu.
const more = page.getByRole("button", { name: "More", exact: true });
await more.click();
await expect(page.getByRole("menu", { name: "More" })).toBeVisible();
await page.keyboard.press("Escape");
await expect(page.getByRole("menu", { name: "More" })).toHaveCount(0);
await expect(more).toBeFocused();
await expect(outlines.nth(0)).toHaveClass(/active/);
await page.keyboard.press("Escape");
await expect(compare.locator(".visual-change-outline.active")).toHaveCount(0);
+266
View File
@@ -0,0 +1,266 @@
import { expect, test, type Page } from "@playwright/test";
const STORAGE_KEY = "expo-explore:inspector-width";
const panel = (page: Page) => page.getByRole("complementary", { name: "Inspector panel" });
const handle = (page: Page) => page.getByRole("separator", { name: "Resize inspector" });
const panelWidth = async (page: Page) => (await panel(page).boundingBox())!.width;
const storedWidth = (page: Page) => page.evaluate((key) => localStorage.getItem(key), STORAGE_KEY);
/** Drags the panel's edge `dx` pixels (negative is left, which widens the panel). */
async function dragEdge(page: Page, dx: number) {
const box = (await handle(page).boundingBox())!;
const x = box.x + box.width / 2;
const y = box.y + box.height / 2;
await page.mouse.move(x, y);
await page.mouse.down();
await page.mouse.move(x + dx / 2, y);
await page.mouse.move(x + dx, y);
await page.mouse.up();
}
test.describe("Inspector resize", () => {
test("dragging the edge resizes the Inspector, and the width is kept for the next visit", async ({ page }) => {
await page.goto("/map?screen=area-0-screen-1");
await expect(panel(page)).toBeVisible();
// The 1280px test window takes the wide default.
expect(await panelWidth(page)).toBe(400);
await expect(handle(page)).toHaveAttribute("aria-valuenow", "400");
await dragEdge(page, -150);
await expect.poll(() => panelWidth(page)).toBe(550);
await expect(handle(page)).toHaveAttribute("aria-valuenow", "550");
expect(await storedWidth(page)).toBe("550");
await page.reload();
await expect(panel(page)).toBeVisible();
await expect.poll(() => panelWidth(page)).toBe(550);
// Dragging back right narrows it, never below the minimum.
await dragEdge(page, 400);
await expect.poll(() => panelWidth(page)).toBe(320);
expect(await storedWidth(page)).toBe("320");
});
test("the width stops at half the window, and a double-click restores the default", async ({ page }) => {
await page.goto("/map?screen=area-0-screen-1");
await expect(panel(page)).toBeVisible();
await dragEdge(page, -600);
await expect.poll(() => panelWidth(page)).toBe(640);
await expect(handle(page)).toHaveAttribute("aria-valuemax", "640");
await expect(handle(page)).toHaveAttribute("aria-valuenow", "640");
// The canvas toolbar moves left, out from under the wide panel, instead of being covered.
const toolbar = page.getByRole("toolbar", { name: "Canvas tools" });
await expect(toolbar).toBeVisible();
await expect.poll(async () => {
const toolbarBox = (await toolbar.boundingBox())!;
const panelBox = (await panel(page).boundingBox())!;
return panelBox.x - (toolbarBox.x + toolbarBox.width);
}).toBeGreaterThanOrEqual(8);
await handle(page).dblclick();
await expect.poll(() => panelWidth(page)).toBe(400);
expect(await storedWidth(page)).toBeNull();
});
test("arrow keys move the edge a step; Home and End take it to its limits", async ({ page }) => {
await page.goto("/map?screen=area-0-screen-1");
await expect(panel(page)).toBeVisible();
await handle(page).focus();
await page.keyboard.press("ArrowLeft");
await expect.poll(() => panelWidth(page)).toBe(416);
await page.keyboard.press("ArrowLeft");
await expect.poll(() => panelWidth(page)).toBe(432);
await page.keyboard.press("ArrowRight");
await expect.poll(() => panelWidth(page)).toBe(416);
await page.keyboard.press("End");
await expect.poll(() => panelWidth(page)).toBe(640);
await page.keyboard.press("Home");
await expect.poll(() => panelWidth(page)).toBe(320);
// The arrows resized the panel; they did not step the selected screen.
expect(new URL(page.url()).searchParams.get("screen")).toBe("area-0-screen-1");
});
test("a saved width wider than half of a smaller window is held to half of it", async ({ page }) => {
await page.addInitScript((key) => localStorage.setItem(key, "760"), STORAGE_KEY);
await page.goto("/map?screen=area-0-screen-1");
await expect(panel(page)).toBeVisible();
expect(await panelWidth(page)).toBe(640);
await expect(handle(page)).toHaveAttribute("aria-valuenow", "640");
});
test("a drag that ends where it started leaves the default width in place", async ({ page }) => {
await page.goto("/map?screen=area-0-screen-1");
await expect(panel(page)).toBeVisible();
const box = (await handle(page).boundingBox())!;
const x = box.x + box.width / 2;
const y = box.y + box.height / 2;
await page.mouse.move(x, y);
await page.mouse.down();
await page.mouse.move(x - 100, y);
await expect.poll(() => panelWidth(page)).toBe(500);
await page.mouse.move(x, y);
await page.mouse.up();
await expect.poll(() => panelWidth(page)).toBe(400);
expect(await storedWidth(page)).toBeNull();
// Still the default: a narrower window takes the narrow default, not the 400 the drag passed through.
await page.setViewportSize({ width: 1100, height: 820 });
await expect.poll(() => panelWidth(page)).toBe(320);
});
test("a saved width below the minimum is held to it", async ({ page }) => {
await page.addInitScript((key) => localStorage.setItem(key, "40"), STORAGE_KEY);
await page.goto("/map?screen=area-0-screen-1");
await expect(panel(page)).toBeVisible();
expect(await panelWidth(page)).toBe(320);
await expect(handle(page)).toHaveAttribute("aria-valuenow", "320");
});
test.describe("in a window wider than two maximum panels", () => {
test.use({ viewport: { width: 1700, height: 900 } });
test("a saved width above the maximum is held to it", async ({ page }) => {
await page.addInitScript((key) => localStorage.setItem(key, "5000"), STORAGE_KEY);
await page.goto("/map?screen=area-0-screen-1");
await expect(panel(page)).toBeVisible();
// Half of this window is 850.
expect(await panelWidth(page)).toBe(800);
await expect(handle(page)).toHaveAttribute("aria-valuenow", "800");
});
});
test("a key that cannot move the edge keeps the saved width", async ({ page }) => {
await page.addInitScript((key) => localStorage.setItem(key, "760"), STORAGE_KEY);
await page.goto("/map?screen=area-0-screen-1");
await expect(panel(page)).toBeVisible();
expect(await panelWidth(page)).toBe(640);
await handle(page).focus();
await page.keyboard.press("End");
await page.keyboard.press("ArrowLeft");
expect(await storedWidth(page)).toBe("760");
await page.keyboard.press("ArrowRight");
await expect.poll(() => panelWidth(page)).toBe(624);
expect(await storedWidth(page)).toBe("624");
});
test("the separator's values follow the window", async ({ page }) => {
await page.goto("/map?screen=area-0-screen-1");
await expect(panel(page)).toBeVisible();
await handle(page).focus();
await page.keyboard.press("End");
await expect(handle(page)).toHaveAttribute("aria-valuenow", "640");
await page.setViewportSize({ width: 1000, height: 820 });
await expect.poll(() => panelWidth(page)).toBe(500);
await expect(handle(page)).toHaveAttribute("aria-valuemax", "500");
await expect(handle(page)).toHaveAttribute("aria-valuenow", "500");
// Back in the wide window the saved width returns.
await page.setViewportSize({ width: 1280, height: 820 });
await expect.poll(() => panelWidth(page)).toBe(640);
await expect(handle(page)).toHaveAttribute("aria-valuenow", "640");
});
test("closing the Inspector mid-drag ends the drag", async ({ page }) => {
await page.goto("/map?screen=area-0-screen-1");
await expect(panel(page)).toBeVisible();
const box = (await handle(page).boundingBox())!;
const x = box.x + box.width / 2;
const y = box.y + box.height / 2;
await page.mouse.move(x, y);
await page.mouse.down();
await page.mouse.move(x - 100, y);
await expect(page.locator("html")).toHaveClass(/inspector-resizing/);
await page.keyboard.press("i");
await expect(panel(page)).toHaveCount(0);
await page.mouse.up();
await expect(page.locator("html")).not.toHaveClass(/inspector-resizing/);
// The width the drag reached is kept.
await page.keyboard.press("i");
await expect.poll(() => panelWidth(page)).toBe(500);
});
test.describe("in a window too narrow for the toolbar beside a half-window Inspector", () => {
test.use({ viewport: { width: 820, height: 800 } });
/** The widest the panel may be here: the window less the bottom bar and a 12px gap either side. */
async function widestBesideToolbar(page: Page) {
const toolbarBox = (await page.getByRole("toolbar", { name: "Canvas tools" }).boundingBox())!;
return Math.floor(820 - (toolbarBox.width + 2 * 12));
}
async function expectToolbarBesidePanel(page: Page) {
const toolbar = page.getByRole("toolbar", { name: "Canvas tools" });
await expect(toolbar).toBeVisible();
await expect(toolbar.getByRole("button", { name: "More", exact: true })).toBeVisible();
const toolbarBox = (await toolbar.boundingBox())!;
const panelBox = (await panel(page).boundingBox())!;
expect(toolbarBox.x).toBeGreaterThanOrEqual(12 - 1);
expect(toolbarBox.x + toolbarBox.width + 12).toBeLessThanOrEqual(panelBox.x + 1);
}
test("End stops the Inspector where the toolbar still fits beside it, with More in reach", async ({ page }) => {
await page.goto("/map?screen=area-0-screen-1");
await expect(panel(page)).toBeVisible();
const widest = await widestBesideToolbar(page);
// Half the window would be 410; the toolbar needs more of the canvas than that leaves.
expect(widest).toBeLessThan(410);
expect(widest).toBeGreaterThan(320);
await expect(handle(page)).toHaveAttribute("aria-valuemax", String(widest));
await handle(page).focus();
await page.keyboard.press("End");
await expect.poll(() => panelWidth(page)).toBe(widest);
await expect(handle(page)).toHaveAttribute("aria-valuenow", String(widest));
await page.keyboard.press("ArrowLeft");
await expect.poll(() => panelWidth(page)).toBe(widest);
await expectToolbarBesidePanel(page);
// Narrowed again, the toolbar keeps its gap to the panel.
await page.keyboard.press("Home");
await expect.poll(() => panelWidth(page)).toBe(320);
await expectToolbarBesidePanel(page);
});
test("a drag or a saved width stops there too", async ({ page }) => {
await page.goto("/map?screen=area-0-screen-1");
await expect(panel(page)).toBeVisible();
const widest = await widestBesideToolbar(page);
await dragEdge(page, -300);
await expect.poll(() => panelWidth(page)).toBe(widest);
expect(await storedWidth(page)).toBe(String(widest));
await expectToolbarBesidePanel(page);
await page.evaluate((key) => localStorage.setItem(key, "800"), STORAGE_KEY);
await page.reload();
await expect(panel(page)).toBeVisible();
await expect.poll(() => panelWidth(page)).toBe(widest);
await expectToolbarBesidePanel(page);
// A wider window gives the saved width more room again.
await page.setViewportSize({ width: 1280, height: 800 });
await expect.poll(() => panelWidth(page)).toBe(640);
});
});
test.describe("in a narrow window", () => {
test.use({ viewport: { width: 1180, height: 820 } });
test("the Inspector starts at its narrow default, and a saved width is held to half the window", async ({ page }) => {
await page.goto("/map?screen=area-0-screen-1");
await expect(panel(page)).toBeVisible();
expect(await panelWidth(page)).toBe(320);
await expect(handle(page)).toHaveAttribute("aria-valuenow", "320");
await page.evaluate((key) => localStorage.setItem(key, "760"), STORAGE_KEY);
await page.reload();
await expect(panel(page)).toBeVisible();
expect(await panelWidth(page)).toBe(590);
await expect(handle(page)).toHaveAttribute("aria-valuenow", "590");
});
});
test.describe("on a phone", () => {
test.use({ viewport: { width: 390, height: 844 }, hasTouch: true, isMobile: true });
test("the Inspector sheet has no resize edge", async ({ page }) => {
await page.goto("/map?screen=area-0-screen-1");
await expect(panel(page)).toBeVisible();
await expect(handle(page)).toHaveCount(0);
});
});
});
+414 -127
View File
@@ -197,15 +197,20 @@ async function expectMapSelectionRing(page: Page) {
await page.mouse.move(1, 1);
}
/** The camera chrome's theme button steps Auto → Dark → Light; press it until the page shows the option. */
/** Picks a theme in the bottom bar's More menu, then closes the menu. */
async function chooseTheme(page: Page, option: "light" | "dark") {
const root = page.locator("html");
for (let presses = 0; presses < 3; presses += 1) {
if (await root.getAttribute("data-theme") === option) return;
await page.getByRole("button", { name: "Toggle theme" }).click();
await page.waitForTimeout(50);
}
await expect(root).toHaveAttribute("data-theme", option);
await page.getByRole("button", { name: "More", exact: true }).click();
const menu = page.getByRole("menu", { name: "More" });
await menu.getByRole("menuitemradio", { name: option === "light" ? "Light" : "Dark", exact: true }).click();
await page.keyboard.press("Escape");
await expect(menu).toHaveCount(0);
await expect(page.locator("html")).toHaveAttribute("data-theme", option);
}
/** There is no button to bring the Inspector back; a selection, Return or I opens it. */
async function openInspector(page: Page) {
await page.keyboard.press("i");
await expect(page.locator(".right-panel")).toBeVisible();
}
/** Bottom toolbar → persistent canvas view control. */
@@ -1668,7 +1673,7 @@ test("collapses the Inspector when a screen is cleared but still allows an empty
await expect.poll(() => new URL(page.url()).searchParams.has("screen")).toBe(false);
await expect(page.locator(".right-panel")).toHaveCount(0);
await page.getByRole("button", { name: "Expand inspector" }).click();
await openInspector(page);
await expect(page.locator(".right-panel")).toBeVisible();
await expect.poll(() => new URL(page.url()).searchParams.has("screen")).toBe(false);
});
@@ -1854,13 +1859,12 @@ test("keeps persistent canvas chrome out of the sliding canvas snapshot", async
await page.setViewportSize({ width: 1600, height: 900 });
await page.goto("/map");
await expect(page.locator(".canvas-minimap-shell")).toBeVisible();
await expect(page.locator(".right-float")).toBeVisible();
await expect(page.locator(".app-content > .canvas-camera-controls")).toBeVisible();
const transitionNames = await page.locator([
".canvas-minimap-shell",
".app-content > .canvas-camera-controls",
".canvas-toolbar",
".right-float",
].join(",")).evaluateAll((elements) => elements.map((element) => ({
className: element.className,
viewTransitionName: getComputedStyle(element).viewTransitionName,
@@ -1869,7 +1873,6 @@ test("keeps persistent canvas chrome out of the sliding canvas snapshot", async
expect.objectContaining({ viewTransitionName: "canvas-minimap" }),
expect.objectContaining({ viewTransitionName: "canvas-camera-controls" }),
expect.objectContaining({ viewTransitionName: "canvas-toolbar" }),
expect.objectContaining({ viewTransitionName: "right-floating-controls" }),
]));
const animations = await captureCanvasViewAnimations(page, "Screens");
@@ -1890,7 +1893,6 @@ test("keeps persistent canvas chrome out of the sliding canvas snapshot", async
const movingPersistentChrome = animations.filter((animation) => (
animation.pseudoElement?.includes("(canvas-camera-controls)")
|| animation.pseudoElement?.includes("(canvas-toolbar)")
|| animation.pseudoElement?.includes("(right-floating-controls)")
));
expect(movingPersistentChrome).toEqual([]);
});
@@ -1916,7 +1918,7 @@ test("centres selected screens after panel changes and makes the primary Fit sel
await expectSelectedScreenCentered(page);
await expectPanelFitMatchesPrimaryFit(page, canvas);
await page.getByRole("button", { name: "Expand inspector" }).click();
await openInspector(page);
await expect(page.locator(".right-panel")).toBeVisible();
await expectSelectedScreenCentered(page);
await expectPanelFitMatchesPrimaryFit(page, canvas);
@@ -2255,7 +2257,7 @@ test("keeps current Map and Screens projections overlap-free without deleting sc
await expect(page).toHaveURL(/\/screens/);
await expect(page.locator(".screens-page .screens-cell")).toHaveCount(SCREEN_COUNT);
await expect.poll(() => overlapCount(".screens-page .screens-cell")).toBe(0);
await page.getByRole("button", { name: "Expand inspector" }).click();
await openInspector(page);
await expect(page.locator(".right-panel")).toBeVisible();
await expect.poll(() => overlapCount(".screens-page .screens-cell")).toBe(0);
});
@@ -2337,7 +2339,7 @@ test("shows the minimap on the Map without a visibility preference", async ({ pa
test("keeps minimap and canvas chrome inside the responsive visible frame", async ({ page }) => {
await page.setViewportSize({ width: 900, height: 820 });
await page.goto("/map");
await page.getByRole("button", { name: "Expand inspector" }).click();
await openInspector(page);
const minimap = page.getByTestId("canvas-minimap");
const toolbar = page.getByRole("toolbar", { name: "Canvas tools" });
@@ -2360,9 +2362,9 @@ test("keeps minimap and canvas chrome inside the responsive visible frame", asyn
for (const box of [minimapBox!, cameraBox!]) {
expect(box.x + box.width).toBeLessThanOrEqual(inspectorBox!.x + 1);
}
expect(Math.abs(
toolbarBox!.x + toolbarBox!.width / 2 - page.viewportSize()!.width / 2,
)).toBeLessThanOrEqual(1);
// The toolbar keeps the window's centre unless the Inspector would cover it; this 320px overlay
// would, so it clears the panel's edge by 12px instead.
expect(toolbarBox!.x + toolbarBox!.width + 12).toBeCloseTo(inspectorBox!.x, 0);
expect(minimapBox!.y + minimapBox!.height + 11).toBeLessThanOrEqual(toolbarBox!.y);
expect(minimapBox!.width).toBeCloseTo(168, 0);
expect(minimapBox!.height).toBeCloseTo(112, 0);
@@ -2377,6 +2379,7 @@ test("keeps minimap and canvas chrome inside the responsive visible frame", asyn
const cameraBeforeTheme = await viewport.getAttribute("style");
const maskBeforePanel = await minimap.locator(".canvas-minimap-visible-mask path").getAttribute("d");
const lightBackground = await minimap.evaluate((element) => getComputedStyle(element).backgroundColor);
// The bar has moved clear of the Inspector, so its More menu is in reach.
await chooseTheme(page, "dark");
await expect(page.locator("html")).toHaveAttribute("data-theme", "dark");
await expect(viewport).toHaveAttribute("style", cameraBeforeTheme!);
@@ -2490,7 +2493,9 @@ test("animates panel Fits once in both directions", async ({ page }) => {
}).__panelFitCameraObserver = observer;
});
await page.getByRole("button", { name: buttonName, exact: true }).click();
// Closed, the Inspector has no button: I opens it.
if (buttonName === "Expand inspector") await page.keyboard.press("i");
else await page.getByRole("button", { name: buttonName, exact: true }).click();
await expectLayout();
await page.waitForTimeout(520);
const samples = await page.evaluate(() => {
@@ -2624,7 +2629,9 @@ test("refits every unselected canvas when the Inspector opens or closes", async
host.__overviewPanelCamera = { values, observer };
}, canvas);
await page.getByRole("button", { name: buttonName, exact: true }).click();
// Closed, the Inspector has no button: I opens it.
if (buttonName === "Expand inspector") await page.keyboard.press("i");
else await page.getByRole("button", { name: buttonName, exact: true }).click();
if (buttonName === "Expand inspector") {
await expect(page.locator(".right-panel")).toBeVisible();
} else {
@@ -2716,7 +2723,7 @@ test("starts the opening Inspector Fit immediately and settles in one flight", a
.__inspectorPaintSamples = samples;
});
await page.getByRole("button", { name: "Expand inspector" }).click();
await openInspector(page);
await expect(page.locator(".right-panel")).toBeVisible();
await page.waitForTimeout(600);
const samples = await page.evaluate(() => (
@@ -2758,47 +2765,41 @@ test("starts the opening Inspector Fit immediately and settles in one flight", a
expect(moving[0]!.elapsed - visible[0]!.elapsed).toBeLessThan(80);
});
test("aligns the pill, camera controls, and collapsed Inspector chrome on one center line", async ({ page }) => {
test("aligns the pill and the Map's camera controls on one center line, mirrored at the edges", async ({ page }) => {
await page.goto("/map?screen=settings-root");
await page.getByRole("button", { name: "Close inspector" }).click();
const pill = page.locator(".left-panel-collapsed-pill");
const camera = page.getByRole("group", { name: "Canvas camera controls" });
const inspector = page.locator(".right-float");
const share = camera.getByRole("button", { name: "Toggle theme", exact: true });
const fit = camera.getByRole("button", { name: "Fit canvas", exact: true });
await expect(pill).toBeVisible();
await expect(camera).toBeVisible();
await expect(inspector).toBeVisible();
// The closed Inspector leaves nothing behind in the top right.
await expect(page.getByRole("button", { name: "Expand inspector" })).toHaveCount(0);
const [pillBox, cameraBox, inspectorBox, shareBox] = await Promise.all([
const [pillBox, cameraBox, fitBox] = await Promise.all([
pill.boundingBox(),
camera.boundingBox(),
inspector.boundingBox(),
share.boundingBox(),
fit.boundingBox(),
]);
expect(pillBox).not.toBeNull();
expect(cameraBox).not.toBeNull();
expect(inspectorBox).not.toBeNull();
expect(shareBox).not.toBeNull();
expect(fitBox).not.toBeNull();
expect(Math.abs(pillBox!.y - 14)).toBeLessThanOrEqual(1);
expect(Math.abs(pillBox!.height - 42)).toBeLessThanOrEqual(1);
expect(Math.abs(cameraBox!.y - 14)).toBeLessThanOrEqual(1);
expect(Math.abs(cameraBox!.height - 42)).toBeLessThanOrEqual(1);
expect(Math.abs(inspectorBox!.y - 14)).toBeLessThanOrEqual(1);
expect(Math.abs(inspectorBox!.height - 42)).toBeLessThanOrEqual(1);
expect(Math.abs(shareBox!.height - 32)).toBeLessThanOrEqual(1);
const centerLine = cameraBox!.y + cameraBox!.height / 2;
for (const box of [pillBox!, inspectorBox!]) {
expect(Math.abs(box.y + box.height / 2 - centerLine)).toBeLessThanOrEqual(1);
}
expect(Math.abs(fitBox!.height - 32)).toBeLessThanOrEqual(1);
expect(Math.abs(pillBox!.y + pillBox!.height / 2 - (cameraBox!.y + cameraBox!.height / 2))).toBeLessThanOrEqual(1);
// The controls sit as far from the right edge as the pill does from the left.
expect(Math.abs(page.viewportSize()!.width - (cameraBox!.x + cameraBox!.width) - pillBox!.x)).toBeLessThanOrEqual(1);
});
test("floats the pill over the canvas and remembers the Inspector across a reload", async ({ page }) => {
await page.goto("/map");
await expect(page.locator(".right-panel")).toHaveCount(0);
await page.getByRole("button", { name: "Expand inspector" }).click();
await openInspector(page);
// The pill and the Inspector share one panel surface.
const expandedPanelBackground = await page.locator(".left-panel-collapsed-pill").evaluate(
(element) => getComputedStyle(element).backgroundColor,
@@ -2833,31 +2834,20 @@ test("floats the pill over the canvas and remembers the Inspector across a reloa
await page.getByRole("button", { name: "Close inspector" }).click();
await expect(page.locator(".right-panel")).toHaveCount(0);
const canvasActions = page.getByRole("toolbar", { name: "Canvas actions" });
const cameraControls = page.getByRole("group", { name: "Canvas camera controls" });
const canvasToolbar = page.getByRole("toolbar", { name: "Canvas tools" });
const minimap = page.getByTestId("canvas-minimap");
await expect(canvasActions).toBeVisible();
// Closed, the Inspector leaves no toolbar of its own; the camera controls stay one floating group.
await expect(page.getByRole("toolbar", { name: "Canvas actions" })).toHaveCount(0);
await expect(cameraControls).toBeVisible();
await expect(canvasToolbar).toBeVisible();
await expect(minimap).toBeVisible();
await expect(canvasActions).toHaveCSS("background-color", expandedPanelBackground);
await expect(cameraControls).toHaveCSS("background-color", expandedPanelBackground);
await expect(canvasActions).toHaveCSS("border-top-width", "0px");
await expect(cameraControls).toHaveCSS("border-top-width", "0px");
await expect(cameraControls.locator(".camera-control-divider").first()).toBeHidden();
const [actionsBox, cameraBox] = await Promise.all([
canvasActions.boundingBox(),
cameraControls.boundingBox(),
]);
expect(actionsBox).not.toBeNull();
expect(cameraBox).not.toBeNull();
const toolbarJoin = actionsBox!.x - (cameraBox!.x + cameraBox!.width);
expect(toolbarJoin).toBeGreaterThanOrEqual(-1.5);
expect(toolbarJoin).toBeLessThanOrEqual(0.5);
await expect(cameraControls).toHaveCSS("border-top-width", "1px");
await expect(cameraControls.locator(".camera-control-divider").first()).toBeVisible();
const [leftShadow, rightShadow, toolbarShadow, toolbarBox, minimapBox] = await Promise.all([
page.locator(".left-panel-collapsed-pill").evaluate((element) => getComputedStyle(element).boxShadow),
cameraControls.evaluate((element) => getComputedStyle(element, "::before").boxShadow),
cameraControls.evaluate((element) => getComputedStyle(element).boxShadow),
canvasToolbar.evaluate((element) => getComputedStyle(element).boxShadow),
canvasToolbar.boundingBox(),
minimap.boundingBox(),
@@ -2874,7 +2864,7 @@ test("floats the pill over the canvas and remembers the Inspector across a reloa
await page.reload();
await expect(page.locator(".left-panel.collapsed")).toBeVisible();
await expect(page.locator(".right-panel")).toHaveCount(0);
await page.getByRole("button", { name: "Expand inspector" }).click();
await openInspector(page);
await expect(page.locator(".right-panel")).toBeVisible();
});
@@ -2910,20 +2900,24 @@ test("keeps stateful shell control geometry stable across visual state changes",
expect(Math.abs(pillAlignment.logo - pillAlignment.pill)).toBeLessThanOrEqual(1);
expect(Math.abs(pillAlignment.name - pillAlignment.pill)).toBeLessThanOrEqual(1);
const rightClosed = await geometry(page.getByRole("button", { name: "Expand inspector" }));
await expect(page.getByRole("button", { name: "Expand inspector" })
.locator("svg.lucide-panel-right")).toHaveCount(1);
await page.getByRole("button", { name: "Expand inspector" }).click();
const rightOpen = await geometry(page.getByRole("button", { name: "Close inspector" }));
// Open, the same button shows an X that closes the Inspector.
// Closed, the Inspector has no button; open, an X closes it.
await expect(page.getByRole("button", { name: "Expand inspector" })).toHaveCount(0);
await openInspector(page);
await expect(page.getByRole("button", { name: "Close inspector" })
.locator("svg.lucide-x")).toHaveCount(1);
expect(rightOpen).toEqual(rightClosed);
const themeButton = page.getByRole("button", { name: "Toggle theme" });
const lightTheme = await geometry(themeButton);
await themeButton.click();
const darkTheme = await geometry(themeButton);
// The More button keeps its size whether its menu is open or not, and the theme switch keeps
// its size whichever theme is checked.
const more = page.getByRole("button", { name: "More", exact: true });
const moreClosed = await geometry(more);
await more.click();
const moreOpen = await geometry(more);
expect(moreOpen).toEqual(moreClosed);
const themes = page.getByRole("menu", { name: "More" }).getByRole("group", { name: "Theme" });
const lightTheme = await geometry(themes);
await themes.getByRole("menuitemradio", { name: "Dark", exact: true }).click();
await expect(page.locator("html")).toHaveAttribute("data-theme", "dark");
const darkTheme = await geometry(themes);
expect(darkTheme).toEqual(lightTheme);
});
@@ -2936,7 +2930,7 @@ test("migrates the legacy shared panel preference once into the Inspector prefer
right: localStorage.getItem("expo-explore:right-panel-collapsed"),
}))).toEqual({ legacy: null, right: "true" });
await page.getByRole("button", { name: "Expand inspector" }).click();
await openInspector(page);
await expect(page.locator(".right-panel")).toBeVisible();
});
@@ -3010,14 +3004,18 @@ test("drives the shell from the keyboard, and says so on hover", async ({ page }
// Every remaining shortcut is discoverable: the tooltip prints the key next to the label.
await compareButton.hover();
await expect(page.locator(".tooltip-key")).toHaveText("C");
await page.getByRole("button", { name: "Expand inspector" }).hover();
await expect(page.locator(".tooltip-key")).toHaveText("I");
// The theme button names the mode in force, and T is its key.
const themeButton = page.getByRole("button", { name: "Toggle theme" });
await themeButton.hover();
await expect(page.locator(".tooltip-content")).toContainText("Theme: Auto");
await expect(page.locator(".tooltip-key")).toHaveText("T");
await page.mouse.move(0, 0);
// The More menu's theme row checks the mode in force, and prints T as its key.
const themeChoice = async () => {
await page.getByRole("button", { name: "More", exact: true }).click();
const menu = page.getByRole("menu", { name: "More" });
await expect(menu.getByRole("group", { name: "Theme" }).locator("kbd")).toHaveText("T");
const checked = await menu.getByRole("menuitemradio", { checked: true }).getAttribute("aria-label");
await page.keyboard.press("Escape");
await expect(menu).toHaveCount(0);
return checked;
};
expect(await themeChoice()).toBe("Auto");
const initialTheme = await page.locator("html").getAttribute("data-theme");
expect(initialTheme === "light" || initialTheme === "dark").toBe(true);
const otherTheme = initialTheme === "dark" ? "light" : "dark";
@@ -3026,9 +3024,7 @@ test("drives the shell from the keyboard, and says so on hover", async ({ page }
await expect(page.locator("html")).toHaveAttribute("data-theme", otherTheme);
await page.keyboard.press("t");
await expect(page.locator("html")).toHaveAttribute("data-theme", initialTheme!);
await themeButton.hover();
await expect(page.locator(".tooltip-content")).toContainText(initialTheme === "dark" ? "Theme: Dark" : "Theme: Light");
await page.mouse.move(0, 0);
expect(await themeChoice()).toBe(initialTheme === "dark" ? "Dark" : "Light");
// The retired theme and inspector chords no longer answer.
await page.keyboard.press(`${mod}+Alt+t`);
await expect(page.locator("html")).toHaveAttribute("data-theme", initialTheme!);
@@ -3081,7 +3077,7 @@ test("keeps fixed objects and canvas pan after a reload", async ({ page }) => {
test("delays the first tooltip, then shows subsequent tooltips instantly", async ({ page }) => {
await page.goto("/map");
const menu = page.locator(".left-panel-collapsed-pill").getByRole("button", { name: "Map", exact: true });
const changes = page.getByRole("button", { name: "Expand inspector" });
const changes = page.getByRole("button", { name: "Fit canvas", exact: true });
const tooltip = page.locator(".tooltip");
await menu.hover();
@@ -3091,7 +3087,7 @@ test("delays the first tooltip, then shows subsequent tooltips instantly", async
await expect(tooltip).not.toHaveAttribute("data-instant", "");
await changes.hover();
await expect(tooltip).toContainText("Expand inspector", { timeout: 150 });
await expect(tooltip).toContainText("Fit canvas", { timeout: 150 });
await expect(tooltip).toHaveAttribute("data-instant", "");
await expect(tooltip).toHaveCSS("animation-name", "none");
@@ -3100,7 +3096,7 @@ test("delays the first tooltip, then shows subsequent tooltips instantly", async
await changes.hover();
await page.waitForTimeout(150);
await expect(tooltip).toHaveCount(0);
await expect(tooltip).toContainText("Expand inspector");
await expect(tooltip).toContainText("Fit canvas");
await expect(tooltip).not.toHaveAttribute("data-instant", "");
});
@@ -3129,9 +3125,10 @@ test("follows system theme and polls lightweight status instead of the full map"
await chooseTheme(page, "light");
await expect(page.locator("html")).toHaveAttribute("data-theme", "light");
expect(await page.evaluate(() => localStorage.getItem("expo-explore:theme"))).toBe("light");
// The button shows the mode in force (Light), not the next one.
await expect(page.getByRole("button", { name: "Toggle theme" })
.locator("svg.lucide-sun")).toBeVisible();
// The More menu checks the mode in force.
await page.getByRole("button", { name: "More", exact: true }).click();
await expect(page.getByRole("menuitemradio", { name: "Light", exact: true })).toHaveAttribute("aria-checked", "true");
await page.keyboard.press("Escape");
await page.waitForTimeout(5_500);
expect(mapRequests).toBe(1);
@@ -3154,7 +3151,7 @@ test("zooms Map inspection up to 25600% without exceeding the ceiling", async ({
test.setTimeout(30_000);
await page.goto("/map");
await expect(page.locator(".map-canvas.canvas-projection-animating")).toHaveCount(0);
await expect(page.locator(".right-float")).toBeVisible();
await expect(page.getByRole("group", { name: "Canvas camera controls" })).toBeVisible();
await page.keyboard.press("Shift+0");
await expect(page.getByRole("button", { name: "Zoom — 100%" })).toBeVisible();
@@ -3175,10 +3172,11 @@ test("zooms Map inspection up to 25600% without exceeding the ceiling", async ({
await expect(zoom).toBeVisible();
expect(scaleFromTransform(await viewport.getAttribute("style"))).toBe(256);
const zoomBox = await zoom.boundingBox();
const shareBox = await page.locator(".right-float").boundingBox();
const cameraBox = await page.getByRole("group", { name: "Canvas camera controls" }).boundingBox();
expect(zoomBox).not.toBeNull();
expect(shareBox).not.toBeNull();
expect(zoomBox!.x + zoomBox!.width).toBeLessThanOrEqual(shareBox!.x);
expect(cameraBox).not.toBeNull();
expect(zoomBox!.x + zoomBox!.width).toBeLessThanOrEqual(cameraBox!.x + cameraBox!.width);
expect(cameraBox!.x + cameraBox!.width).toBeLessThanOrEqual(page.viewportSize()!.width);
await page.keyboard.press("Shift+0");
await expect(page.getByRole("button", { name: "Zoom — 100%" })).toBeVisible();
@@ -3482,15 +3480,13 @@ test("restores the fitted camera after internal navigation on the Map", async ({
});
});
test("keeps theme and full screen in the persistent canvas controls, not the inspector header", async ({ page }) => {
test("the Map's top right holds only fit, center and zoom; theme and full screen are not in the inspector header", async ({ page }) => {
await page.goto("/map");
// Collapsed inspector: the camera controls and the panel toggle form one toolbar.
// Closed, the Inspector leaves no toggle behind: the camera controls are all there is.
const collapsedCamera = page.getByRole("group", { name: "Canvas camera controls" });
await expect(collapsedCamera.getByRole("button", { name: "Toggle theme", exact: true })).toBeVisible();
await expect(collapsedCamera.getByRole("button", { name: "Enter full screen", exact: true })).toBeVisible();
await expect(page.locator(".right-float button")).toHaveCount(1);
await expect(page.locator(".right-float button")).toHaveAccessibleName("Expand inspector");
await page.getByRole("button", { name: "Expand inspector" }).click();
await expect(collapsedCamera.getByRole("button")).toHaveCount(3);
await expect(page.getByRole("button", { name: "Expand inspector" })).toHaveCount(0);
await openInspector(page);
await expect(page.getByRole("button", { name: /Share/ })).toHaveCount(0);
await expect(page.locator(".right-head button")).toHaveCount(1);
await expect(page.locator(".right-head button")).toHaveAccessibleName("Close inspector");
@@ -3508,18 +3504,19 @@ test("keeps theme and full screen in the persistent canvas controls, not the ins
await expect(cameraControls).toBeVisible();
await expect(cameraControls).not.toHaveCSS("background-color", "rgba(0, 0, 0, 0)");
await expect(cameraControls).toHaveCSS("border-top-width", "1px");
await expect(cameraControls.locator(".camera-control-divider")).toHaveCount(3);
await expect(cameraControls.locator(".camera-control-divider")).toHaveCount(1);
const cameraButtons = cameraControls.getByRole("button");
await expect(cameraButtons).toHaveCount(5);
await expect(cameraButtons.nth(3)).toHaveAccessibleName("Toggle theme");
await expect(cameraButtons.nth(4)).toHaveAccessibleName("Enter full screen");
await expect(cameraButtons).toHaveCount(3);
await expect(cameraButtons.nth(0)).toHaveAccessibleName("Fit canvas");
await expect(cameraButtons.nth(1)).toHaveAccessibleName("Center canvas");
await expect(cameraButtons.nth(2)).toHaveAccessibleName(/^Zoom — /);
await expect(page.getByRole("button", { name: /Toggle theme|full screen/ })).toHaveCount(0);
for (const button of await cameraButtons.all()) {
await expect(button).toHaveCSS("border-top-width", "0px");
await expect(button).toHaveCSS("background-color", "rgba(0, 0, 0, 0)");
}
await expect(page.locator(".app-content > .canvas-camera-controls")).toHaveCount(1);
await expect(page.locator(".right-panel .canvas-camera-controls, .right-float .canvas-camera-controls"))
.toHaveCount(0);
await expect(page.locator(".right-panel .canvas-camera-controls")).toHaveCount(0);
const zoomButton = cameraControls.getByRole("button", { name: /^Zoom — / });
await expect(zoomButton).toBeVisible();
await expect(zoomButton.locator("svg")).toHaveCount(0);
@@ -3573,11 +3570,10 @@ test("keeps theme and full screen in the persistent canvas controls, not the ins
await expect.poll(async () => scaleFromTransform(await viewport.getAttribute("style")))
.toBeCloseTo(pannedScale, 6);
// The theme toggle changes the page theme without changing the route.
// The theme changes the page theme without changing the route.
const canonical = page.url();
const themeBefore = await page.locator("html").getAttribute("data-theme");
await cameraControls.getByRole("button", { name: "Toggle theme", exact: true }).click();
await expect(page.locator("html")).not.toHaveAttribute("data-theme", themeBefore!);
await chooseTheme(page, themeBefore === "dark" ? "light" : "dark");
await expect(page).toHaveURL(canonical);
await expect(page.getByRole("dialog")).toHaveCount(0);
@@ -4089,10 +4085,10 @@ test("reload max-fits the comparison overview with the Inspector collapsed", asy
await page.setViewportSize({ width: 1600, height: 900 });
await page.goto("/map");
await expect(page.locator(".react-flow__node-screen")).toHaveCount(SCREEN_COUNT);
await expect(page.getByRole("button", { name: "Expand inspector" })).toBeVisible();
await expect(page.locator(".right-panel")).toHaveCount(0);
await page.reload();
await expect(page.locator(".react-flow__node-screen")).toHaveCount(SCREEN_COUNT);
await expect(page.getByRole("button", { name: "Expand inspector" })).toBeVisible();
await expect(page.locator(".right-panel")).toHaveCount(0);
const viewport = page.locator(".map-canvas .react-flow__viewport");
await expect(viewport).toBeVisible();
@@ -4686,10 +4682,10 @@ test.describe("phone layout", () => {
await page.goto("/map");
const tabs = page.getByRole("navigation", { name: "Views" });
await expect(tabs).toBeVisible();
// Desktop chrome is gone: the floating toolbar with its shortcuts button, the camera controls
// and the minimap.
// Desktop chrome is gone: the floating toolbar with its More menu, the camera controls and the
// minimap.
await expect(page.getByRole("toolbar", { name: "Canvas tools" })).toHaveCount(0);
await expect(page.getByRole("button", { name: "Keyboard shortcuts" })).toHaveCount(0);
await expect(page.getByRole("button", { name: "More", exact: true })).toHaveCount(0);
await expect(page.locator(".canvas-camera-controls")).toHaveCount(0);
await expect(tabs.getByRole("button", { name: /Compare/ })).toBeEnabled();
@@ -5204,40 +5200,312 @@ test.describe("phone layout", () => {
});
});
test("the theme is Auto until the toggle picks one: it follows the system, then steps Dark → Light → Auto and keeps the pick", async ({ page }) => {
test("the theme is Auto until the More menu picks one: it follows the system, and a pick outlives a reload", async ({ page }) => {
await page.emulateMedia({ colorScheme: "dark" });
await page.goto("/map");
const html = page.locator("html");
const button = page.getByRole("button", { name: "Toggle theme" });
const more = page.getByRole("button", { name: "More", exact: true });
const menu = page.getByRole("menu", { name: "More" });
const theme = (name: "Auto" | "Light" | "Dark") => menu.getByRole("menuitemradio", { name, exact: true });
await expect(html).toHaveAttribute("data-theme", "dark");
await expect(button).toHaveAttribute("data-theme-preference", "system");
await button.hover();
await expect(page.locator(".tooltip-content")).toContainText("Theme: Auto (system)");
await more.click();
await expect(theme("Auto")).toHaveAttribute("aria-checked", "true");
// Auto tracks the system while it is in force.
await page.emulateMedia({ colorScheme: "light" });
await expect(html).toHaveAttribute("data-theme", "light");
await button.click();
// A pick applies at once and keeps the menu open, so the switch shows it.
await theme("Dark").click();
await expect(html).toHaveAttribute("data-theme", "dark");
await expect(button).toHaveAttribute("data-theme-preference", "dark");
await expect(page.locator(".tooltip-content")).toContainText("Theme: Dark");
await button.click();
await expect(theme("Dark")).toHaveAttribute("aria-checked", "true");
await expect(theme("Auto")).toHaveAttribute("aria-checked", "false");
await theme("Light").click();
await expect(html).toHaveAttribute("data-theme", "light");
await expect(button).toHaveAttribute("data-theme-preference", "light");
await button.click();
await expect(button).toHaveAttribute("data-theme-preference", "system");
await theme("Auto").click();
await expect(theme("Auto")).toHaveAttribute("aria-checked", "true");
await expect(html).toHaveAttribute("data-theme", "light");
await page.emulateMedia({ colorScheme: "dark" });
await expect(html).toHaveAttribute("data-theme", "dark");
// A picked theme outlives a reload and ignores the system.
await button.click();
await expect(button).toHaveAttribute("data-theme-preference", "dark");
await button.click();
await expect(button).toHaveAttribute("data-theme-preference", "light");
await theme("Light").click();
await page.keyboard.press("Escape");
await page.reload();
await expect(html).toHaveAttribute("data-theme", "light");
await expect(page.getByRole("button", { name: "Toggle theme" })).toHaveAttribute("data-theme-preference", "light");
await page.getByRole("button", { name: "More", exact: true }).click();
await expect(theme("Light")).toHaveAttribute("aria-checked", "true");
});
/** Stands in for the browser's full screen, which headless Chromium cannot enter, and records the calls. */
async function stubFullscreen(page: Page) {
await page.addInitScript(() => {
const host = window as typeof window & { __fullscreenCalls: string[] };
host.__fullscreenCalls = [];
let element: Element | null = null;
Object.defineProperty(Document.prototype, "fullscreenElement", { configurable: true, get: () => element });
Element.prototype.requestFullscreen = function requestFullscreen() {
host.__fullscreenCalls.push("enter");
element = document.documentElement;
document.dispatchEvent(new Event("fullscreenchange"));
return Promise.resolve();
};
Document.prototype.exitFullscreen = function exitFullscreen() {
host.__fullscreenCalls.push("exit");
element = null;
document.dispatchEvent(new Event("fullscreenchange"));
return Promise.resolve();
};
});
}
function fullscreenCalls(page: Page) {
return page.evaluate(() => (window as typeof window & { __fullscreenCalls: string[] }).__fullscreenCalls);
}
/** The visible buttons in the window's top-right corner, where the camera controls sit on the Map. */
async function topRightButtons(page: Page) {
return page.evaluate(() => [...document.querySelectorAll<HTMLElement>("button, [role='button']")]
.filter((element) => {
const box = element.getBoundingClientRect();
if (box.width === 0 || box.height === 0 || getComputedStyle(element).visibility === "hidden") return false;
return box.bottom <= 80 && box.right >= window.innerWidth - 240;
})
.map((element) => element.getAttribute("aria-label") ?? element.textContent?.trim() ?? ""));
}
test("the bottom bar's More menu holds the theme, full screen and keyboard shortcuts, each with its key", async ({ page }) => {
await stubFullscreen(page);
await page.emulateMedia({ colorScheme: "light" });
await page.goto("/map");
const toolbar = page.getByRole("toolbar", { name: "Canvas tools" });
const more = toolbar.getByRole("button", { name: "More", exact: true });
// The keyboard button became More; it is the bar's last button.
await expect(toolbar.getByRole("button", { name: "Keyboard shortcuts" })).toHaveCount(0);
await expect(toolbar.getByRole("button").last()).toHaveAccessibleName("More");
await expect(more).toHaveAttribute("aria-haspopup", "menu");
await expect(more).toHaveAttribute("aria-expanded", "false");
await more.click();
const menu = page.getByRole("menu", { name: "More" });
await expect(menu).toBeVisible();
await expect(more).toHaveAttribute("aria-expanded", "true");
// It opens above the bar, anchored to the button.
const [menuBox, moreBox, toolbarBox] = await Promise.all([menu.boundingBox(), more.boundingBox(), toolbar.boundingBox()]);
expect(menuBox!.y + menuBox!.height).toBeLessThan(toolbarBox!.y);
expect(Math.abs(menuBox!.x + menuBox!.width - (moreBox!.x + moreBox!.width))).toBeLessThanOrEqual(2);
// Rows: Theme (a group of three radio items), Full screen, Keyboard shortcuts, in sentence case.
const themes = menu.getByRole("group", { name: "Theme" });
expect(await themes.getByRole("menuitemradio").evaluateAll((items) => items.map((item) => item.getAttribute("aria-label"))))
.toEqual(["Auto", "Light", "Dark"]);
await expect(menu.getByRole("menuitem")).toHaveCount(2);
await expect(menu.getByRole("menuitem").nth(0)).toHaveAccessibleName("Full screen");
await expect(menu.getByRole("menuitem").nth(1)).toHaveAccessibleName("Keyboard shortcuts");
await expect(menu.getByRole("menuitemcheckbox")).toHaveAccessibleName("Inspector");
await expect(menu.locator(".more-menu-label")).toHaveText(["Theme", "Full screen", "Inspector", "Keyboard shortcuts"]);
await expect(menu.locator("kbd")).toHaveText(["T", "F", "I", "?"]);
for (const label of await menu.locator(".more-menu-label").all()) {
await expect(label).toHaveCSS("text-transform", "none");
}
// It opens on the current theme; the arrows walk the rows and the switch, Esc closes it and
// returns focus to More.
await expect(themes.getByRole("menuitemradio", { name: "Auto" })).toBeFocused();
await expect(themes.getByRole("menuitemradio", { name: "Auto" })).toHaveAttribute("aria-checked", "true");
await page.keyboard.press("ArrowRight");
await expect(themes.getByRole("menuitemradio", { name: "Light" })).toBeFocused();
await page.keyboard.press("ArrowDown");
await expect(menu.getByRole("menuitem", { name: "Full screen" })).toBeFocused();
await page.keyboard.press("ArrowDown");
await expect(menu.getByRole("menuitemcheckbox", { name: "Inspector" })).toBeFocused();
await page.keyboard.press("ArrowDown");
await expect(menu.getByRole("menuitem", { name: "Keyboard shortcuts" })).toBeFocused();
await page.keyboard.press("ArrowDown");
await expect(themes.getByRole("menuitemradio", { name: "Auto" })).toBeFocused();
await page.keyboard.press("Escape");
await expect(menu).toHaveCount(0);
await expect(more).toBeFocused();
await expect(more).toHaveAttribute("aria-expanded", "false");
// The switch sets the theme and keeps the menu open; T still flips it, and the switch follows.
await more.click();
await themes.getByRole("menuitemradio", { name: "Dark" }).click();
await expect(page.locator("html")).toHaveAttribute("data-theme", "dark");
await expect(themes.getByRole("menuitemradio", { name: "Dark" })).toHaveAttribute("aria-checked", "true");
await expect(menu).toBeVisible();
await page.keyboard.press("t");
await expect(page.locator("html")).toHaveAttribute("data-theme", "light");
await expect(themes.getByRole("menuitemradio", { name: "Light" })).toHaveAttribute("aria-checked", "true");
// Full screen: the row enters it and closes the menu; the row then offers the way out.
await menu.getByRole("menuitem", { name: "Full screen" }).click();
await expect(menu).toHaveCount(0);
expect(await fullscreenCalls(page)).toEqual(["enter"]);
await more.click();
await expect(menu.getByRole("menuitem", { name: "Exit full screen" })).toBeVisible();
await page.keyboard.press("Escape");
// F is the same toggle from the keyboard.
await page.keyboard.press("f");
expect(await fullscreenCalls(page)).toEqual(["enter", "exit"]);
await page.keyboard.press("f");
expect(await fullscreenCalls(page)).toEqual(["enter", "exit", "enter"]);
await more.click();
await expect(menu.getByRole("menuitem", { name: "Exit full screen" })).toBeVisible();
await page.keyboard.press("Escape");
await page.keyboard.press("f");
// Keyboard shortcuts opens the reference, which lists F.
await more.click();
await menu.getByRole("menuitem", { name: "Keyboard shortcuts" }).click();
await expect(menu).toHaveCount(0);
const dialog = page.getByRole("dialog", { name: "Keyboard shortcuts" });
await expect(dialog).toBeVisible();
await expect(dialog.locator(".shortcuts-row", { hasText: "Enter or exit full screen" }).locator("kbd")).toHaveText("F");
await page.keyboard.press("Escape");
await expect(dialog).toHaveCount(0);
// ? still opens it too.
await page.keyboard.press("?");
await expect(dialog).toBeVisible();
});
for (const [setup, withoutFullscreen] of [
// iPhone Safari has no element full screen.
["no element full screen", async (page: Page) => page.addInitScript(() => {
delete (Element.prototype as Partial<Element>).requestFullscreen;
})],
// A frame not allowed full screen (an embedded Viewer) has the method, but every request fails.
["a frame without full screen", async (page: Page) => {
await stubFullscreen(page);
await page.addInitScript(() => {
Object.defineProperty(Document.prototype, "fullscreenEnabled", { configurable: true, get: () => false });
});
}],
] as const) {
test(`without the browser's full screen (${setup}), the More menu, F and the shortcuts leave it out`, async ({ page }) => {
await withoutFullscreen(page);
await page.goto("/map");
await page.getByRole("button", { name: "More", exact: true }).click();
const menu = page.getByRole("menu", { name: "More" });
await expect(menu.getByRole("menuitem")).toHaveCount(1);
await expect(menu.getByRole("menuitem", { name: /full screen/i })).toHaveCount(0);
await expect(menu.locator("kbd")).toHaveText(["T", "I", "?"]);
await page.keyboard.press("Escape");
await page.keyboard.press("f");
expect(await page.evaluate(() => (window as typeof window & { __fullscreenCalls?: string[] }).__fullscreenCalls ?? [])).toEqual([]);
await page.keyboard.press("?");
await expect(page.getByRole("dialog", { name: "Keyboard shortcuts" })).not.toContainText("full screen");
});
}
test("the More menu's keys are its own: on Compare, ← → step no screen behind it, and ? hands focus back to More", async ({ page }) => {
await page.setViewportSize({ width: 1440, height: 860 });
await serveWorkspace(page);
await page.goto("/compare?screen=current-profile");
const compare = page.locator(".compare-section");
const route = compare.locator(".compare-bar .compare-nav-route");
await expect(route).toHaveText("/current-profile");
const more = page.getByRole("button", { name: "More", exact: true });
const menu = page.getByRole("menu", { name: "More" });
// Compare has no Inspector, so the menu leaves its row out.
await more.click();
await expect(menu.getByRole("menuitemcheckbox", { name: "Inspector" })).toHaveCount(0);
// ← and → on a row that is not the theme switch do nothing, and step no screen behind the menu.
await page.keyboard.press("ArrowDown");
await expect(menu.getByRole("menuitem").first()).toBeFocused();
await page.keyboard.press("ArrowRight");
await page.keyboard.press("ArrowLeft");
await page.keyboard.press("ArrowRight");
await expect(menu).toBeVisible();
await expect(route).toHaveText("/current-profile");
await expect(page).toHaveURL(/screen=current-profile/);
await page.keyboard.press("Escape");
await expect(menu).toHaveCount(0);
// ? opens the shortcuts as the row does; closing them returns focus to More.
await more.click();
await page.keyboard.press("?");
const dialog = page.getByRole("dialog", { name: "Keyboard shortcuts" });
await expect(dialog).toBeVisible();
await expect(menu).toHaveCount(0);
await page.keyboard.press("Escape");
await expect(dialog).toHaveCount(0);
await expect(more).toBeFocused();
});
test("with nothing selected, the More menu's Inspector row opens the Inspector, and the open menu follows the bar it moves", async ({ page }) => {
await page.setViewportSize({ width: 1000, height: 820 });
await page.goto("/map");
const more = page.getByRole("button", { name: "More", exact: true });
const menu = page.getByRole("menu", { name: "More" });
const inspector = page.locator(".right-panel");
await expect(inspector).toHaveCount(0);
await more.click();
const row = menu.getByRole("menuitemcheckbox", { name: "Inspector" });
await expect(row).toHaveAttribute("aria-checked", "false");
await expect(row).toHaveAttribute("aria-keyshortcuts", "I");
await row.click();
await expect(menu).toHaveCount(0);
await expect(inspector).toBeVisible();
await more.click();
await expect(row).toHaveAttribute("aria-checked", "true");
await row.click();
await expect(inspector).toHaveCount(0);
// I opens the Inspector with the menu up; the bar moves left out of its way, and the menu with it.
await more.click();
await expect(menu).toBeVisible();
const before = (await more.boundingBox())!;
await page.keyboard.press("i");
await expect(inspector).toBeVisible();
await expect.poll(async () => (await more.boundingBox())!.x).toBeLessThan(before.x - 1);
await expect(menu).toBeVisible();
await expect.poll(async () => {
const [menuBox, moreBox] = await Promise.all([menu.boundingBox(), more.boundingBox()]);
return Math.abs(menuBox!.x + menuBox!.width - (moreBox!.x + moreBox!.width));
}).toBeLessThanOrEqual(2);
});
test("in a window too short for it, the More menu scrolls", async ({ page }) => {
await page.setViewportSize({ width: 1180, height: 150 });
await page.goto("/map");
await page.getByRole("button", { name: "More", exact: true }).click();
const popover = page.locator(".menu-popover.more-menu");
await expect(popover).toBeVisible();
expect(await popover.evaluate((element) => element.scrollHeight > element.clientHeight)).toBe(true);
const box = (await popover.boundingBox())!;
expect(box.y + box.height).toBeLessThanOrEqual(150);
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);
await page.mouse.wheel(0, 200);
await expect.poll(() => popover.evaluate((element) => element.scrollTop)).toBeGreaterThan(0);
await expect(page.getByRole("menu", { name: "More" }).getByRole("menuitem", { name: "Keyboard shortcuts" })).toBeInViewport({ ratio: 1 });
});
test("the top right is the camera's alone: fit, center and zoom on the Map, nothing on Screens or Compare", async ({ page }) => {
await page.setViewportSize({ width: 1440, height: 900 });
await serveWorkspace(page);
await page.goto("/map");
const camera = page.getByRole("group", { name: "Canvas camera controls" });
await expect(camera).toBeVisible();
expect(await topRightButtons(page)).toEqual(["Fit canvas", "Center canvas", expect.stringMatching(/^Zoom — \d+%$/)]);
// With the Inspector open the camera keeps to the canvas beside it; the Inspector's header has
// only its own actions.
await openInspector(page);
await expect(camera.getByRole("button")).toHaveCount(3);
await page.getByRole("button", { name: "Close inspector" }).click();
await expect(page.locator(".right-panel")).toHaveCount(0);
await chooseCanvasView(page, "Screens");
await expect(page).toHaveURL(/\/screens/);
await expect(page.locator(".screens-page .screens-cell").first()).toBeVisible();
await expect(page.locator(".canvas-camera-controls")).toHaveCount(0);
expect(await topRightButtons(page)).toEqual([]);
await page.goto("/compare?screen=current-profile");
await expect(page.getByRole("region", { name: /^Compare / })).toBeVisible();
await expect(page.locator(".canvas-camera-controls")).toHaveCount(0);
expect(await topRightButtons(page)).toEqual([]);
});
test("/ finds screens on the Screens page: the tree and the grid narrow to the query, Enter picks the first match, Esc clears then closes", async ({ page }) => {
@@ -5449,3 +5717,22 @@ test("a find left on when the window narrows to the phone layout does not filter
await page.setViewportSize({ width: 390, height: 844 });
await expect(cells).toHaveCount(all);
});
test.describe("a wide Inspector in a short window", () => {
test.use({ viewport: { width: 1180, height: 600 } });
test("holds the review's Split pair to most of the window's height", async ({ page }) => {
await page.addInitScript(() => localStorage.setItem("expo-explore:inspector-width", "590"));
await serveWorkspace(page);
await page.goto("/map?screen=current-profile");
const review = page.locator(".right-panel").getByRole("region", { name: "Changes in /current-profile" });
await expect(review).toBeVisible();
await review.getByRole("button", { name: /^Split/ }).click();
const frame = review.locator(".compare-frame").first();
await expect(frame).toBeVisible();
// Two frames of a 590px panel would be over 600px tall unbounded; the cap is 70% of the window,
// the same as Swipe's and Flip's one frame.
await expect.poll(async () => (await frame.boundingBox())!.height).toBeLessThanOrEqual(421);
await expect.poll(async () => (await frame.boundingBox())!.height).toBeGreaterThan(300);
});
});
+35
View File
@@ -0,0 +1,35 @@
import assert from "node:assert/strict";
import test from "node:test";
const { tsImport } = await import("tsx/esm/api");
const { clampInspectorWidth, inspectorWidthBounds, INSPECTOR_WIDTH_MAX, INSPECTOR_WIDTH_MIN } =
await tsImport("../../viewer/src/utils/inspector-width.ts", import.meta.url);
test("the Inspector may take at most half the window, within its fixed range", () => {
assert.deepEqual(inspectorWidthBounds(1440), { min: INSPECTOR_WIDTH_MIN, max: 720 });
assert.deepEqual(inspectorWidthBounds(2560), { min: INSPECTOR_WIDTH_MIN, max: INSPECTOR_WIDTH_MAX });
// A window narrower than two minimum panels still allows the minimum.
assert.deepEqual(inspectorWidthBounds(500), { min: INSPECTOR_WIDTH_MIN, max: INSPECTOR_WIDTH_MIN });
});
test("the bounds are in the panel's own pixels when the chrome is zoomed", () => {
assert.deepEqual(inspectorWidthBounds(1600, 1.25), { min: INSPECTOR_WIDTH_MIN, max: 640 });
assert.deepEqual(inspectorWidthBounds(1600, 0), inspectorWidthBounds(1600, 1));
});
test("the Inspector stops where the canvas keeps the bottom bar's room, never below the minimum", () => {
// 820 - 424 leaves 396, less than half of 820.
assert.deepEqual(inspectorWidthBounds(820, 1, 424), { min: INSPECTOR_WIDTH_MIN, max: 396 });
// In a wide window half of it is the tighter cap.
assert.deepEqual(inspectorWidthBounds(1440, 1, 424), { min: INSPECTOR_WIDTH_MIN, max: 720 });
// The room is in window pixels, the width in the panel's own: (1000 - 530) / 1.25 = 376.
assert.deepEqual(inspectorWidthBounds(1000, 1.25, 530), { min: INSPECTOR_WIDTH_MIN, max: 376 });
assert.deepEqual(inspectorWidthBounds(700, 1, 424), { min: INSPECTOR_WIDTH_MIN, max: INSPECTOR_WIDTH_MIN });
});
test("a width is clamped to the bounds and rounded to whole pixels", () => {
const bounds = { min: 320, max: 720 };
assert.equal(clampInspectorWidth(100, bounds), 320);
assert.equal(clampInspectorWidth(1000, bounds), 720);
assert.equal(clampInspectorWidth(455.6, bounds), 456);
});
+4
View File
@@ -113,6 +113,10 @@ test("the palette's commands follow the canvas: Compare steps changes with the a
assert.ok(!ids(compare).includes("go:compare"));
assert.ok(ids(compare).includes("go:map"));
// Full screen, where the browser has it, prints F; without it there is no command.
assert.equal(commandItems({ ...base, canvas: "map", fullscreen: false }, actions).find((item) => item.id === "command:view:fullscreen").shortcut, "F");
assert.ok(!ids(map).includes("view:fullscreen"));
// A phone has no keyboard shortcuts to list.
assert.ok(ids(map).includes("go:shortcuts"));
assert.ok(!ids(commandItems({ ...base, canvas: "map", phone: true }, actions)).includes("go:shortcuts"));
+8
View File
@@ -70,3 +70,11 @@ test("⌥1–⌥8 open a target by its place, with ⌥ alone; D and ` are plain
assert.ok(matchesShortcut(key("KeyD"), SHORTCUTS.target.menu));
assert.ok(matchesShortcut(key("Backquote"), SHORTCUTS.target.last));
});
test("F is full screen, a plain key: ⌘F stays the browser's find", () => {
assert.equal(formatShortcut(SHORTCUTS.view.fullscreen, true), "F");
assert.ok(matchesShortcut(key("KeyF"), SHORTCUTS.view.fullscreen));
assert.ok(!matchesShortcut(key("KeyF", { metaKey: true }), SHORTCUTS.view.fullscreen));
assert.ok(!matchesShortcut(key("KeyF", { ctrlKey: true }), SHORTCUTS.view.fullscreen));
assert.ok(!matchesShortcut(key("KeyF", { shiftKey: true }), SHORTCUTS.view.fullscreen));
});
+20 -13
View File
@@ -7,12 +7,13 @@ import { isEmbeddedArtifactUrl, leaseEmbeddedArtifactUrl, optionalStorage, viewe
import { REPORT_SOURCE } from "./utils/report-source";
import { CanvasToolbar } from "./components/canvas/toolbar";
import { CanvasCameraControls } from "./components/canvas/camera-controls";
import { MoreMenu } from "./components/canvas/more-menu";
import { CanvasVisibleFrameProvider } from "./components/canvas/visible-frame-provider";
import { AppLoading } from "./components/shared/app-loading";
import { ReportLoadingShell } from "./components/shared/report-loading-shell";
import { screenLabel } from "./utils/screen-path";
import { AppPill, PLATFORM_NAMES, runTargets, siblingReportUrl, targetSwitch } from "./components/panels/app-pill";
import { useFullscreen } from "./components/panels/shell-actions";
import { fullscreenSupported, useFullscreen } from "./components/panels/shell-actions";
import { getCanvasZoomState, runCanvasZoomCommand } from "./utils/canvas-zoom";
import { commandItems, suggestedCommands } from "./utils/commands";
import { changedScreens, focusCounts as countFocusStatuses, isCapturedChange, type ChangedScreen } from "./utils/changed-screens";
@@ -383,11 +384,8 @@ const ViewerApp = memo(function ViewerApp({ reportKey }: { reportKey: number })
const revisionRef = useRef<{ runId: string; revision: number } | undefined>(undefined);
const pollingRef = useRef(false);
const theme = themePreference === "system" ? preferredSystemTheme : themePreference;
// Auto → Dark → Light → Auto, as the button's tooltip spells out.
const toggleTheme = useCallback(() => {
setThemePreference(current => current === "system" ? "dark" : current === "dark" ? "light" : "system");
}, []);
// The T key flips what is on screen, dark to light and back; only the button returns to Auto.
// The T key flips what is on screen, dark to light and back; only the More menu's theme switch
// (or the palette) returns to Auto.
const flipTheme = useCallback(() => {
setThemePreference(current => (current === "system" ? preferredSystemTheme : current) === "dark" ? "light" : "dark");
}, [preferredSystemTheme]);
@@ -1043,6 +1041,10 @@ const ViewerApp = memo(function ViewerApp({ reportKey }: { reportKey: number })
setHandoffOpen(true);
} else if (matchesShortcut(event, SHORTCUTS.appearance.theme)) {
flipTheme();
} else if (matchesShortcut(event, SHORTCUTS.view.fullscreen)) {
// The More menu and the palette offer full screen only where the browser has it.
if (phoneRef.current || !fullscreenSupported()) return;
toggleFullscreen();
} else if (matchesShortcut(event, SHORTCUTS.appearance.app)) {
// Only a report captured in both schemes has another appearance to show.
const { options, current } = appearanceRef.current;
@@ -1064,7 +1066,7 @@ const ViewerApp = memo(function ViewerApp({ reportKey }: { reportKey: number })
return () => {
window.removeEventListener("keydown", onKeyDown);
};
}, [chooseAppearance, clearSelectedScreen, flipTheme, navigate, searchOpen, selectCanvas, toggleRightPanel]);
}, [chooseAppearance, clearSelectedScreen, flipTheme, navigate, searchOpen, selectCanvas, toggleFullscreen, toggleRightPanel]);
// A side-panel row or a deep link is a "go to": the camera fits that screen and the step is
// kept. Screens inventory clicks only select in place; Map clicks also focus the chosen screen. Repeating a selected target refits it without adding history.
@@ -1574,7 +1576,7 @@ const ViewerApp = memo(function ViewerApp({ reportKey }: { reportKey: number })
theme: themePreference,
appearances: appearances.length > 1 ? appearances.map((option) => ({ id: option, label: appearanceLabel(option), current: option === appearance })) : [],
inspector: phone || comparingScreens ? undefined : { open: !rightCollapsed },
fullscreen: !phone && typeof document.documentElement.requestFullscreen === "function" ? fullscreen : undefined,
fullscreen: !phone && fullscreenSupported() ? fullscreen : undefined,
targets: (() => {
const run = runTargets(map.run);
const noun = run.targets.every((target) => target.id === target.platform) ? "platform" as const : "device" as const;
@@ -1692,10 +1694,8 @@ const ViewerApp = memo(function ViewerApp({ reportKey }: { reportKey: number })
/>
)}
</div>
{phone ? null : (
<CanvasCameraControls inspectorCollapsed={comparing ? false : rightCollapsed} theme={theme} themePreference={themePreference} onToggleTheme={toggleTheme}
camera={route.canvas === "map"} />
)}
{/* Top right holds the camera only, so only the Map has anything there. */}
{phone || route.canvas !== "map" ? null : <CanvasCameraControls />}
{phone ? (
<PhoneTabBar
canvas={route.canvas}
@@ -1706,7 +1706,13 @@ const ViewerApp = memo(function ViewerApp({ reportKey }: { reportKey: number })
canvas={route.canvas}
searchOpen={searchOpen}
{...(handoffAction ? { actions: handoffAction } : {})}
onOpenShortcuts={() => setShortcutsOpen(true)}
more={<MoreMenu
themePreference={themePreference}
onChangeTheme={setThemePreference}
{...(fullscreenSupported() ? { fullscreen: { active: fullscreen, onToggle: toggleFullscreen } } : {})}
{...(comparingScreens ? {} : { inspector: { open: !rightCollapsed, onToggle: toggleRightPanel } })}
onOpenShortcuts={() => setShortcutsOpen(true)}
/>}
onSelectCanvas={selectCanvas}
onOpenSearch={() => setSearchOpen(true)}
/>}
@@ -1714,6 +1720,7 @@ const ViewerApp = memo(function ViewerApp({ reportKey }: { reportKey: number })
{shortcutsOpen ? (
<ShortcutsDialog
context={{ canvas: route.canvas, review: reviewingInSidebar, hasChanges: compareOrder.length > 0, handoff: Boolean(handoffInput), appearances: appearances.length > 1,
fullscreen: !phone && fullscreenSupported(),
...(switchTargets ? { targets: switchTargets } : {}) }}
onClose={() => setShortcutsOpen(false)}
/>
@@ -6,20 +6,9 @@ import { formatShortcut, SHORTCUTS } from "../../utils/shortcuts";
import { KeyHint } from "../shared/key-hint";
import { Menu, type MenuItem } from "../shared/menu";
import { Tooltip } from "../shared/tooltip";
import { FullscreenToggleButton, ThemeToggleButton, type ShellActionsProps, type ShellTheme } from "../panels/shell-actions";
import { useCanvasVisibleFrame } from "./visible-frame-provider";
import { setFollowSelection, useFollowSelection } from "../../utils/follow-selection";
type CanvasCameraControlsProps = {
/** Makes room for the collapsed inspector controls at the window edge. */
inspectorCollapsed: boolean;
theme: ShellTheme;
themePreference: ShellActionsProps["themePreference"];
onToggleTheme: () => void;
/** Fit, center and zoom act on a canvas; a page (Screens) or Compare shows only the page actions. */
camera?: boolean;
};
const CAMERA_CONTROLS_MINIMUM_FRAME_WIDTH = 240;
function ZoomControl() {
@@ -114,11 +103,11 @@ function RecenterControl() {
}
/**
* Camera actions belong to the canvas, not to either inspector panel. The page-level theme and
* full screen actions share the toolbar, so it stays in one place whether the inspector is open
* or not.
* Camera actions belong to the canvas, not to either inspector panel: fit, center and the zoom
* level, top right on the Map. Screens and Compare have no camera, so nothing renders there; the
* page-wide theme and full screen live in the bottom bar's "More" menu.
*/
export function CanvasCameraControls({ inspectorCollapsed, theme, themePreference, onToggleTheme, camera = true }: CanvasCameraControlsProps) {
export function CanvasCameraControls() {
const { visibleFrame } = useCanvasVisibleFrame();
if (visibleFrame && visibleFrame.width < CAMERA_CONTROLS_MINIMUM_FRAME_WIDTH) return null;
const style = visibleFrame ? ({
@@ -126,24 +115,12 @@ export function CanvasCameraControls({ inspectorCollapsed, theme, themePreferenc
} as CSSProperties) : undefined;
return (
<div
className={`canvas-camera-controls${inspectorCollapsed ? " inspector-collapsed" : ""}`}
style={style}
role="group"
aria-label="Canvas camera controls">
<div className="canvas-camera-controls" style={style} role="group" aria-label="Canvas camera controls">
<div className="canvas-camera-controls-inner">
{camera ? (
<>
<FitControl />
<span className="camera-control-divider" aria-hidden="true" />
<RecenterControl />
<span className="camera-control-divider" aria-hidden="true" />
<ZoomControl />
<span className="camera-control-divider" aria-hidden="true" />
</>
) : null}
<ThemeToggleButton theme={theme} themePreference={themePreference} onToggleTheme={onToggleTheme} className="camera-action-button" />
<FullscreenToggleButton className="camera-action-button" />
<FitControl />
<RecenterControl />
<span className="camera-control-divider" aria-hidden="true" />
<ZoomControl />
</div>
</div>
);
+180
View File
@@ -0,0 +1,180 @@
import { useCallback, useId, useRef, useState, type KeyboardEvent, type ReactNode } from "react";
import { Check, Ellipsis, Keyboard, Maximize, Minimize, Monitor, Moon, PanelRight, Sun } from "lucide-react";
import { Menu } from "../shared/menu";
import { Tooltip } from "../shared/tooltip";
import { formatShortcut, SHORTCUTS } from "../../utils/shortcuts";
import type { ThemePreference } from "../../utils/navigation";
const THEME_OPTIONS: { id: ThemePreference; label: string; title: string; icon: ReactNode }[] = [
{ id: "system", label: "Auto", title: "Auto (system)", icon: <Monitor /> },
{ id: "light", label: "Light", title: "Light", icon: <Sun /> },
{ id: "dark", label: "Dark", title: "Dark", icon: <Moon /> },
];
export type MoreMenuProps = {
themePreference: ThemePreference;
onChangeTheme: (theme: ThemePreference) => void;
/** Full screen's state and toggle; left out where the browser has no full screen. */
fullscreen?: { active: boolean; onToggle: () => void } | undefined;
/** The Inspector's state and toggle; left out where there is no Inspector (Compare). */
inspector?: { open: boolean; onToggle: () => void } | undefined;
onOpenShortcuts: () => void;
};
/**
* The bottom bar's last button: the page-wide settings that have no place on a canvas. Every row
* reads the same way, icon, label, control and key: the Viewer's theme (Auto, Light, Dark; T
* flips light and dark), full screen (F), the Inspector (I) and the keyboard shortcuts (?).
*/
export function MoreMenu(props: MoreMenuProps) {
const [open, setOpen] = useState(false);
const buttonRef = useRef<HTMLButtonElement>(null);
const listRef = useRef<HTMLDivElement>(null);
// The menu opens on the current theme, as a choice menu opens on its current choice.
const currentThemeRef = useRef<HTMLButtonElement>(null);
const themeLabelId = useId();
const close = useCallback(() => setOpen(false), []);
// ↑ and ↓ move between rows (the theme row's stop is its current choice), ← and → between the
// three themes. Tab leaves the menu, as it does a native one. The menu's keys are its own: Esc
// and the arrows are marked used, so a canvas behind it (Compare's screens and areas) leaves them.
// ? opens the shortcuts as the row does, so the dialog hands focus back to More.
const onKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {
const list = listRef.current;
if (!list) return;
if (event.key === "Tab") {
close();
return;
}
if (event.key === "Escape") {
event.preventDefault();
close();
return;
}
if (event.key === "?" && !event.metaKey && !event.ctrlKey && !event.altKey) {
event.preventDefault();
close();
props.onOpenShortcuts();
return;
}
const active = document.activeElement as HTMLElement | null;
if (event.key === "ArrowLeft" || event.key === "ArrowRight") {
event.preventDefault();
const radios = [...list.querySelectorAll<HTMLElement>('[role="menuitemradio"]')];
const at = active ? radios.indexOf(active) : -1;
if (at < 0) return;
radios[(at + (event.key === "ArrowRight" ? 1 : -1) + radios.length) % radios.length]?.focus();
return;
}
if (!["ArrowDown", "ArrowUp", "Home", "End"].includes(event.key)) return;
event.preventDefault();
const rows = [...list.querySelectorAll<HTMLElement>("[data-more-row]")];
if (rows.length === 0) return;
const at = rows.findIndex((row) => active && row.contains(active));
const next = event.key === "Home" ? 0
: event.key === "End" ? rows.length - 1
: (Math.max(at, event.key === "ArrowDown" ? -1 : 0) + (event.key === "ArrowDown" ? 1 : -1) + rows.length) % rows.length;
const row = rows[next];
const stop = row?.matches('[role="menuitem"], [role="menuitemcheckbox"]') ? row
: row?.querySelector<HTMLElement>('[aria-checked="true"]') ?? row?.querySelector<HTMLElement>('[role="menuitemradio"]');
stop?.focus();
};
return (
<>
<Tooltip label="More" placement="top" disabled={open}>
<button
ref={buttonRef}
type="button"
className={`toolbar-button${open ? " active" : ""}`}
aria-label="More"
aria-haspopup="menu"
aria-expanded={open}
onClick={() => setOpen((current) => !current)}>
<Ellipsis />
</button>
</Tooltip>
<Menu open={open} anchorRef={buttonRef} initialFocusRef={currentThemeRef} align="end" className="more-menu" onDismiss={close}>
<div ref={listRef} className="more-menu-list" role="menu" aria-label="More" onKeyDown={onKeyDown}>
<div className="more-menu-row" role="group" aria-labelledby={themeLabelId} data-more-row>
<span className="more-menu-icon" aria-hidden="true"><Moon /></span>
<span className="more-menu-label" id={themeLabelId}>Theme</span>
<span className="more-theme-switch">
{THEME_OPTIONS.map((option) => {
const checked = props.themePreference === option.id;
return (
<button
key={option.id}
ref={checked ? currentThemeRef : undefined}
type="button"
className="more-theme-option"
role="menuitemradio"
aria-checked={checked}
aria-label={option.label}
title={option.title}
tabIndex={-1}
onClick={() => props.onChangeTheme(option.id)}>
{option.icon}
</button>
);
})}
</span>
<kbd className="more-menu-key" aria-hidden="true">{formatShortcut(SHORTCUTS.appearance.theme)}</kbd>
</div>
{props.fullscreen ? (
<button
type="button"
className="more-menu-row more-menu-item"
role="menuitem"
tabIndex={-1}
aria-keyshortcuts={SHORTCUTS.view.fullscreen.key}
data-more-row
onClick={() => {
props.fullscreen?.onToggle();
close();
}}>
<span className="more-menu-icon" aria-hidden="true">{props.fullscreen.active ? <Minimize /> : <Maximize />}</span>
<span className="more-menu-label">{props.fullscreen.active ? "Exit full screen" : "Full screen"}</span>
<kbd className="more-menu-key" aria-hidden="true">{formatShortcut(SHORTCUTS.view.fullscreen)}</kbd>
</button>
) : null}
{props.inspector ? (
<button
type="button"
className="more-menu-row more-menu-item"
role="menuitemcheckbox"
aria-checked={props.inspector.open}
tabIndex={-1}
aria-keyshortcuts={SHORTCUTS.panel.right.key}
data-more-row
onClick={() => {
props.inspector?.onToggle();
close();
}}>
<span className="more-menu-icon" aria-hidden="true"><PanelRight /></span>
<span className="more-menu-label">Inspector</span>
{props.inspector.open ? <span className="more-menu-check" aria-hidden="true"><Check /></span> : null}
<kbd className="more-menu-key" aria-hidden="true">{formatShortcut(SHORTCUTS.panel.right)}</kbd>
</button>
) : null}
<button
type="button"
className="more-menu-row more-menu-item"
role="menuitem"
tabIndex={-1}
aria-haspopup="dialog"
aria-keyshortcuts="?"
data-more-row
onClick={() => {
close();
props.onOpenShortcuts();
}}>
<span className="more-menu-icon" aria-hidden="true"><Keyboard /></span>
<span className="more-menu-label">Keyboard shortcuts</span>
<kbd className="more-menu-key" aria-hidden="true">?</kbd>
</button>
</div>
</Menu>
</>
);
}
+44 -12
View File
@@ -1,7 +1,8 @@
import { GitCompareArrows, Keyboard, LayoutGrid, Map, Search } from "lucide-react";
import { type CSSProperties } from "react";
import { GitCompareArrows, LayoutGrid, Map, Search } from "lucide-react";
import { type CSSProperties, useLayoutEffect, useState } from "react";
import { Tooltip } from "../shared/tooltip";
import { useCanvasVisibleFrame } from "./visible-frame-provider";
import { setToolbarRoom } from "../../utils/inspector-width";
import { CANVAS_NUMBER_KEYS, formatShortcut, SHORTCUTS } from "../../utils/shortcuts";
import { KeyHint } from "../shared/key-hint";
import {
@@ -26,23 +27,59 @@ type CanvasToolbarProps = {
actions?: React.ReactNode;
onSelectCanvas: (canvas: CanvasView) => void;
onOpenSearch: () => void;
onOpenShortcuts: () => void;
/** The bar's last button: the "More" menu with theme, full screen and keyboard shortcuts. */
more: React.ReactNode;
};
/** Room kept between the toolbar and an Inspector wide enough to reach it. */
const TOOLBAR_PANEL_GAP = 12;
export function CanvasToolbar(props: CanvasToolbarProps) {
const { visibleFrame } = useCanvasVisibleFrame();
// The bar as mounted now: it unmounts while hidden, and its last width is kept for deciding when
// it fits again.
const [element, setElement] = useState<HTMLDivElement | null>(null);
const [ownWidth, setOwnWidth] = useState(0);
useLayoutEffect(() => {
if (!element) return;
const measure = () => setOwnWidth(element.getBoundingClientRect().width);
measure();
if (typeof ResizeObserver === "undefined") return;
const observer = new ResizeObserver(measure);
observer.observe(element);
return () => observer.disconnect();
}, [element]);
// The Inspector stops short of covering the bar: it may widen only as far as leaves the canvas
// room for the bar and a gap either side.
useLayoutEffect(() => {
if (ownWidth > 0) setToolbarRoom(ownWidth + 2 * TOOLBAR_PANEL_GAP);
}, [ownWidth]);
// When responsive panels leave less room than the toolbar itself, hiding it is the only
// collision-free layout. It returns as soon as either panel is collapsed.
// collision-free layout. It returns as soon as either panel is collapsed. The Inspector's width is
// capped to leave the bar its room, so this is a last resort: a desktop window (820px and up)
// always fits the bar beside the narrowest Inspector.
if (visibleFrame && visibleFrame.width < TOOLBAR_MINIMUM_FRAME_WIDTH) return null;
// The toolbar is the canvas' persistent mode switcher. Panel geometry may raise it to avoid
// bottom chrome, but must not pull it away from the window's stable horizontal centre.
// bottom chrome, but must not pull it away from the window's stable horizontal centre. Only an
// Inspector that would cover it (widened by the reader, or a narrow window's overlay) pushes it
// left, and by just that much, never past the canvas' left edge: with no room left between the
// two, it hides as it does above, which the Inspector's cap keeps from happening.
let shift = 0;
if (visibleFrame && typeof window !== "undefined") {
const centredLeft = window.innerWidth / 2 - ownWidth / 2;
const needed = centredLeft + ownWidth + TOOLBAR_PANEL_GAP - (visibleFrame.x + visibleFrame.width);
const room = centredLeft - (visibleFrame.x + TOOLBAR_PANEL_GAP);
if (needed > 0 && needed > room) return null;
shift = Math.max(0, needed);
}
const style = visibleFrame ? ({
"--canvas-visible-bottom-inset": `calc(100% - ${visibleFrame.y + visibleFrame.height}px)`,
"--canvas-toolbar-shift": `${shift}px`,
} as CSSProperties) : undefined;
const views = CANVAS_VIEW_ORDER;
return (
<div className="canvas-toolbar" role="toolbar" aria-label="Canvas tools" style={style}>
<div ref={setElement} className="canvas-toolbar" role="toolbar" aria-label="Canvas tools" style={style}>
{/* The contents grow with --ui-scale; the bar itself keeps its exact place. */}
<div className="canvas-toolbar-inner">
<div className="toolbar-group" role="group" aria-label="Canvas actions">
@@ -96,12 +133,7 @@ export function CanvasToolbar(props: CanvasToolbarProps) {
<span className="toolbar-divider" aria-hidden="true" />
<Tooltip label="Keyboard shortcuts" shortcut="?" placement="top">
<button type="button" className="toolbar-button" aria-label="Keyboard shortcuts"
aria-haspopup="dialog" onClick={props.onOpenShortcuts}>
<Keyboard />
</button>
</Tooltip>
{props.more}
</div>
</div>
);
@@ -490,9 +490,9 @@
the size a changed screen's is. */
.sidebar-review-off .variant-preview.has-image-ratio { width: min(100%, calc(70dvh * var(--preview-aspect))); }
.sidebar-review-stage {
/* Two frames and a 12px gap share the panel's width. One frame takes the whole width, up to
most of the window's height. */
--compare-frame-height: calc((100cqw - 12px) / 2 / var(--compare-aspect));
/* Two frames and a 12px gap share the panel's width, up to most of the window's height (a wide
panel would otherwise push What changed below the fold). One frame takes the whole width. */
--compare-frame-height: min(calc((100cqw - 12px) / 2 / var(--compare-aspect)), 70dvh);
gap: 12px;
}
.sidebar-review-stage.mode-swipe,
@@ -19,6 +19,8 @@ export type ShortcutContext = {
handoff?: boolean;
/** The report was captured in both light and dark, so the app's appearance can be switched. */
appearances?: boolean;
/** The browser can put the Viewer in full screen. */
fullscreen?: boolean;
/** The run's other targets are one switch away; the pill calls them devices, or platforms in reports from before targets. */
targets?: { noun: "device" | "platform"; count: number };
};
@@ -94,6 +96,7 @@ export function shortcutGroups(context: ShortcutContext): Group[][] {
...(context.canvas === "compare" ? [] : [{ label: "Show or hide the inspector", keys: [SHORTCUTS.panel.right] }]),
{ label: "Viewer theme: dark or light", keys: [SHORTCUTS.appearance.theme] },
...(context.appearances ? [{ label: "The app's appearance: light or dark", keys: [SHORTCUTS.appearance.app] }] : []),
...(context.fullscreen ? [{ label: "Enter or exit full screen", keys: [SHORTCUTS.view.fullscreen] }] : []),
{ label: "Show this list", keys: ["?"] },
],
};
@@ -119,7 +122,7 @@ export function shortcutGroups(context: ShortcutContext): Group[][] {
return [here, [goTo, view]];
}
/** The keyboard reference, opened with "?" or the button at the end of the bottom bar. */
/** The keyboard reference, opened with "?" or from the More menu at the end of the bottom bar. */
export function ShortcutsDialog(props: { context: ShortcutContext; onClose: () => void }) {
const dialogRef = useModalDialog(true, props.onClose);
useEffect(() => {
@@ -0,0 +1,183 @@
import {
useCallback, useRef, useSyncExternalStore, type CSSProperties, type KeyboardEvent, type PointerEvent, type RefObject,
} from "react";
import {
clampInspectorWidth, getToolbarRoom, inspectorWidthBounds, INSPECTOR_WIDTH_MAX, INSPECTOR_WIDTH_MIN, INSPECTOR_WIDTH_STEP,
setInspectorWidth, subscribeToToolbarRoom, useInspectorWidth,
type InspectorWidthBounds,
} from "../../utils/inspector-width";
/** On the root while the edge is dragged, so the whole page keeps the resize cursor and selects nothing. */
const RESIZING_CLASS = "inspector-resizing";
/** The chrome's zoom (`--ui-scale`): pointer distances are in window pixels, the panel's width in its own. */
function uiScale(): number {
const raw = parseFloat(getComputedStyle(document.documentElement).getPropertyValue("--ui-scale"));
return Number.isFinite(raw) && raw > 0 ? raw : 1;
}
/** The panel's width in its own pixels: the reader's, else the stylesheet's default for this window. */
function panelWidth(panel: HTMLElement): number {
return parseFloat(getComputedStyle(panel).width) || 0;
}
function defaultWidth(): number {
return window.matchMedia("(max-width: 1180px)").matches ? 320 : 400;
}
/** The panel's widest and default widths follow the window (and `--ui-scale`, which follows it too). */
function subscribeToWindow(onChange: () => void): () => void {
window.addEventListener("resize", onChange);
return () => window.removeEventListener("resize", onChange);
}
/** The widest the panel can be now: it follows the window, `--ui-scale` and the bottom bar's width. */
function currentBounds(): InspectorWidthBounds {
return inspectorWidthBounds(window.innerWidth, uiScale(), getToolbarRoom());
}
function subscribeToBounds(onChange: () => void): () => void {
const unsubscribeToolbar = subscribeToToolbarRoom(onChange);
const unsubscribeWindow = subscribeToWindow(onChange);
return () => {
unsubscribeToolbar();
unsubscribeWindow();
};
}
function widestWidth(): number {
return currentBounds().max;
}
type Drag = {
pointerId: number;
startX: number;
startWidth: number;
scale: number;
bounds: InspectorWidthBounds;
last: number;
/** The panel's own `--inspector-width` before the drag, put back when the drag changes nothing. */
inline: string;
};
/**
* Makes the Inspector's left edge a splitter. A drag moves the edge live (the width is written to
* the panel's `--inspector-width` directly, so nothing re-renders per pointer move) and is kept
* when the pointer lifts; arrow keys move it a step; Home and End take it to its narrowest and
* widest; a double-click returns it to the default.
*/
export function useInspectorResize(panelRef: RefObject<HTMLElement | null>) {
const width = useInspectorWidth();
const widest = useSyncExternalStore(subscribeToBounds, widestWidth, () => INSPECTOR_WIDTH_MAX);
const fallback = useSyncExternalStore(subscribeToWindow, defaultWidth, () => 400);
const drag = useRef<Drag | null>(null);
// Every way a drag can stop ends here, once: the pointer lifting, the browser taking the pointer
// back, the window losing focus, or the edge itself going away (the Inspector closed mid-drag).
const endDrag = useCallback(() => {
const state = drag.current;
if (!state) return;
drag.current = null;
document.documentElement.classList.remove(RESIZING_CLASS);
if (state.last !== state.startWidth) {
setInspectorWidth(state.last);
return;
}
// Nothing changed, so nothing re-renders to replace the width the drag wrote.
const panel = panelRef.current;
if (!panel) return;
if (state.inline) panel.style.setProperty("--inspector-width", state.inline);
else panel.style.removeProperty("--inspector-width");
}, [panelRef]);
const handleRef = useCallback((element: HTMLElement | null) => {
if (!element) return;
window.addEventListener("blur", endDrag);
return () => {
window.removeEventListener("blur", endDrag);
endDrag();
};
}, [endDrag]);
const onPointerDown = (event: PointerEvent<HTMLElement>) => {
const panel = panelRef.current;
if (event.button !== 0 || !panel) return;
const scale = uiScale();
const startWidth = panelWidth(panel);
drag.current = {
pointerId: event.pointerId, startX: event.clientX, startWidth, scale,
bounds: currentBounds(), last: startWidth,
inline: panel.style.getPropertyValue("--inspector-width"),
};
event.currentTarget.setPointerCapture(event.pointerId);
document.documentElement.classList.add(RESIZING_CLASS);
event.preventDefault();
};
const onPointerMove = (event: PointerEvent<HTMLElement>) => {
const state = drag.current;
const panel = panelRef.current;
if (!state || state.pointerId !== event.pointerId || !panel) return;
// A release the handle never heard about.
if (event.buttons === 0) {
endDrag();
return;
}
// The edge is on the left: moving the pointer left widens the panel.
const next = clampInspectorWidth(state.startWidth + (state.startX - event.clientX) / state.scale, state.bounds);
if (next === state.last) return;
state.last = next;
panel.style.setProperty("--inspector-width", `${next}px`);
};
const onPointerEnd = (event: PointerEvent<HTMLElement>) => {
const state = drag.current;
if (!state || state.pointerId !== event.pointerId) return;
if (event.currentTarget.hasPointerCapture(event.pointerId)) event.currentTarget.releasePointerCapture(event.pointerId);
endDrag();
};
const onKeyDown = (event: KeyboardEvent<HTMLElement>) => {
const panel = panelRef.current;
if (!panel) return;
const bounds = currentBounds();
const current = panelWidth(panel);
let next: number;
switch (event.key) {
case "ArrowLeft": next = current + INSPECTOR_WIDTH_STEP; break;
case "ArrowRight": next = current - INSPECTOR_WIDTH_STEP; break;
case "Home": next = bounds.min; break;
case "End": next = bounds.max; break;
default: return;
}
event.preventDefault();
event.stopPropagation();
// A key that cannot move the edge (End at a smaller window's cap) keeps the saved width.
next = clampInspectorWidth(next, bounds);
if (next !== Math.round(current)) setInspectorWidth(next);
};
// The saved width is the reader's preference; the panel takes as much of it as this window allows.
const bounds = { min: INSPECTOR_WIDTH_MIN, max: widest };
const shown = width === undefined ? undefined : clampInspectorWidth(width, bounds);
const style = (shown === undefined ? undefined : { "--inspector-width": `${shown}px` }) as CSSProperties | undefined;
const handleProps = {
role: "separator",
"aria-orientation": "vertical",
"aria-label": "Resize inspector",
"aria-valuemin": bounds.min,
"aria-valuemax": bounds.max,
"aria-valuenow": shown ?? fallback,
title: "Drag to resize. Double-click to reset.",
tabIndex: 0,
ref: handleRef,
onPointerDown,
onPointerMove,
onPointerUp: onPointerEnd,
onPointerCancel: onPointerEnd,
onLostPointerCapture: endDrag,
onKeyDown,
onDoubleClick: () => setInspectorWidth(undefined),
} as const;
return { style, handleProps };
}
+15 -19
View File
@@ -1,5 +1,5 @@
import { useEffect, useRef } from "react";
import { GitCompareArrows, PanelRight, ScanSearch, X } from "lucide-react";
import { GitCompareArrows, ScanSearch, X } from "lucide-react";
import { Tooltip } from "../shared/tooltip";
import { formatShortcut, SHORTCUTS } from "../../utils/shortcuts";
import { InspectorPanel } from "./inspector";
@@ -14,6 +14,7 @@ import { setOutlinesShown, useOutlinesShown } from "../compare/compare-section";
import { AutoHideScrollArea } from "../shared/auto-hide-scroll-area";
import { usePhoneLayout } from "../../utils/phone-layout";
import { useDragToDismiss } from "../phone/phone-chrome";
import { useInspectorResize } from "./inspector-resize";
type RightPanelProps = {
index: MapIndex;
@@ -36,6 +37,9 @@ export function RightPanel(props: RightPanelProps) {
// On a phone the panel is a bottom sheet; dragging its header down closes it.
const phone = usePhoneLayout();
const drag = useDragToDismiss(props.onToggleCollapsed);
// On a desktop its left edge is a splitter; the sheet keeps the window's width.
const panelRef = useRef<HTMLElement>(null);
const resize = useInspectorResize(panelRef);
const selectedPath = props.screen ? displayPathForScreen(props.screen) : undefined;
const screenDiff = props.screen ? props.diff?.screens.get(props.screen.id) : undefined;
// Compare opens only a screen it reviews: a changed screen in the review order, not a state
@@ -55,36 +59,28 @@ export function RightPanel(props: RightPanelProps) {
if (scrollRef.current) scrollRef.current.scrollTop = 0;
}, [screenId]);
// Collapsed, the panel icon brings the Inspector back; open, an X closes it.
// Closed, the Inspector leaves no button behind: a selection, Return or I opens it. Open, an X
// closes it.
if (props.collapsed) return null;
const panelButton = (
<Tooltip
label={props.collapsed ? "Expand inspector" : "Close inspector"}
shortcut={formatShortcut(SHORTCUTS.panel.right)}
placement="bottom-end">
<Tooltip label="Close inspector" shortcut={formatShortcut(SHORTCUTS.panel.right)} placement="bottom-end">
<button
type="button"
className="icon-button"
aria-label={props.collapsed ? "Expand inspector" : "Close inspector"}
aria-expanded={!props.collapsed}
aria-label="Close inspector"
aria-expanded
onClick={props.onToggleCollapsed}>
{props.collapsed ? <PanelRight aria-hidden="true" /> : <X aria-hidden="true" />}
<X aria-hidden="true" />
</button>
</Tooltip>
);
if (props.collapsed) {
return (
<div className="right-float" role="toolbar" aria-label="Canvas actions">
{panelButton}
</div>
);
}
// One header row: the screen's status and path, then the close button. On a phone the close
// button leads the row instead, away from the screen stepper's arrows. Theme and full screen
// live in the canvas camera controls.
// live in the bottom bar's "More" menu.
return (
<aside className="right-panel" data-drag-sheet aria-label="Inspector panel">
<aside ref={panelRef} className="right-panel" data-drag-sheet aria-label="Inspector panel" style={phone ? undefined : resize.style}>
{phone ? null : <div className="right-panel-resize" {...resize.handleProps} />}
<header className="right-head" {...(phone ? drag : {})}>
{phone ? <span className="right-sheet-grabber" aria-hidden="true" /> : null}
{phone ? panelButton : null}
+13 -60
View File
@@ -1,25 +1,18 @@
import { useEffect, useState } from "react";
import { Maximize, Minimize, Moon, Sun, SunMoon } from "lucide-react";
import { Tooltip } from "../shared/tooltip";
import { formatShortcut, SHORTCUTS } from "../../utils/shortcuts";
import type { ThemePreference } from "../../utils/navigation";
export type ShellTheme = "light" | "dark";
export type ShellActionsProps = {
/** The theme on screen: the preference, or the system's when that is Auto. */
theme: ShellTheme;
themePreference: ThemePreference;
/** Steps Auto → Dark → Light → Auto. */
onToggleTheme: () => void;
/** The host toolbar's button class, so the actions match their neighbours. */
className?: string;
};
import { useCallback, useEffect, useState } from "react";
function fullscreenActive(): boolean {
return typeof document !== "undefined" && document.fullscreenElement !== null;
}
/**
* Whether this browser can put the page in full screen at all: iPhone Safari has no element full
* screen, and a frame that was not allowed it (an embedded Viewer) refuses every request.
*/
export function fullscreenSupported(): boolean {
return typeof document !== "undefined" && typeof document.documentElement.requestFullscreen === "function"
&& document.fullscreenEnabled !== false;
}
/** Tracks the page-level fullscreen state, including exits triggered by the browser itself. */
export function useFullscreen(): [boolean, () => void] {
const [active, setActive] = useState(fullscreenActive);
@@ -30,54 +23,14 @@ export function useFullscreen(): [boolean, () => void] {
return () => document.removeEventListener("fullscreenchange", sync);
}, []);
const toggle = () => {
const toggle = useCallback(() => {
if (document.fullscreenElement) {
void document.exitFullscreen().catch(() => {});
return;
}
if (typeof document.documentElement.requestFullscreen !== "function") return;
if (!fullscreenSupported()) return;
void document.documentElement.requestFullscreen().catch(() => {});
};
}, []);
return [active, toggle];
}
const THEME_LABELS: Record<ThemePreference, string> = {
system: "Theme: Auto (system)",
dark: "Theme: Dark",
light: "Theme: Light",
};
/** The theme button shows the current preference; a press steps Auto → Dark → Light. */
export function ThemeToggleButton(props: ShellActionsProps) {
const Icon = props.themePreference === "system" ? SunMoon : props.themePreference === "dark" ? Moon : Sun;
return (
<Tooltip label={THEME_LABELS[props.themePreference]} shortcut={formatShortcut(SHORTCUTS.appearance.theme)} placement="bottom">
<button
type="button"
className={props.className ?? "icon-button"}
aria-label="Toggle theme"
data-theme-preference={props.themePreference}
onClick={props.onToggleTheme}>
<Icon aria-hidden="true" />
</button>
</Tooltip>
);
}
export function FullscreenToggleButton(props: Pick<ShellActionsProps, "className">) {
const [active, toggle] = useFullscreen();
const label = active ? "Exit full screen" : "Enter full screen";
return (
<Tooltip label={label} placement="bottom">
<button
type="button"
className={props.className ?? "icon-button"}
aria-label={label}
aria-pressed={active}
onClick={toggle}>
{active ? <Minimize aria-hidden="true" /> : <Maximize aria-hidden="true" />}
</button>
</Tooltip>
);
}
+2 -2
View File
@@ -531,10 +531,10 @@
.changes-menu .panel-search-clear { width: 44px; height: 44px; }
/* The minimap repeats what a phone already shows whole, and covers a sixth of it. */
.phone-layout .canvas-minimap-shell { display: none; }
/* With nothing selected there is no Inspector to reopen. */
.phone-layout .right-float { display: none; }
/* The Inspector slides up over the whole screen; a drag down on its header puts it away. */
.phone-layout .right-panel {
/* The sheet is the window's width; the desktop's half-window limit is not for it. */
max-width: none;
position: fixed;
z-index: 120;
inset: 0;
+18 -1
View File
@@ -237,12 +237,29 @@ export function Menu({ items = [], children, initialFocusRef, open, ariaLabel, c
if (initialFocusRef && event.target instanceof Node
&& !popoverRef.current?.contains(event.target) && !anchorRef?.current?.contains(event.target)) dismissRef.current();
};
// A trigger can also move with no scroll or resize, as the bottom bar does when the Inspector
// opens beside it; an anchored menu checks where its trigger is once a frame while it is open.
let frame = 0;
let anchorAt = "";
const follow = () => {
const rect = anchorRef?.current?.getBoundingClientRect();
const at = rect ? `${rect.left},${rect.top}` : "";
if (at !== anchorAt) {
if (anchorAt) place();
anchorAt = at;
}
frame = requestAnimationFrame(follow);
};
window.addEventListener("pointerdown", onPointerDown);
window.addEventListener("keydown", onKeyDown);
window.addEventListener("resize", place);
if (anchorRef) window.addEventListener("scroll", onScroll, true);
if (anchorRef) {
window.addEventListener("scroll", onScroll, true);
follow();
}
window.addEventListener("focusin", onFocusIn);
return () => {
cancelAnimationFrame(frame);
window.removeEventListener("pointerdown", onPointerDown);
window.removeEventListener("keydown", onKeyDown);
window.removeEventListener("resize", place);
+99 -68
View File
@@ -133,13 +133,10 @@
--icon-hit-min: 32px;
/* Chevrons, carets and status glyphs that sit inline next to text. */
--icon-glyph-inline: 14px;
/* Floating canvas chrome shares a y=30px center line. The collapsed inspector joins the
camera controls into one compact toolbar. Reserve space for the visible actions only. */
/* Floating canvas chrome shares a y=30px center line. Reserve space for the visible actions only. */
--floating-chrome-top: 14px;
--floating-chrome-height: 42px;
--canvas-chrome-inline-inset: 12px;
--right-float-edge: 12px;
--right-float-width: calc(var(--icon-btn-md) + 6px);
--left-collapsed-pill-width: 420px;
--left-collapsed-pill-height: var(--floating-chrome-height);
--left-collapsed-pill-top: var(--floating-chrome-top);
@@ -304,16 +301,14 @@ code {
}
:root[data-canvas-transition-direction]::view-transition-group(app-pill),
:root[data-canvas-transition-direction]::view-transition-group(canvas-camera-controls),
:root[data-canvas-transition-direction]::view-transition-group(canvas-toolbar),
:root[data-canvas-transition-direction]::view-transition-group(right-floating-controls) {
:root[data-canvas-transition-direction]::view-transition-group(canvas-toolbar) {
z-index: 101;
animation: none;
}
:root[data-canvas-transition-direction]::view-transition-image-pair(canvas-minimap),
:root[data-canvas-transition-direction]::view-transition-image-pair(app-pill),
:root[data-canvas-transition-direction]::view-transition-image-pair(canvas-camera-controls),
:root[data-canvas-transition-direction]::view-transition-image-pair(canvas-toolbar),
:root[data-canvas-transition-direction]::view-transition-image-pair(right-floating-controls) {
:root[data-canvas-transition-direction]::view-transition-image-pair(canvas-toolbar) {
isolation: isolate;
}
:root[data-canvas-transition-direction]::view-transition-old(canvas-view-content),
@@ -325,9 +320,7 @@ code {
:root[data-canvas-transition-direction]::view-transition-old(canvas-toolbar),
:root[data-canvas-transition-direction]::view-transition-old(phone-top-actions),
:root[data-canvas-transition-direction]::view-transition-new(canvas-toolbar),
:root[data-canvas-transition-direction]::view-transition-new(phone-top-actions),
:root[data-canvas-transition-direction]::view-transition-old(right-floating-controls),
:root[data-canvas-transition-direction]::view-transition-new(right-floating-controls) {
:root[data-canvas-transition-direction]::view-transition-new(phone-top-actions) {
mix-blend-mode: normal;
}
:root[data-canvas-transition-direction="forward"]::view-transition-old(canvas-view-content) {
@@ -350,15 +343,13 @@ code {
}
:root[data-canvas-transition-direction]::view-transition-old(app-pill),
:root[data-canvas-transition-direction]::view-transition-old(canvas-camera-controls),
:root[data-canvas-transition-direction]::view-transition-old(canvas-toolbar),
:root[data-canvas-transition-direction]::view-transition-old(right-floating-controls) {
:root[data-canvas-transition-direction]::view-transition-old(canvas-toolbar) {
animation: none;
opacity: 0;
}
:root[data-canvas-transition-direction]::view-transition-new(app-pill),
:root[data-canvas-transition-direction]::view-transition-new(canvas-camera-controls),
:root[data-canvas-transition-direction]::view-transition-new(canvas-toolbar),
:root[data-canvas-transition-direction]::view-transition-new(right-floating-controls) {
:root[data-canvas-transition-direction]::view-transition-new(canvas-toolbar) {
animation: none;
opacity: 1;
}
@@ -1011,7 +1002,7 @@ code {
border-radius: calc(14px * var(--ui-scale));
background: var(--surface);
box-shadow: var(--floating-chrome-shadow);
transform: translateX(-50%);
transform: translateX(calc(-50% - var(--canvas-toolbar-shift, 0px)));
view-transition-name: canvas-toolbar;
}
.canvas-toolbar-inner { display: flex; align-items: center; gap: 2px; zoom: var(--ui-scale); }
@@ -1118,7 +1109,10 @@ code {
z-index: 100;
display: flex;
flex: none;
width: 400px;
/* The reader's own width when they have dragged the edge (utils/inspector-width.ts), else the
default; never more than half the window, so the canvas keeps the other half. */
width: var(--inspector-width, 400px);
max-width: 50%;
height: 100%;
min-height: 0;
flex-direction: column;
@@ -1130,33 +1124,35 @@ code {
/* Two Diff previews, their 8px gap, and the 14px side insets must fit this same width. */
--inspector-shared-preview-max-width: calc((100cqw - 36px) / 2);
}
/* When minimised, the inspector actions join the camera controls as one floating toolbar. */
.right-float {
position: fixed;
z-index: 100;
top: var(--chrome-top);
right: var(--right-float-edge);
width: calc(var(--right-float-width) * var(--ui-scale));
height: var(--chrome-height);
display: flex;
align-items: center;
gap: 2px;
padding: calc(3px * var(--ui-scale));
border: 0;
border-radius: 0 calc(8px * var(--ui-scale)) calc(8px * var(--ui-scale)) 0;
background: var(--side-panel-surface);
box-shadow: none;
/* No backdrop blur: the surface is opaque, and a blurred backdrop leaves this toolbar's view
transition snapshot stale, so a button that moves into its place paints late. */
view-transition-name: right-floating-controls;
/* The panel's left edge is a splitter: a 10px strip over the border, quiet until it is hovered,
dragged or focused, when the border thickens into the accent line. */
.right-panel-resize {
position: absolute;
z-index: 1;
top: 0;
bottom: 0;
left: -5px;
width: 10px;
cursor: col-resize;
touch-action: none;
outline: none;
}
.right-float > * { zoom: var(--ui-scale); }
.right-float .icon-button.active { color: var(--text); background: var(--element); }
.right-float .icon-button[disabled] { color: var(--border); cursor: default; background: transparent; }
.right-float .icon-button:hover {
border-color: transparent;
background: var(--panel-hover);
.right-panel-resize::before {
position: absolute;
top: 0;
bottom: 0;
left: 4px;
width: 2px;
background: var(--accent);
content: "";
opacity: 0;
transition: opacity var(--toolbar-motion) var(--toolbar-easing) 120ms;
}
.right-panel-resize:hover::before,
.right-panel-resize:focus-visible::before,
.inspector-resizing .right-panel-resize::before { opacity: 1; transition-delay: 0ms; }
/* While the edge is dragged nothing else may select or change the cursor. */
.inspector-resizing, .inspector-resizing * { cursor: col-resize !important; user-select: none !important; }
.right-head {
display: flex;
flex: none;
@@ -1215,7 +1211,8 @@ code {
position: absolute;
z-index: 20;
top: var(--chrome-top);
right: calc(var(--canvas-visible-right-inset, 0px) + 8px);
/* Mirrors the pill: the same inset from the canvas' right edge as the pill's from its left. */
right: calc(var(--canvas-visible-right-inset, 0px) + var(--canvas-chrome-inline-inset));
display: inline-flex;
height: var(--chrome-height);
align-items: center;
@@ -1226,30 +1223,9 @@ code {
color: var(--text);
background: var(--side-panel-surface);
box-shadow: var(--floating-chrome-shadow);
/* No backdrop blur, as on .right-float: with it, entering Compare painted full screen late. */
/* No backdrop blur: with it, the view transition's snapshot of these controls painted late. */
view-transition-name: canvas-camera-controls;
}
.canvas-camera-controls.inspector-collapsed {
right: calc(
var(--canvas-visible-right-inset, 0px) +
var(--right-float-edge) + var(--right-float-width) * var(--ui-scale) - 1px
);
border: 0;
border-radius: calc(8px * var(--ui-scale)) 0 0 calc(8px * var(--ui-scale));
box-shadow: none;
}
.canvas-camera-controls.inspector-collapsed::before {
position: absolute;
z-index: -1;
top: 0;
right: calc((var(--right-float-width) * var(--ui-scale) - 1px) * -1);
bottom: 0;
left: 0;
border-radius: calc(8px * var(--ui-scale));
box-shadow: var(--floating-chrome-shadow);
content: "";
pointer-events: none;
}
.canvas-camera-controls .camera-action-button,
.canvas-camera-controls .zoom-button {
border: 0;
@@ -1273,7 +1249,6 @@ code {
flex: none;
background: var(--border-subtle);
}
.canvas-camera-controls.inspector-collapsed .camera-control-divider { display: none; }
.canvas-camera-controls .zoom-button:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 1px;
@@ -2069,6 +2044,61 @@ code {
.menu-row-shortcut { flex: none; margin-left: 16px; color: var(--tertiary); font-size: 11px; }
.menu-separator { height: 1px; margin: 4px 6px; background: var(--popover-line); }
/* ── More menu (the bottom bar's "…") ───────────────────────────────────── */
/* The menu is anchored to its button, but clears the bar the button sits in. The popover itself
is the surface, as the Changes menu's is: an anchored popover scrolls, and would clip a shadow
drawn by the list inside it. Only a window too short for the menu scrolls it. */
.menu-popover.more-menu {
overflow-x: hidden !important;
border: 1px solid var(--popover-line);
border-radius: calc(9px * var(--ui-scale));
background: var(--popover);
box-shadow: var(--popover-shadow);
translate: 0 calc(-12px * var(--ui-scale));
}
/* Rows read icon, label, control, key, in the menu's own type and colours. */
.more-menu-list { display: flex; width: 248px; flex-direction: column; padding: 4px; }
.more-menu-row {
display: flex;
width: 100%;
min-height: 34px;
align-items: center;
gap: 8px;
padding: 4px 6px 4px 8px;
border-radius: 5px;
color: var(--text);
background: transparent;
font-size: 12px;
text-align: left;
}
.more-menu-item:hover,
.more-menu-item:focus-visible { background: var(--popover-hover); outline: none; }
.more-menu-icon { display: flex; width: 16px; flex: none; align-items: center; justify-content: center; color: var(--secondary); }
.more-menu-icon > svg { width: 15px; height: 15px; }
.more-menu-label { min-width: 0; flex: 1; white-space: nowrap; }
.more-menu-check { display: flex; flex: none; color: var(--secondary); }
.more-menu-check > svg { width: 14px; height: 14px; }
/* The key column lines up down the menu, whatever the row holds before it. */
.more-menu-key { min-width: 22px; flex: none; text-align: center; }
/* A compact three-way switch: Auto, Light, Dark, on the segmented control's track and thumb. */
.more-theme-switch { display: flex; flex: none; gap: 2px; padding: 2px; border-radius: 7px; background: var(--segment-track); }
.more-theme-option {
display: flex;
width: 26px;
height: 22px;
align-items: center;
justify-content: center;
border-radius: 5px;
color: var(--tertiary);
background: transparent;
transition: color 120ms ease, background 120ms ease;
}
.more-theme-option > svg { width: 14px; height: 14px; }
.more-theme-option:hover { color: var(--text); }
.more-theme-option[aria-checked="true"] { color: var(--text); background: var(--segment-thumb); box-shadow: 0 1px 2px rgb(0 0 0 / 0.12); }
.more-theme-option:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; }
/* ── Feedback dialog ────────────────────────────────────────────────────── */
.dialog-backdrop {
@@ -2215,7 +2245,8 @@ code {
.search-command-result-copy code { color: inherit; font-size: inherit; }
.search-command-section + .search-command-section { margin-top: 4px; }
.search-command-section > .search-command-section-label { padding: 8px 8px 4px; }
.search-command-result-key {
.search-command-result-key,
.more-menu-key {
padding: 2px 6px;
border: 1px solid var(--border);
border-radius: 5px;
@@ -2343,7 +2374,7 @@ html [data-sonner-toaster][data-sonner-theme] {
@keyframes tooltip-in { from { opacity: 0; } }
@media (max-width: 1180px) {
.right-panel { width: 320px; }
.right-panel { width: var(--inspector-width, 320px); }
}
@media (max-width: 900px) {
+2 -1
View File
@@ -102,7 +102,8 @@ export function commandItems(context: CommandContext, actions: CommandActions):
{ keywords: ["app", "appearance", "scheme", "captured"], shortcut: !appearance.current && context.appearances.length === 2 ? key(SHORTCUTS.appearance.app) : undefined });
}
if (context.fullscreen !== undefined) {
add("view:fullscreen", "View", context.fullscreen ? "Exit full screen" : "Enter full screen", actions.toggleFullscreen, { keywords: ["fullscreen", "window", "focus"] });
add("view:fullscreen", "View", context.fullscreen ? "Exit full screen" : "Enter full screen", actions.toggleFullscreen,
{ keywords: ["fullscreen", "window", "focus"], shortcut: key(SHORTCUTS.view.fullscreen) });
}
for (const target of context.targets) {
+83
View File
@@ -0,0 +1,83 @@
import { useSyncExternalStore } from "react";
import { optionalStorage } from "./embedded-report";
const INSPECTOR_WIDTH_STORAGE_KEY = "expo-explore:inspector-width";
/** Below this the Before/After pair no longer reads; above the maximum the canvas is the one squeezed. */
export const INSPECTOR_WIDTH_MIN = 320;
export const INSPECTOR_WIDTH_MAX = 800;
/** How far one arrow key press moves the panel's edge. */
export const INSPECTOR_WIDTH_STEP = 16;
const listeners = new Set<() => void>();
/** The choice made this visit: storage can be denied (a private window), and the drag must still hold. `null` is a reset. */
let chosen: number | null | undefined;
function parseWidth(value: string | null): number | undefined {
if (value === null) return undefined;
const width = Number(value);
return Number.isFinite(width) && width > 0 ? width : undefined;
}
function stored(): number | undefined {
if (chosen !== undefined) return chosen ?? undefined;
return parseWidth(optionalStorage.getItem(INSPECTOR_WIDTH_STORAGE_KEY));
}
/** Sets the Inspector's width in unscaled CSS pixels, or `undefined` to return to the default, and remembers it where it can. */
export function setInspectorWidth(width: number | undefined) {
chosen = width ?? null;
if (width === undefined) optionalStorage.removeItem(INSPECTOR_WIDTH_STORAGE_KEY);
else optionalStorage.setItem(INSPECTOR_WIDTH_STORAGE_KEY, String(width));
for (const listener of listeners) listener();
}
/** The reader's Inspector width, or `undefined` while the panel keeps its default width. */
export function useInspectorWidth(): number | undefined {
return useSyncExternalStore(
(onChange) => {
listeners.add(onChange);
return () => listeners.delete(onChange);
},
stored,
() => undefined,
);
}
/** The room the bottom bar needs beside the Inspector, in window pixels: its measured width and a gap either side. */
let toolbarRoom = 0;
const toolbarListeners = new Set<() => void>();
/** The bottom bar reports the room it needs whenever its measured width changes (with `--ui-scale` too). */
export function setToolbarRoom(room: number) {
if (room === toolbarRoom) return;
toolbarRoom = room;
for (const listener of toolbarListeners) listener();
}
export function getToolbarRoom(): number {
return toolbarRoom;
}
export function subscribeToToolbarRoom(onChange: () => void): () => void {
toolbarListeners.add(onChange);
return () => toolbarListeners.delete(onChange);
}
export type InspectorWidthBounds = { min: number; max: number };
/**
* The widths the panel may take in a window `windowWidth` wide: at most half of it, so the canvas
* keeps the other half, and never so wide that the canvas beside it loses the `toolbarRoom` the
* bottom bar needs (window pixels), in the panel's own (unscaled) pixels when the chrome is zoomed
* by `scale`. Neither cap goes below the minimum.
*/
export function inspectorWidthBounds(windowWidth: number, scale = 1, room = 0): InspectorWidthBounds {
const zoom = scale > 0 ? scale : 1;
const half = Math.floor(windowWidth / 2 / zoom);
const besideBar = Math.floor((windowWidth - room) / zoom);
return { min: INSPECTOR_WIDTH_MIN, max: Math.max(INSPECTOR_WIDTH_MIN, Math.min(INSPECTOR_WIDTH_MAX, half, besideBar)) };
}
export function clampInspectorWidth(width: number, bounds: InspectorWidthBounds): number {
return Math.round(Math.min(bounds.max, Math.max(bounds.min, width)));
}
+4
View File
@@ -77,6 +77,10 @@ export const SHORTCUTS = {
theme: plain("KeyT", "T"),
app: shift("KeyT", "T"),
},
/** F puts the whole Viewer in or out of full screen, where the browser allows it. */
view: {
fullscreen: plain("KeyF", "F"),
},
/** Canvas edits follow the platform-standard history keys. */
edit: {
undo: mod("KeyZ", "Z"),