mirror of
https://github.com/expo/explore.git
synced 2026-11-15 13:18:16 -10:00
Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0ed12b1fc2 | ||
|
|
034aabe2aa | ||
|
|
b6be88adb9 | ||
|
|
b281c734f4 | ||
|
|
c99c26f9bb | ||
|
|
9150a24cd9 |
No files matched your search
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
Generated
+2
-2
@@ -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
@@ -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",
|
||||
|
||||
@@ -1,33 +1,57 @@
|
||||
import { posix } from "node:path";
|
||||
import ts from "typescript";
|
||||
|
||||
/** The `@/*` import alias a tsconfig maps to one project directory, such as `src/` or the root. */
|
||||
/** The import aliases a tsconfig maps to project directories, such as `@/*` to `src/` and `@/assets/*` to `assets/`. */
|
||||
export type TsconfigAlias = {
|
||||
/** Directory prefix that replaces `@/`, with a trailing slash or empty for the project root. */
|
||||
target: string;
|
||||
/** Each alias prefix (`@/`, `@/assets/`) and the directory prefix that replaces it, longest prefix first. */
|
||||
prefixes: readonly { prefix: string; target: string }[];
|
||||
/** `baseUrl` is the project root: a bare specifier no alias matches is looked up there before it is taken for a package. */
|
||||
baseUrl?: true;
|
||||
/** Set when the tsconfig asks for module resolution the static analysis cannot follow. */
|
||||
unsupported?: string;
|
||||
};
|
||||
|
||||
const SINGLE_DIRECTORY_TARGET = /^(?:\.\/)?((?:[\w.-]+\/)*)\*$/;
|
||||
// A relative-looking key (`./*`, `/*`) is never applied: TypeScript and Metro resolve relative specifiers directly.
|
||||
const PREFIX_KEY = /^([^*./][^*]*\/)\*$/;
|
||||
const DEFAULT: TsconfigAlias = { prefixes: [{ prefix: "@/", target: "src/" }] };
|
||||
|
||||
/**
|
||||
* Static analysis follows one alias, `@/*`, pointing at a single directory (`./*`, `src/*`, `./src/*`),
|
||||
* which is what create-expo-app and the Expo docs set up. Anything else is reported, not guessed.
|
||||
* Static analysis follows `paths` entries of the form `prefix/*` that each point at a single directory (`./*`, `src/*`,
|
||||
* `./assets/*`), which covers create-expo-app's `@/*` and the extra entries apps add beside it. Anything else is
|
||||
* reported, not guessed.
|
||||
*/
|
||||
export function readTsconfigAlias(configText: string | undefined): TsconfigAlias {
|
||||
if (configText === undefined) return { target: "src/" };
|
||||
if (configText === undefined) return DEFAULT;
|
||||
const parsed = ts.parseConfigFileTextToJson("tsconfig.json", configText);
|
||||
const options = parsed.config?.compilerOptions ?? {};
|
||||
const unsupported = { target: "src/", unsupported: "custom module resolution is not statically supported" };
|
||||
const unsupported = { ...DEFAULT, unsupported: "custom module resolution is not statically supported" };
|
||||
if (parsed.error) return unsupported;
|
||||
if (options.baseUrl && ![".", "./"].includes(options.baseUrl)) return unsupported;
|
||||
if (parsed.config?.extends && parsed.config.extends !== "expo/tsconfig.base") return unsupported;
|
||||
const baseUrl = options.baseUrl ? { baseUrl: true as const } : {};
|
||||
const entries = Object.entries(options.paths ?? {}) as [string, unknown][];
|
||||
if (entries.length === 0) return { target: "src/" };
|
||||
if (entries.length > 1 || entries[0]![0] !== "@/*") return unsupported;
|
||||
const targets = entries[0]![1];
|
||||
if (!Array.isArray(targets) || targets.length !== 1 || typeof targets[0] !== "string") return unsupported;
|
||||
const match = SINGLE_DIRECTORY_TARGET.exec(targets[0]);
|
||||
if (!match || match[1]!.split("/").includes("..")) return unsupported;
|
||||
return { target: match[1]! };
|
||||
if (entries.length === 0) return { ...DEFAULT, ...baseUrl };
|
||||
const prefixes: { prefix: string; target: string }[] = [];
|
||||
for (const [key, targets] of entries) {
|
||||
const prefix = PREFIX_KEY.exec(key)?.[1];
|
||||
if (!prefix || !Array.isArray(targets) || targets.length !== 1 || typeof targets[0] !== "string") return unsupported;
|
||||
const match = SINGLE_DIRECTORY_TARGET.exec(targets[0]);
|
||||
if (!match || match[1]!.split("/").some(segment => segment === "." || segment === "..")) return unsupported;
|
||||
prefixes.push({ prefix, target: match[1]! });
|
||||
}
|
||||
// TypeScript picks the pattern with the longest prefix, so `@/assets/x` goes to `assets/`, not `src/assets/`.
|
||||
return { prefixes: prefixes.sort((a, b) => b.prefix.length - a.prefix.length), ...baseUrl };
|
||||
}
|
||||
|
||||
/** The project path an aliased specifier names, before extensions, or undefined when no alias matches it. */
|
||||
export function resolveTsconfigAlias(alias: TsconfigAlias, specifier: string): string | undefined {
|
||||
const entry = alias.prefixes.find(({ prefix }) => specifier.startsWith(prefix));
|
||||
// Normalized as Metro joins it: `@app/a/../b` is `src/b`, and a trailing slash still finds `index`.
|
||||
return entry ? posix.normalize(`${entry.target}${specifier.slice(entry.prefix.length)}`).replace(/\/$/, "") : undefined;
|
||||
}
|
||||
|
||||
/** The project path a bare specifier names under a root `baseUrl`, or undefined; a miss there is a package, not a gap. */
|
||||
export function resolveTsconfigBaseUrl(alias: TsconfigAlias, specifier: string): string | undefined {
|
||||
return alias.baseUrl && !/^[./]/.test(specifier) ? specifier : undefined;
|
||||
}
|
||||
@@ -3,7 +3,7 @@ import { spawnSync } from "node:child_process";
|
||||
import ts from "typescript";
|
||||
import type { SourceChange } from "./git-diff.js";
|
||||
import { validateSourceRoutes, type SourceRoute } from "../contracts/source-route.js";
|
||||
import { readTsconfigAlias } from "../shared/tsconfig-alias.js";
|
||||
import { readTsconfigAlias, resolveTsconfigAlias, resolveTsconfigBaseUrl } from "../shared/tsconfig-alias.js";
|
||||
|
||||
/** Repository path → file text at one exact commit. Non-source files carry an empty string. */
|
||||
export type SourceSnapshot = ReadonlyMap<string, string>;
|
||||
@@ -50,11 +50,12 @@ export function surfaceDependencies(routes: readonly SourceRoute[], files: Sourc
|
||||
if (alias.unsupported) unresolved.add("Custom TypeScript module resolution requires conservative capture");
|
||||
const cache = new Map<string, string[]>();
|
||||
const resolveModule = (importer: string, specifier: string): string | undefined => {
|
||||
const base = specifier.startsWith("@/") ? `${alias.target}${specifier.slice(2)}`
|
||||
: specifier.startsWith(".") ? posix.normalize(posix.join(posix.dirname(importer), specifier))
|
||||
: undefined;
|
||||
const base = resolveTsconfigAlias(alias, specifier)
|
||||
?? (specifier.startsWith(".") ? posix.normalize(posix.join(posix.dirname(importer), specifier))
|
||||
: resolveTsconfigBaseUrl(alias, specifier));
|
||||
if (!base) return undefined;
|
||||
const extensions = ["tsx", "ts", "jsx", "js"].flatMap(ext => [`.${platform}.${ext}`, ...(platform === "web" ? [] : [`.native.${ext}`]), `.${ext}`]).concat([".mjs", ".cjs", ".json"]);
|
||||
// Metro tries a platform suffix with every extension before the next suffix, so `Foo.ios.ts` beats `Foo.tsx`.
|
||||
const extensions = [`.${platform}`, ...(platform === "web" ? [] : [".native"]), ""].flatMap(suffix => ["tsx", "ts", "jsx", "js"].map(ext => `${suffix}.${ext}`)).concat([".mjs", ".cjs", ".json"]);
|
||||
return [...extensions.map((ext) => base + ext), base,
|
||||
...extensions.map((ext) => `${base}/index${ext}`)].find((candidate) => !/(?:^|\/)surfaces?\.json$/.test(candidate) && files.has(candidate));
|
||||
};
|
||||
@@ -78,7 +79,8 @@ export function surfaceDependencies(routes: readonly SourceRoute[], files: Sourc
|
||||
const specifier = node.text;
|
||||
const resolved = resolveModule(path, specifier);
|
||||
if (resolved) dependencies.push(resolved);
|
||||
else if (specifier.startsWith(".") || specifier.startsWith("@/") || specifier.startsWith("~")) {
|
||||
// An alias that matches but finds no file (an .svg, a scale variant) is local code this analysis cannot follow, not a package.
|
||||
else if (specifier.startsWith(".") || resolveTsconfigAlias(alias, specifier) !== undefined || specifier.startsWith("@/") || specifier.startsWith("~")) {
|
||||
unresolved.add(`Unresolved runtime import: ${path} -> ${specifier}`);
|
||||
}
|
||||
// Bare npm packages are covered by lockfile/package changes.
|
||||
@@ -103,7 +105,7 @@ export function surfaceDependencies(routes: readonly SourceRoute[], files: Sourc
|
||||
const pending = [surface.routeFile, ...surface.sourceFiles];
|
||||
let directory = posix.dirname(surface.routeFile);
|
||||
while (directory !== "." && directory !== "/") {
|
||||
const suffixes = ["tsx", "ts", "jsx", "js"].flatMap(extension => [`.${platform}.${extension}`, ...(platform === "web" ? [] : [`.native.${extension}`]), `.${extension}`]);
|
||||
const suffixes = [`.${platform}`, ...(platform === "web" ? [] : [".native"]), ""].flatMap(suffix => ["tsx", "ts", "jsx", "js"].map(ext => `${suffix}.${ext}`));
|
||||
const layout = suffixes.map(suffix => `${directory}/_layout${suffix}`).find(path => files.has(path));
|
||||
if (layout) pending.push(layout);
|
||||
directory = posix.dirname(directory);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { posix } from "node:path";
|
||||
import ts from "typescript";
|
||||
import type { SourceSnapshot } from "./dependency-graph.js";
|
||||
import { readTsconfigAlias } from "../shared/tsconfig-alias.js";
|
||||
import { readTsconfigAlias, resolveTsconfigAlias, resolveTsconfigBaseUrl } from "../shared/tsconfig-alias.js";
|
||||
import { detectAppDir, routeGroupOf } from "./route-providers/expo-router.js";
|
||||
import { validateSourceRoutes, type SourceRoute } from "../contracts/source-route.js";
|
||||
import { validateNavigationGraph, type NavigationEdge, type NavigationGraph } from "../contracts/navigation-graph.js";
|
||||
@@ -54,7 +54,7 @@ export function extractSourceNavigation(routes: readonly SourceRoute[], files: S
|
||||
if (routes.length > 5_000 || files.size > 50_000) throw new Error("Source navigation inventory exceeds its analysis limit");
|
||||
const appDir = detectAppDir(files, analysis.entry);
|
||||
const platform = analysis.platform ?? "ios";
|
||||
const extensions = ["tsx", "ts", "jsx", "js"].flatMap(extension => [`.${platform}.${extension}`, ...(platform === "web" ? [] : [`.native.${extension}`]), `.${extension}`]).concat([".mjs", ".cjs"]);
|
||||
const extensions = [`.${platform}`, ...(platform === "web" ? [] : [".native"]), ""].flatMap(suffix => ["tsx", "ts", "jsx", "js"].map(ext => `${suffix}.${ext}`)).concat([".mjs", ".cjs"]);
|
||||
const unresolved = new Set<string>();
|
||||
const edges = new Map<string, NavigationEdge>();
|
||||
const modalSurfaceIds = new Set<string>();
|
||||
@@ -65,8 +65,8 @@ export function extractSourceNavigation(routes: readonly SourceRoute[], files: S
|
||||
const alias = readTsconfigAlias(files.get("tsconfig.json"));
|
||||
if (alias.unsupported) unresolved.add(`Unresolved navigation: tsconfig.json: ${alias.unsupported}`);
|
||||
const resolveModule = (specifier: string, importer: string): string | undefined => {
|
||||
const base = specifier.startsWith("@/") ? `${alias.target}${specifier.slice(2)}`
|
||||
: specifier.startsWith(".") ? posix.normalize(posix.join(posix.dirname(importer.replace(/^\//, "")), specifier)) : undefined;
|
||||
const base = resolveTsconfigAlias(alias, specifier)
|
||||
?? (specifier.startsWith(".") ? posix.normalize(posix.join(posix.dirname(importer.replace(/^\//, "")), specifier)) : resolveTsconfigBaseUrl(alias, specifier));
|
||||
if (!base || base.startsWith("../")) return undefined;
|
||||
const withoutJs = /\.[cm]?jsx?$/.test(base) ? base.replace(/\.[cm]?jsx?$/, "") : base;
|
||||
return [...extensions.map((ext) => base + ext), base,
|
||||
@@ -542,7 +542,7 @@ export function extractSourceNavigation(routes: readonly SourceRoute[], files: S
|
||||
let parent: ts.Node = declaration;
|
||||
while (!ts.isImportDeclaration(parent) && !ts.isSourceFile(parent)) parent = parent.parent;
|
||||
if (ts.isImportDeclaration(parent) && ts.isStringLiteral(parent.moduleSpecifier)
|
||||
&& /^(?:\.|@\/|~)/.test(parent.moduleSpecifier.text)
|
||||
&& (/^(?:\.|@\/|~)/.test(parent.moduleSpecifier.text) || resolveTsconfigAlias(alias, parent.moduleSpecifier.text) !== undefined)
|
||||
&& !assetFile.test(parent.moduleSpecifier.text)
|
||||
&& !resolveModule(parent.moduleSpecifier.text, parent.getSourceFile().fileName)) issue(parent, "local imported code could not be resolved");
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { posix } from "node:path";
|
||||
import ts from "typescript";
|
||||
import { readTsconfigAlias } from "../../shared/tsconfig-alias.js";
|
||||
import { readTsconfigAlias, resolveTsconfigAlias, resolveTsconfigBaseUrl } from "../../shared/tsconfig-alias.js";
|
||||
|
||||
const UNKNOWN = "\u0000";
|
||||
const MAX_VALUES = 64;
|
||||
@@ -15,7 +15,7 @@ function unwrap(node: ts.Node): ts.Node {
|
||||
|
||||
/** Prove that every render path forwards elsewhere; unknown behavior remains capturable. */
|
||||
export function expoRedirectTargets(files: ReadonlyMap<string, string>, routeFiles: readonly string[], platform = "ios"): Map<string, string[]> {
|
||||
const extensions = ["tsx", "ts", "jsx", "js"].flatMap(ext => [`.${platform}.${ext}`, ...(platform === "web" ? [] : [`.native.${ext}`]), `.${ext}`]).concat([".mjs", ".cjs"]);
|
||||
const extensions = [`.${platform}`, ...(platform === "web" ? [] : [".native"]), ""].flatMap(suffix => ["tsx", "ts", "jsx", "js"].map(ext => `${suffix}.${ext}`)).concat([".mjs", ".cjs"]);
|
||||
const sources = new Map<string, ts.SourceFile | undefined>();
|
||||
let sourceBytes = 0;
|
||||
const sourceFile = (name: string): ts.SourceFile | undefined => {
|
||||
@@ -34,8 +34,8 @@ export function expoRedirectTargets(files: ReadonlyMap<string, string>, routeFil
|
||||
};
|
||||
const alias = readTsconfigAlias(files.get("tsconfig.json"));
|
||||
const resolveModule = (specifier: string, importer: string): string | undefined => {
|
||||
const base = specifier.startsWith("@/") && !alias.unsupported ? `${alias.target}${specifier.slice(2)}`
|
||||
: specifier.startsWith(".") ? posix.normalize(posix.join(posix.dirname(importer.replace(/^\//, "")), specifier)) : undefined;
|
||||
const base = (alias.unsupported ? undefined : resolveTsconfigAlias(alias, specifier))
|
||||
?? (specifier.startsWith(".") ? posix.normalize(posix.join(posix.dirname(importer.replace(/^\//, "")), specifier)) : alias.unsupported ? undefined : resolveTsconfigBaseUrl(alias, specifier));
|
||||
if (!base || base.startsWith("../")) return undefined;
|
||||
const withoutJs = base.replace(/\.[cm]?jsx?$/, "");
|
||||
return [...extensions.map(ext => base + ext), base, ...extensions.map(ext => `${base}/index${ext}`),
|
||||
|
||||
@@ -45,6 +45,8 @@ export function discoverReactNavigation(files: Record<string, string>, options:
|
||||
}
|
||||
}
|
||||
}
|
||||
// TypeScript uses the pattern with the longest prefix and no other, so `@/assets/x` never falls back to `@/*`.
|
||||
aliases.sort((a, b) => b.pattern.split("*")[0]!.length - a.pattern.split("*")[0]!.length);
|
||||
const resolveModule = (file: string, specifier: string): string | undefined => {
|
||||
const bases: string[] = [];
|
||||
if (specifier.startsWith(".")) bases.push(posix.normalize(posix.join(posix.dirname(file), specifier)));
|
||||
@@ -54,6 +56,7 @@ export function discoverReactNavigation(files: Record<string, string>, options:
|
||||
if (suffix === undefined ? specifier === prefix : specifier.startsWith(prefix!) && specifier.endsWith(suffix)) {
|
||||
const replacement = suffix === undefined ? "" : specifier.slice(prefix!.length, specifier.length - suffix.length);
|
||||
bases.push(...alias.targets.map((target) => posix.normalize(posix.join(alias.base, target.replace("*", replacement)))));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,12 +188,11 @@ test("Map keeps selected elevated arrows behind screenshots without rendering na
|
||||
await expect(sourceHitArea.locator("title")).toHaveText("Source navigation\npush · app/home.tsx");
|
||||
await page.mouse.move(1320, 30);
|
||||
const dimmedComparisons = [];
|
||||
for (const presentation of ["muted", "selection"]) {
|
||||
// Only the Changes filter dims a screen; a selection fades nothing.
|
||||
for (const presentation of ["muted"]) {
|
||||
await page.evaluate(mode => {
|
||||
const profile = document.querySelector('.react-flow__node[data-id="profile"]');
|
||||
const canvas = document.querySelector(".map-canvas");
|
||||
profile.classList.toggle("graph-node-muted", mode === "muted");
|
||||
canvas.classList.toggle("screen-selection-active", mode === "selection");
|
||||
}, presentation);
|
||||
const dimmedWithArrows = await profileImage.screenshot({ animations: "disabled" });
|
||||
await page.locator(".map-surface .react-flow__edges").evaluate(node => { node.style.visibility = "hidden"; });
|
||||
@@ -216,7 +215,6 @@ test("Map keeps selected elevated arrows behind screenshots without rendering na
|
||||
}
|
||||
await page.evaluate(() => {
|
||||
document.querySelector('.react-flow__node[data-id="profile"]').classList.remove("graph-node-muted");
|
||||
document.querySelector(".map-canvas").classList.remove("screen-selection-active");
|
||||
});
|
||||
await page.getByRole("button", { name: "Open Profile", exact: true }).click();
|
||||
assert.equal(await page.evaluate(() => window.selectedScreen), "profile");
|
||||
|
||||
@@ -0,0 +1,235 @@
|
||||
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 wide Inspector", () => {
|
||||
test.use({ viewport: { width: 820, height: 800 } });
|
||||
|
||||
test("the toolbar never moves past the canvas' left edge", async ({ page }) => {
|
||||
await page.goto("/map?screen=area-0-screen-1");
|
||||
await expect(panel(page)).toBeVisible();
|
||||
const toolbar = page.getByRole("toolbar", { name: "Canvas tools" });
|
||||
await expect(toolbar).toBeVisible();
|
||||
await handle(page).focus();
|
||||
await page.keyboard.press("End");
|
||||
await expect.poll(() => panelWidth(page)).toBe(410);
|
||||
// Either it fits between the window's edge and the panel, or it gives way, as it does when
|
||||
// the panels leave the canvas too little room.
|
||||
await expect.poll(async () => {
|
||||
if (await toolbar.count() === 0) return true;
|
||||
const toolbarBox = (await toolbar.boundingBox())!;
|
||||
const panelBox = (await panel(page).boundingBox())!;
|
||||
return toolbarBox.x >= 0 && toolbarBox.x + toolbarBox.width <= panelBox.x;
|
||||
}).toBe(true);
|
||||
// Narrowed again, the toolbar returns.
|
||||
await page.keyboard.press("Home");
|
||||
await expect(toolbar).toBeVisible();
|
||||
const toolbarBox = (await toolbar.boundingBox())!;
|
||||
const panelBox = (await panel(page).boundingBox())!;
|
||||
expect(toolbarBox.x).toBeGreaterThanOrEqual(0);
|
||||
expect(toolbarBox.x + toolbarBox.width + 12).toBeCloseTo(panelBox.x, 0);
|
||||
});
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
+206
-152
@@ -80,136 +80,121 @@ async function expectAutoHideScrollbar(
|
||||
await expect(scrollbar).toHaveCSS("opacity", "0");
|
||||
}
|
||||
|
||||
async function expectMapScreenSelectionDimming(
|
||||
page: Page,
|
||||
options: { hoverTargetCount?: number } = {},
|
||||
) {
|
||||
const screens = page.locator(
|
||||
".map-canvas .react-flow__node-screen:not(.canvas-node-exit)",
|
||||
);
|
||||
const selected = page.locator(
|
||||
".map-canvas .react-flow__node-screen.selected:not(.canvas-node-exit)",
|
||||
);
|
||||
const dimmed = page.locator(
|
||||
".map-canvas .react-flow__node-screen:not(.selected):not(.canvas-node-exit)",
|
||||
);
|
||||
await expect(page.locator(".map-canvas")).toHaveClass(/screen-selection-active/);
|
||||
await expect(selected).toHaveCount(1);
|
||||
await expect.poll(async () => dimmed.count()).toBe((await screens.count()) - 1);
|
||||
expect(await screens.evaluateAll(nodes => nodes.every(node => getComputedStyle(node).opacity === "1"))).toBe(true);
|
||||
/** The Map's canvas tokens as computed colours, to compare with what a ring or an edge draws. */
|
||||
async function mapCanvasColors(page: Page) {
|
||||
return page.locator(".map-canvas").evaluate((canvas) => {
|
||||
const resolve = (token: string) => {
|
||||
const probe = document.createElement("span");
|
||||
probe.style.color = `var(${token})`;
|
||||
canvas.append(probe);
|
||||
const color = getComputedStyle(probe).color;
|
||||
probe.remove();
|
||||
return color;
|
||||
};
|
||||
return {
|
||||
accent: resolve("--accent"),
|
||||
accentStrong: resolve("--accent-strong"),
|
||||
hoverRing: resolve("--hover-ring"),
|
||||
quiet: resolve("--border-subtle"),
|
||||
hoverEdge: resolve("--tertiary"),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
await expect.poll(async () => {
|
||||
const [selectedOpacity, dimmedOpacity] = await Promise.all([
|
||||
selected.locator(":scope > .canvas-active-frame").evaluate((node) => Number.parseFloat(getComputedStyle(node).opacity)),
|
||||
dimmed.first().locator(":scope > .canvas-active-frame").evaluate((node) => Number.parseFloat(getComputedStyle(node).opacity)),
|
||||
]);
|
||||
return dimmedOpacity < selectedOpacity;
|
||||
}).toBe(true);
|
||||
/** The screenshot frame's box shadow on a Map card: where its ring is drawn. */
|
||||
function mapCardRing(node: Locator) {
|
||||
return node.locator(".screen-node-image :is(img, .image-placeholder)").first()
|
||||
.evaluate((frame) => getComputedStyle(frame).boxShadow);
|
||||
}
|
||||
|
||||
// Selection focus moves the canvas before hover affordances are exercised. Choose hover
|
||||
// targets only after that flight settles so a node cannot move underneath the minimap between
|
||||
// the hit-test below and Playwright's pointer action.
|
||||
await expect(page.locator(".map-canvas.canvas-focus-animating")).toHaveCount(0);
|
||||
|
||||
const hoverableDimmedIndexes = await dimmed.evaluateAll((nodes) => nodes.flatMap((node, index) => {
|
||||
const bounds = node.getBoundingClientRect();
|
||||
const centerTarget = document.elementFromPoint(
|
||||
bounds.left + bounds.width / 2,
|
||||
bounds.top + bounds.height / 2,
|
||||
);
|
||||
const nodeId = node.getAttribute("data-id");
|
||||
const hasDirectEdge = nodeId !== null && [...document.querySelectorAll(".react-flow__edge")]
|
||||
.some((edge) => {
|
||||
const label = edge.getAttribute("aria-label") ?? "";
|
||||
return label.startsWith(`Edge from ${nodeId} to `) || label.endsWith(` to ${nodeId}`);
|
||||
});
|
||||
return centerTarget !== null && node.contains(centerTarget) && hasDirectEdge ? [index] : [];
|
||||
/** Each Map edge's id, ends and drawn stroke. */
|
||||
function mapEdgeStrokes(page: Page) {
|
||||
return page.locator(".map-canvas .react-flow__edge").evaluateAll((edges) => edges.map((edge) => {
|
||||
const match = /^Edge from (.+) to (.+)$/.exec(edge.getAttribute("aria-label") ?? "");
|
||||
const path = getComputedStyle(edge.querySelector(".transition-edge-path")!);
|
||||
return {
|
||||
id: edge.getAttribute("data-id") ?? "",
|
||||
from: match?.[1] ?? "",
|
||||
to: match?.[2] ?? "",
|
||||
stroke: path.stroke,
|
||||
strokeWidth: Number.parseFloat(path.strokeWidth),
|
||||
};
|
||||
}));
|
||||
const hoverTargetCount = options.hoverTargetCount ?? 1;
|
||||
expect(hoverableDimmedIndexes.length).toBeGreaterThanOrEqual(hoverTargetCount);
|
||||
// A card fades through its frame's --map-card-opacity (the node itself stays opaque over the
|
||||
// connectors). The property is not animated, so it reads what hover asks for at once.
|
||||
const cardOpacities = () => screens.evaluateAll((nodes) => Object.fromEntries(nodes.map((node) => [
|
||||
node.getAttribute("data-id") ?? "",
|
||||
getComputedStyle(node.querySelector(":scope > .canvas-active-frame")!).getPropertyValue("--map-card-opacity").trim(),
|
||||
])));
|
||||
const restingOpacities = await cardOpacities();
|
||||
let lastHoverTarget = dimmed.nth(hoverableDimmedIndexes[0]!);
|
||||
}
|
||||
|
||||
for (const index of hoverableDimmedIndexes.slice(0, hoverTargetCount)) {
|
||||
const hoverTarget = dimmed.nth(index);
|
||||
const hoverTargetId = await hoverTarget.getAttribute("data-id");
|
||||
expect(hoverTargetId).not.toBeNull();
|
||||
await hoverTarget.hover();
|
||||
await expect.poll(() => hoverTarget.locator(":scope > .canvas-active-frame").evaluate(
|
||||
(node) => Number.parseFloat(getComputedStyle(node).opacity),
|
||||
)).toBe(1);
|
||||
await expect(hoverTarget).toHaveCSS("filter", "none");
|
||||
const hoverSubject = page.locator(
|
||||
".map-canvas .react-flow__node-screen.graph-node-hover-subject",
|
||||
);
|
||||
await expect(hoverSubject).toHaveCount(1);
|
||||
await expect(hoverSubject).toHaveAttribute("data-id", hoverTargetId!);
|
||||
const allEdges = page.locator(".map-canvas .react-flow__edge");
|
||||
const directEdgeCount = await allEdges.evaluateAll((edges, nodeId) => edges.filter((edge) => {
|
||||
const label = edge.getAttribute("aria-label") ?? "";
|
||||
return label.startsWith(`Edge from ${nodeId} to `) || label.endsWith(` to ${nodeId}`);
|
||||
}).length, hoverTargetId!);
|
||||
expect(directEdgeCount).toBeGreaterThan(0);
|
||||
// The hovered screen and every screen it shares an edge with are marked related; nothing on
|
||||
// the map recedes while hovering, so the only changes are the subject ring, the incident
|
||||
// edges and the neighbours' frames.
|
||||
const neighbourIds = await allEdges.evaluateAll((edges, nodeId) => {
|
||||
const ids = new Set<string>([nodeId]);
|
||||
for (const edge of edges) {
|
||||
const match = /^Edge from (.+) to (.+)$/.exec(edge.getAttribute("aria-label") ?? "");
|
||||
if (!match) continue;
|
||||
if (match[1] === nodeId) ids.add(match[2]!);
|
||||
if (match[2] === nodeId) ids.add(match[1]!);
|
||||
}
|
||||
return [...ids].sort();
|
||||
}, hoverTargetId!);
|
||||
const brightNodes = page.locator(
|
||||
".map-canvas .react-flow__node-screen.graph-node-hover-related",
|
||||
);
|
||||
await expect.poll(() => brightNodes.evaluateAll((nodes) => (
|
||||
nodes.map((node) => node.getAttribute("data-id") ?? "").sort()
|
||||
))).toEqual(neighbourIds);
|
||||
const unrelated = page.locator(
|
||||
".map-canvas .react-flow__node-screen:not(.graph-node-hover-related):not(.canvas-node-exit)",
|
||||
);
|
||||
const unrelatedIds = await unrelated.evaluateAll((nodes) => nodes.map((node) => node.getAttribute("data-id") ?? ""));
|
||||
expect(unrelatedIds.length).toBeGreaterThan(0);
|
||||
const hoverOpacities = await cardOpacities();
|
||||
expect(unrelatedIds.map((id) => hoverOpacities[id])).toEqual(unrelatedIds.map((id) => restingOpacities[id]));
|
||||
expect(await unrelated.evaluateAll((nodes) => nodes.every((node) => getComputedStyle(node).filter === "none"))).toBe(true);
|
||||
await expect(page.locator(".map-canvas .screen-open-hint:visible")).toHaveCount(0);
|
||||
const activeEdges = page.locator(
|
||||
".map-canvas .react-flow__edge.graph-edge-hover-related",
|
||||
);
|
||||
await expect(activeEdges).toHaveCount(directEdgeCount);
|
||||
const activeEdgeLabels = await activeEdges.evaluateAll((edges) => (
|
||||
edges.map((edge) => edge.getAttribute("aria-label") ?? "")
|
||||
/**
|
||||
* A selected Map screen is ringed in the accent, its route turns accent and its transitions stay
|
||||
* accent while every other transition quiets to a hairline. No card fades. Hovering another card
|
||||
* rings it in grey beside the selection, with no tooltip, and darkens its own transitions;
|
||||
* hovering the selected card keeps its accent ring.
|
||||
*/
|
||||
async function expectMapSelectionRing(page: Page) {
|
||||
const screens = page.locator(".map-canvas .react-flow__node-screen:not(.canvas-node-exit)");
|
||||
const selected = page.locator(".map-canvas .react-flow__node-screen.selected:not(.canvas-node-exit)");
|
||||
await expect(selected).toHaveCount(1);
|
||||
const selectedId = (await selected.getAttribute("data-id"))!;
|
||||
const colors = await mapCanvasColors(page);
|
||||
await expect.poll(() => mapCardRing(selected)).toContain(colors.accent);
|
||||
await expect(selected.locator(".screen-node-title")).toHaveCSS("color", colors.accentStrong);
|
||||
// Nothing fades: every card and its frame stay at full strength.
|
||||
await expect.poll(() => screens.evaluateAll((nodes) => nodes.every((node) => (
|
||||
getComputedStyle(node).opacity === "1"
|
||||
&& getComputedStyle(node.querySelector(":scope > .canvas-active-frame")!).opacity === "1"
|
||||
&& ["", "1"].includes(getComputedStyle(node.querySelector(":scope > .canvas-active-frame")!).getPropertyValue("--map-card-opacity").trim())
|
||||
)))).toBe(true);
|
||||
const unselected = page.locator(".map-canvas .react-flow__node-screen:not(.selected):not(.canvas-node-exit)");
|
||||
expect(await unselected.evaluateAll((nodes, accent) => nodes.every((node) => (
|
||||
!getComputedStyle(node.querySelector(".screen-node-image :is(img, .image-placeholder)")!).boxShadow.includes(accent)
|
||||
)), colors.accent)).toBe(true);
|
||||
// The selection's transitions are accent and a little heavier; every other one is a hairline.
|
||||
const edges = await mapEdgeStrokes(page);
|
||||
const incident = edges.filter((edge) => edge.from === selectedId || edge.to === selectedId);
|
||||
const others = edges.filter((edge) => edge.from !== selectedId && edge.to !== selectedId);
|
||||
expect(incident.length).toBeGreaterThan(0);
|
||||
expect(others.length).toBeGreaterThan(0);
|
||||
expect(incident.every((edge) => edge.stroke === colors.accent && edge.strokeWidth === 2.5)).toBe(true);
|
||||
expect(others.every((edge) => edge.stroke === colors.quiet && edge.strokeWidth === 1)).toBe(true);
|
||||
await expect(page.locator(".map-canvas .react-flow__edge.graph-edge-quiet")).toHaveCount(others.length);
|
||||
|
||||
// Hover a card that shares no edge with the selection but has edges of its own.
|
||||
await expect(page.locator(".map-canvas.canvas-focus-animating")).toHaveCount(0);
|
||||
const neighbours = new Set(incident.flatMap((edge) => [edge.from, edge.to]));
|
||||
const hoverId = await unselected.evaluateAll((nodes, excluded) => nodes.find((node) => {
|
||||
const id = node.getAttribute("data-id") ?? "";
|
||||
const target = node.querySelector(".screen-screenshot-target")!.getBoundingClientRect();
|
||||
const hit = document.elementFromPoint(target.left + target.width / 2, target.top + target.height / 3);
|
||||
const linked = [...document.querySelectorAll(".map-canvas .react-flow__edge")].some((edge) => (
|
||||
(edge.getAttribute("aria-label") ?? "").split(/ (?:from|to) /).slice(1).includes(id)
|
||||
));
|
||||
expect(activeEdgeLabels.every((label) => (
|
||||
label.startsWith(`Edge from ${hoverTargetId} to `)
|
||||
|| label.endsWith(` to ${hoverTargetId}`)
|
||||
))).toBe(true);
|
||||
lastHoverTarget = hoverTarget;
|
||||
if (index !== hoverableDimmedIndexes.slice(0, hoverTargetCount).at(-1)) {
|
||||
await page.mouse.move(1, 1);
|
||||
await page.waitForTimeout(160);
|
||||
}
|
||||
return !excluded.includes(id) && linked && hit !== null && node.contains(hit);
|
||||
})?.getAttribute("data-id"), [...neighbours]);
|
||||
expect(hoverId).toBeTruthy();
|
||||
const hovered = page.locator(`.map-canvas .react-flow__node-screen[data-id="${hoverId}"]`);
|
||||
const target = hovered.locator(".screen-screenshot-target");
|
||||
const box = (await target.boundingBox())!;
|
||||
await target.hover({ position: { x: box.width / 2, y: box.height / 3 } });
|
||||
await expect(hovered).toHaveClass(/graph-node-hover-subject/);
|
||||
await expect.poll(() => mapCardRing(hovered)).toContain(colors.hoverRing);
|
||||
await expect.poll(() => mapCardRing(selected)).toContain(colors.accent);
|
||||
// Past the tooltip delay, nothing says Open in Inspector.
|
||||
await page.waitForTimeout(600);
|
||||
await expect(page.locator(".tooltip")).toHaveCount(0);
|
||||
// The hovered card's transitions darken to grey; the selection's stay accent; the rest stay quiet.
|
||||
const hovering = await mapEdgeStrokes(page);
|
||||
for (const edge of hovering) {
|
||||
if (edge.from === selectedId || edge.to === selectedId) expect(edge.stroke, edge.id).toBe(colors.accent);
|
||||
else if (edge.from === hoverId || edge.to === hoverId) expect(edge.stroke, edge.id).toBe(colors.hoverEdge);
|
||||
else expect(edge.stroke, edge.id).toBe(colors.quiet);
|
||||
}
|
||||
|
||||
// Hovering the selected card keeps its accent ring.
|
||||
const selectedTarget = selected.locator(".screen-screenshot-target");
|
||||
const selectedBox = (await selectedTarget.boundingBox())!;
|
||||
await selectedTarget.hover({ position: { x: selectedBox.width / 2, y: selectedBox.height / 3 } });
|
||||
await expect(selected).toHaveClass(/graph-node-hover-subject/);
|
||||
await expect.poll(() => mapCardRing(selected)).toContain(colors.accent);
|
||||
expect(await mapCardRing(selected)).not.toContain(colors.hoverRing);
|
||||
await expect.poll(() => mapCardRing(hovered)).not.toContain(colors.hoverRing);
|
||||
await page.mouse.move(1, 1);
|
||||
await expect.poll(async () => {
|
||||
const [selectedOpacity, dimmedOpacity] = await Promise.all([
|
||||
selected.locator(":scope > .canvas-active-frame").evaluate((node) => Number.parseFloat(getComputedStyle(node).opacity)),
|
||||
lastHoverTarget.locator(":scope > .canvas-active-frame").evaluate((node) => Number.parseFloat(getComputedStyle(node).opacity)),
|
||||
]);
|
||||
return dimmedOpacity < selectedOpacity;
|
||||
}).toBe(true);
|
||||
}
|
||||
|
||||
/** The camera chrome's theme button steps Auto → Dark → Light; press it until the page shows the option. */
|
||||
@@ -1529,6 +1514,59 @@ test("Esc closes the Inspector first, then deselects; arrows and hjkl walk the m
|
||||
await expect(selected).toHaveAttribute("data-id", child!);
|
||||
});
|
||||
|
||||
test("Return after the arrow keys opens the screen they reached, not the one clicked before, on the Map and on Screens", async ({ page }) => {
|
||||
await serveSyntheticWorkspace(page);
|
||||
const inspector = page.getByRole("complementary", { name: "Inspector panel" });
|
||||
const accent = await page.evaluate(() => {
|
||||
const probe = document.createElement("span");
|
||||
probe.style.color = "#0588f0";
|
||||
document.body.append(probe);
|
||||
const color = getComputedStyle(probe).color;
|
||||
probe.remove();
|
||||
return color;
|
||||
});
|
||||
|
||||
// Map: the click leaves the keyboard focus on the first screen's button; Return must not press it.
|
||||
await page.goto("/map?screen=area-0-screen-1");
|
||||
const selected = page.locator(".map-canvas .react-flow__node-screen.selected");
|
||||
await expect(selected).toHaveAttribute("data-id", "area-0-screen-1");
|
||||
await expectMapCameraAtRest(page);
|
||||
await selected.locator(".screen-screenshot-target").click();
|
||||
await expect(inspector).toBeVisible();
|
||||
await page.keyboard.press("Escape");
|
||||
await expect(inspector).toBeHidden();
|
||||
await page.keyboard.press("ArrowDown");
|
||||
await expect(selected).not.toHaveAttribute("data-id", "area-0-screen-1");
|
||||
const reached = (await selected.getAttribute("data-id"))!;
|
||||
// The ring went with the selection.
|
||||
const ring = (id: string) => page.locator(`.map-canvas .react-flow__node-screen[data-id="${id}"] .screen-node-image img`)
|
||||
.evaluate((image) => getComputedStyle(image).boxShadow);
|
||||
await expect.poll(() => ring(reached)).toContain(accent);
|
||||
await expect.poll(() => ring("area-0-screen-1")).not.toContain(accent);
|
||||
const reachedPath = (await selected.locator(".screen-node-title").textContent())!;
|
||||
await page.keyboard.press("Enter");
|
||||
await expect(inspector).toBeVisible();
|
||||
await expect(selected).toHaveAttribute("data-id", reached);
|
||||
await expect(page).toHaveURL(new RegExp(`screen=${reached}`));
|
||||
await expect(inspector).toContainText(reachedPath);
|
||||
|
||||
// Screens: the same walk, from a clicked card.
|
||||
await chooseCanvasView(page, "Screens");
|
||||
const grid = page.getByRole("main", { name: "Screens" });
|
||||
await grid.getByRole("button", { name: /^All/ }).click();
|
||||
const ids = await grid.locator(".screens-grid .screens-cell")
|
||||
.evaluateAll((elements) => elements.map((element) => element.getAttribute("data-screen-id")!));
|
||||
await grid.locator(`.screens-cell[data-screen-id="${ids[0]}"] .screen-screenshot-target`).click();
|
||||
await expect(inspector).toBeVisible();
|
||||
await page.keyboard.press("Escape");
|
||||
await expect(inspector).toBeHidden();
|
||||
await page.keyboard.press("ArrowRight");
|
||||
await expect(grid.locator(`.screens-cell[data-screen-id="${ids[1]}"] .screen-screenshot-card`)).toHaveClass(/selected/);
|
||||
await page.keyboard.press("Enter");
|
||||
await expect(inspector).toBeVisible();
|
||||
await expect(page).toHaveURL(new RegExp(`screen=${ids[1]}`));
|
||||
});
|
||||
|
||||
test("a held key stops when Esc, another key or a dialog takes the keyboard; a menu keeps its own arrows", async ({ page }) => {
|
||||
await page.goto("/map");
|
||||
const selected = page.locator(".map-canvas .react-flow__node-screen.selected");
|
||||
@@ -1955,7 +1993,7 @@ test("fits the visible Map screenshot frame to the capture's intrinsic ratio", a
|
||||
const selected = page.locator(".map-canvas .react-flow__node-screen.selected");
|
||||
const image = selected.locator(".screen-node-image img");
|
||||
await expect(image).toBeVisible();
|
||||
await expectMapScreenSelectionDimming(page);
|
||||
await expectMapSelectionRing(page);
|
||||
const pathStyle = await selected.locator(".screen-node-title").evaluate((element) => {
|
||||
const style = getComputedStyle(element);
|
||||
const bounds = element.getBoundingClientRect();
|
||||
@@ -2042,13 +2080,18 @@ async function hoverableMapScreen(candidates: Locator, room = 80) {
|
||||
return candidates.nth(index);
|
||||
}
|
||||
|
||||
test("hovering a Map screen fades nothing and says Open in Inspector in a tooltip below the card that keeps to it", async ({ page }) => {
|
||||
test("hovering a Map screen fades nothing, rings it in grey, darkens its transitions and shows no tooltip", async ({ page }) => {
|
||||
await serveSyntheticWorkspace(page);
|
||||
await page.goto("/map");
|
||||
const screens = page.locator(".map-canvas .react-flow__node-screen:not(.canvas-node-exit)");
|
||||
await expect(screens.first()).toBeVisible();
|
||||
await expectMapCameraAtRest(page);
|
||||
const colors = await mapCanvasColors(page);
|
||||
const resting = await mapCardOpacities(page);
|
||||
// With nothing selected no transition is quiet: they keep their own colours.
|
||||
await expect(page.locator(".map-canvas .react-flow__edge.graph-edge-quiet")).toHaveCount(0);
|
||||
const restingEdges = await mapEdgeStrokes(page);
|
||||
expect(restingEdges.some((edge) => edge.stroke === colors.quiet)).toBe(false);
|
||||
// A screen at one end of a secondary transition, which rests a little faded.
|
||||
const secondaryEnds = await page.locator(".map-canvas .react-flow__edge.graph-edge-secondary").evaluateAll((edges) => (
|
||||
[...new Set(edges.flatMap((edge) => /^Edge from (.+) to (.+)$/.exec(edge.getAttribute("aria-label") ?? "")?.slice(1) ?? []))]
|
||||
@@ -2057,42 +2100,34 @@ test("hovering a Map screen fades nothing and says Open in Inspector in a toolti
|
||||
const node = await hoverableMapScreen(page.locator(
|
||||
secondaryEnds.map((id) => `.map-canvas .react-flow__node-screen[data-id="${id}"]`).join(", "),
|
||||
));
|
||||
const id = (await node.getAttribute("data-id"))!;
|
||||
const target = node.locator(".screen-screenshot-target");
|
||||
const heading = node.locator(".screen-node-heading");
|
||||
// The tooltip says what a click does; no native title tooltip joins it.
|
||||
// No native title tooltip either; the heading names the screen.
|
||||
await expect(target).not.toHaveAttribute("title");
|
||||
// Near the card's top, so the pan below keeps the pointer on it.
|
||||
const box = (await target.boundingBox())!;
|
||||
await target.hover({ position: { x: box.width / 2, y: box.height / 4 } });
|
||||
await expect(page.locator(".connection-canvas-surface.canvas-hovering")).toHaveCount(1);
|
||||
const tooltip = page.locator(".tooltip", { hasText: "Open in Inspector" });
|
||||
await expect(tooltip).toBeVisible();
|
||||
await expect.poll(() => mapCardRing(node)).toContain(colors.hoverRing);
|
||||
expect(await mapCardRing(node)).not.toContain(colors.accent);
|
||||
// Past the tooltip delay, nothing covers or labels the card.
|
||||
await page.waitForTimeout(600);
|
||||
await expect(page.locator(".tooltip")).toHaveCount(0);
|
||||
await expect(page.locator(".map-canvas .screen-open-hint:visible")).toHaveCount(0);
|
||||
const related = await page.locator(".map-canvas .react-flow__node-screen.graph-node-hover-related")
|
||||
.evaluateAll((nodes) => nodes.map((element) => element.getAttribute("data-id") ?? ""));
|
||||
const unrelated = Object.keys(resting).filter((id) => !related.includes(id));
|
||||
const unrelated = Object.keys(resting).filter((other) => !related.includes(other));
|
||||
expect(unrelated.length).toBeGreaterThan(0);
|
||||
const hovering = await mapCardOpacities(page);
|
||||
expect(unrelated.map((id) => hovering[id])).toEqual(unrelated.map((id) => resting[id]));
|
||||
await expect(page.locator(".map-canvas .screen-open-hint:visible")).toHaveCount(0);
|
||||
// The transitions into and out of it come fully up, the secondary one too.
|
||||
expect(unrelated.map((other) => hovering[other])).toEqual(unrelated.map((other) => resting[other]));
|
||||
// The transitions into and out of it come fully up in a darker grey, the secondary one too; the rest stay as they were.
|
||||
const incident = page.locator(".map-canvas .react-flow__edge.graph-edge-hover-related");
|
||||
await expect(incident.and(page.locator(".graph-edge-secondary"))).not.toHaveCount(0);
|
||||
await expect.poll(() => incident.evaluateAll((edges) => edges.every((edge) => getComputedStyle(edge).opacity === "1"))).toBe(true);
|
||||
// The route heads a Map card, so the bubble sits below the screenshot, clear of both.
|
||||
const clearance = async () => {
|
||||
const [bubble, card, title] = await Promise.all([tooltip.boundingBox(), target.boundingBox(), heading.boundingBox()]);
|
||||
if (!bubble || !card || !title) return Number.NaN;
|
||||
const headingOverlap = bubble.y < title.y + title.height && title.y < bubble.y + bubble.height
|
||||
&& bubble.x < title.x + title.width && title.x < bubble.x + bubble.width;
|
||||
return headingOverlap ? -1 : bubble.y - (card.y + card.height);
|
||||
};
|
||||
expect(await clearance()).toBeGreaterThan(0);
|
||||
// Panning with the pointer still on the card moves the card by transform; the bubble follows it
|
||||
// rather than staying behind over the screenshot.
|
||||
const before = await target.boundingBox();
|
||||
await page.mouse.wheel(0, 40);
|
||||
await expect.poll(async () => (await target.boundingBox())!.y).toBeLessThan(before!.y - 10);
|
||||
await expect.poll(clearance).toBeGreaterThan(0);
|
||||
const hoverEdges = await mapEdgeStrokes(page);
|
||||
for (const edge of hoverEdges) {
|
||||
if (edge.from === id || edge.to === id) expect(edge.stroke, edge.id).toBe(colors.hoverEdge);
|
||||
else expect(edge.stroke, edge.id).toBe(restingEdges.find((resting) => resting.id === edge.id)!.stroke);
|
||||
}
|
||||
});
|
||||
|
||||
test("hovering a Map screen the Changes filter muted brings it and its neighbours back up, and nothing else", async ({ page }) => {
|
||||
@@ -2325,9 +2360,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);
|
||||
@@ -5414,3 +5449,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);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
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("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);
|
||||
});
|
||||
@@ -21,6 +21,60 @@ test("import closure attributes component and platform-source changes to depende
|
||||
assert.deepEqual(selectedPaths(plan({base:files,platform:"android",changes:[{status:"modified",path:"src/theme.ios.ts"}]})), []);
|
||||
});
|
||||
|
||||
test("tsconfig paths with several single-directory aliases resolve by their longest prefix, as TypeScript does", () => {
|
||||
const tsconfig = JSON.stringify({ extends: "expo/tsconfig.base", compilerOptions: { paths: { "@/*": ["./src/*"], "@/assets/*": ["./assets/*"] } } });
|
||||
const files = [["tsconfig.json", tsconfig], ["src/app/one.tsx", 'import { tint } from "@/theme"; import icon from "@/assets/icon"; export default () => [tint, icon];'],
|
||||
["src/app/two.tsx", page], ["src/theme.ts", "export const tint = 'blue';"], ["assets/icon.ts", "export default 'icon';"], ["src/assets/icon.ts", "export default 'other';"]];
|
||||
const result = plan({ base: files, changes: [{ status: "modified", path: "assets/icon.ts" }] });
|
||||
assert.deepEqual(selectedPaths(result), ["/one"]);
|
||||
assert.equal(result.surfaces.flatMap(row => row.reasons ?? []).some(reason => /module resolution/.test(reason)), false);
|
||||
// `@/assets/icon` is `assets/icon.ts`, not `src/assets/icon.ts`, so an edit to the latter changes nothing.
|
||||
assert.deepEqual(selectedPaths(plan({ base: files, changes: [{ status: "modified", path: "src/assets/icon.ts" }] })), []);
|
||||
assert.deepEqual(selectedPaths(plan({ base: files, changes: [{ status: "modified", path: "src/theme.ts" }] })), ["/one"]);
|
||||
});
|
||||
|
||||
test("an alias import that finds no file is local code the plan cannot follow, not a package", () => {
|
||||
const tsconfig = JSON.stringify({ compilerOptions: { paths: { "@/*": ["./src/*"], "@icons/*": ["./src/icons/*"] } } });
|
||||
const files = [["tsconfig.json", tsconfig], ["src/app/one.tsx", 'import Logo from "@icons/logo"; export default () => Logo;'], ["src/app/two.tsx", page], ["src/icons/logo.svg", "<svg/>"]];
|
||||
const result = plan({ base: files, changes: [{ status: "modified", path: "src/icons/logo.svg" }] });
|
||||
assert.ok(result.unresolved.some(message => message.includes("@icons/logo")), JSON.stringify(result.unresolved));
|
||||
assert.ok(selectedPaths(result).includes("/one"));
|
||||
});
|
||||
|
||||
test("tsconfig aliases: single-directory prefix keys are followed; anything TypeScript would read differently is not", async () => {
|
||||
const { readTsconfigAlias, resolveTsconfigAlias } = await tsImport("../../src/shared/tsconfig-alias.ts", import.meta.url);
|
||||
const read = paths => readTsconfigAlias(JSON.stringify({ compilerOptions: { paths } }));
|
||||
for (const paths of [{ "*": ["src/*"] }, { "@*": ["src/*"] }, { "@/x": ["src/x"] }, { "@/*/x": ["src/*"] }, { "./*": ["src/*"] }, { "/*": ["src/*"] },
|
||||
{ "@/*": ["src/*", "lib/*"] }, { "@/*": ["../src/*"] }, { "@/*": ["./src/./lib/*"] }, { "@/*": ["src/*.ts"] }]) {
|
||||
assert.ok(read(paths).unsupported, JSON.stringify(paths));
|
||||
}
|
||||
const alias = read({ "@/*": ["./src/*"], "@/assets/*": ["./assets/*"], "~/*": ["./*"] });
|
||||
assert.equal(alias.unsupported, undefined);
|
||||
assert.equal(resolveTsconfigAlias(alias, "@/assets/icon"), "assets/icon");
|
||||
assert.equal(resolveTsconfigAlias(alias, "@/assets"), "src/assets");
|
||||
assert.equal(resolveTsconfigAlias(alias, "~/theme"), "theme");
|
||||
assert.equal(resolveTsconfigAlias(alias, "react"), undefined);
|
||||
assert.equal(resolveTsconfigAlias(alias, "@/a/../b"), "src/b");
|
||||
assert.equal(resolveTsconfigAlias(alias, "@/components/"), "src/components");
|
||||
});
|
||||
|
||||
test("a platform file wins over a plain file of another extension, as Metro resolves it", () => {
|
||||
const files = [["app/one.tsx", 'import Card from "../src/card"; export default () => Card;'], ["app/two.tsx", page],
|
||||
["src/card.tsx", "export default 1;"], ["src/card.ios.ts", "export default 2;"]];
|
||||
assert.deepEqual(selectedPaths(plan({ base: files, changes: [{ status: "modified", path: "src/card.ios.ts" }] })), ["/one"]);
|
||||
assert.deepEqual(selectedPaths(plan({ base: files, changes: [{ status: "modified", path: "src/card.tsx" }] })), []);
|
||||
assert.deepEqual(selectedPaths(plan({ base: files, platform: "android", changes: [{ status: "modified", path: "src/card.tsx" }] })), ["/one"]);
|
||||
});
|
||||
|
||||
test("with a root baseUrl, a bare specifier that names a project file is a dependency; one that does not is a package", () => {
|
||||
const tsconfig = JSON.stringify({ compilerOptions: { baseUrl: ".", paths: { "components/*": ["./src/components/*"] } } });
|
||||
const files = [["tsconfig.json", tsconfig], ["app/one.tsx", 'import theme from "theme"; import { View } from "react-native"; export default () => [theme, View];'],
|
||||
["app/two.tsx", page], ["theme.ts", "export default 1;"]];
|
||||
const result = plan({ base: files, changes: [{ status: "modified", path: "theme.ts" }] });
|
||||
assert.deepEqual(selectedPaths(result), ["/one"]);
|
||||
assert.deepEqual(result.unresolved, []);
|
||||
});
|
||||
|
||||
test("route additions and removals are independently inventoried at each commit", () => {
|
||||
const result = plan({base:[["app/removed.tsx",page]],head:[["app/added.tsx",page]]});
|
||||
assert.deepEqual(selectedPaths(result,"base"), ["/removed"]);
|
||||
|
||||
@@ -168,7 +168,7 @@ test("follows the create-expo-app alias @/* -> ./* without a diagnostic", () =>
|
||||
|
||||
test("unresolved object hrefs and unsupported custom aliases remain explicit diagnostics", () => {
|
||||
const result = graph([surface("one"),surface("two")], {
|
||||
"tsconfig.json": JSON.stringify({compilerOptions:{paths:{"~/*":["src/*"]}}}),
|
||||
"tsconfig.json": JSON.stringify({compilerOptions:{paths:{"~/*":["src/*","lib/*"]}}}),
|
||||
"src/app/one.tsx": "import {router} from 'expo-router';import {Screen} from '~/screen';export default function One(){router.push({pathname:getPath()});return <Screen/>;}",
|
||||
});
|
||||
assert.deepEqual(result.edges, []);
|
||||
|
||||
@@ -31,8 +31,8 @@ export type ScreenScreenshotCardProps = {
|
||||
loading?: "eager" | "lazy";
|
||||
leading?: ReactNode;
|
||||
trailing?: ReactNode;
|
||||
/** Where the "Open in Inspector" tooltip sits: away from the route heading, which is above the screenshot on the Map. */
|
||||
tooltipPlacement?: "top" | "bottom";
|
||||
/** Say "Open in Inspector" in a tooltip over the screenshot (Screens). The Map's cards go without. */
|
||||
inspectorTooltip?: boolean;
|
||||
/** Short lines about the screen, inside the card after its screenshot (Screens: how it was reached, where else it changed). */
|
||||
note?: ReactNode;
|
||||
onClick: MouseEventHandler<HTMLButtonElement>;
|
||||
@@ -92,10 +92,10 @@ export function ScreenScreenshotCard(props: ScreenScreenshotCardProps) {
|
||||
free of block children. */}
|
||||
<span className="screen-screenshot-slot">
|
||||
{props.leading}
|
||||
{/* With a pointer, what a click does is said once, zoom-independent, in the shared tooltip
|
||||
after its usual delay; the selected screen is already in the Inspector. The button has
|
||||
no title of its own, so no native tooltip joins it; the heading names the screen. */}
|
||||
<Tooltip label="Open in Inspector" placement={props.tooltipPlacement ?? "top"} disabled={Boolean(props.selected)}>
|
||||
{/* On Screens, with a pointer, what a click does is said once in the shared tooltip after
|
||||
its usual delay; the selected screen is already in the Inspector. The button has no
|
||||
title of its own, so no native tooltip joins it; the heading names the screen. */}
|
||||
<Tooltip label="Open in Inspector" placement="top" disabled={props.inspectorTooltip === false || Boolean(props.selected)}>
|
||||
<button
|
||||
type="button"
|
||||
className="screen-screenshot-target"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { GitCompareArrows, Keyboard, LayoutGrid, Map, Search } from "lucide-react";
|
||||
import { type CSSProperties } from "react";
|
||||
import { type CSSProperties, useLayoutEffect, useState } from "react";
|
||||
import { Tooltip } from "../shared/tooltip";
|
||||
import { useCanvasVisibleFrame } from "./visible-frame-provider";
|
||||
import { CANVAS_NUMBER_KEYS, formatShortcut, SHORTCUTS } from "../../utils/shortcuts";
|
||||
@@ -29,20 +29,48 @@ type CanvasToolbarProps = {
|
||||
onOpenShortcuts: () => void;
|
||||
};
|
||||
|
||||
/** 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]);
|
||||
// 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.
|
||||
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.
|
||||
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">
|
||||
|
||||
@@ -12,7 +12,8 @@ export type TransitionEdgeData = {
|
||||
transitionCount: number;
|
||||
active: boolean;
|
||||
primary: boolean;
|
||||
dimmed: boolean;
|
||||
/** Another screen is selected: the edge steps back to a hairline, so the selection's own stand out. */
|
||||
quiet: boolean;
|
||||
sourceOnly?: boolean;
|
||||
previousSource?: boolean;
|
||||
tooltip?: string;
|
||||
@@ -39,9 +40,10 @@ export function TransitionEdge(props: EdgeProps<TransitionGraphEdge>) {
|
||||
curvature: 0.24,
|
||||
});
|
||||
const emphasized = Boolean(props.data?.active || props.selected || hovered);
|
||||
const dimmed = Boolean(props.data?.dimmed && !emphasized);
|
||||
const quiet = Boolean(props.data?.quiet && !emphasized);
|
||||
const stroke = emphasized
|
||||
? "var(--accent)"
|
||||
: quiet ? "var(--border-subtle)"
|
||||
: props.data?.previousSource ? "var(--danger)" : props.data?.primary ? "var(--graph-line)" : "var(--graph-line-soft)";
|
||||
|
||||
return (
|
||||
@@ -66,9 +68,8 @@ export function TransitionEdge(props: EdgeProps<TransitionGraphEdge>) {
|
||||
style={{
|
||||
...props.style,
|
||||
stroke,
|
||||
strokeWidth: emphasized ? 2.2 : props.data?.primary ? 1.15 : 0.9,
|
||||
strokeWidth: emphasized ? 2.5 : quiet ? 1 : props.data?.primary ? 1.15 : 0.9,
|
||||
strokeDasharray: props.data?.sourceOnly ? "6 5" : emphasized || props.data?.primary ? undefined : "4 7",
|
||||
opacity: dimmed ? 0.12 : 1,
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
|
||||
@@ -107,6 +107,13 @@ export function ZoomBridge(props: {
|
||||
publishZoom(Math.round(zoom * 100) / 100);
|
||||
}, [props.cameraReady, zoom]);
|
||||
|
||||
// What a stroke that must stay legible at any zoom divides by (the Map's selection ring). It
|
||||
// moves in quarter-octave steps, so a pinch restyles the canvas a few times, not every frame.
|
||||
const strokeZoom = 2 ** (Math.round(Math.log2(zoom) * 4) / 4);
|
||||
useEffect(() => {
|
||||
canvas?.style.setProperty("--canvas-zoom", String(strokeZoom));
|
||||
}, [canvas, strokeZoom]);
|
||||
|
||||
useEffect(() => {
|
||||
// Re-registering after selection changes publishes the new capability to the zoom menu.
|
||||
// Reading through getNodes keeps the commands themselves on the latest canvas snapshot.
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
import {
|
||||
useCallback, useRef, useSyncExternalStore, type CSSProperties, type KeyboardEvent, type PointerEvent, type RefObject,
|
||||
} from "react";
|
||||
import {
|
||||
clampInspectorWidth, inspectorWidthBounds, INSPECTOR_WIDTH_MAX, INSPECTOR_WIDTH_MIN, INSPECTOR_WIDTH_STEP,
|
||||
setInspectorWidth, 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);
|
||||
}
|
||||
|
||||
function widestWidth(): number {
|
||||
return inspectorWidthBounds(window.innerWidth, uiScale()).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(subscribeToWindow, 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: inspectorWidthBounds(window.innerWidth, scale), 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 = inspectorWidthBounds(window.innerWidth, uiScale());
|
||||
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 };
|
||||
}
|
||||
@@ -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
|
||||
@@ -84,7 +88,8 @@ export function RightPanel(props: RightPanelProps) {
|
||||
// button leads the row instead, away from the screen stepper's arrows. Theme and full screen
|
||||
// live in the canvas camera controls.
|
||||
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}
|
||||
|
||||
@@ -535,6 +535,8 @@
|
||||
.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;
|
||||
|
||||
@@ -31,6 +31,7 @@ import { arrowsOwnedBy, mapKeyDirection, mapKeyEntry, mapKeyTarget, type MapKeyD
|
||||
import { createKeyHold } from "../../utils/key-hold";
|
||||
|
||||
const HOVER_CLEAR_DELAY = 180;
|
||||
const PRESSABLE = 'button, a, summary, [role="button"]';
|
||||
const MAP_LAYOUT_REVISION = "flat-v1";
|
||||
const MAP_FIT_VIEW_OPTIONS = {
|
||||
padding: 0.04,
|
||||
@@ -115,8 +116,8 @@ function ScreenNodeCard({ data, selected }: NodeProps<ScreenGraphNode>) {
|
||||
imageHeight={data.screenshotSize?.imageHeight ?? data.frame.screen.height}
|
||||
placeholderSize={data.frame.screen}
|
||||
loading="lazy"
|
||||
// The route heads the card, so the tooltip goes below it.
|
||||
tooltipPlacement="bottom"
|
||||
// The ring says which screen is which; a click opening it in the Inspector needs no tooltip.
|
||||
inspectorTooltip={false}
|
||||
leading={<Handle type="target" position={horizontal ? Position.Left : Position.Top} className="graph-handle" />}
|
||||
trailing={<Handle type="source" position={horizontal ? Position.Right : Position.Bottom} className="graph-handle" />}
|
||||
onMouseEnter={() => data.onHover(data.screen.id)}
|
||||
@@ -342,8 +343,9 @@ function projectionElements(
|
||||
const edges: TransitionGraphEdge[] = structure.groups.map((group) => {
|
||||
const hierarchyEdge = structure.primaryEdgeKeys.has(group.key);
|
||||
const connected = group.from === selectedScreenId || group.to === selectedScreenId;
|
||||
const dimmed = false;
|
||||
const active = connected;
|
||||
// While a screen is selected, every other transition quiets to a hairline; cards never fade.
|
||||
const quiet = Boolean(selectedScreenId) && !connected;
|
||||
const sourceOnly = group.transitionIds.length === 0 && Boolean(group.sourceEdges?.length);
|
||||
const previousSource = group.sourceRevision === "baseline";
|
||||
const removed = previousSource || (!group.synthetic && diff?.screens.get(group.to)?.status === "removed");
|
||||
@@ -356,25 +358,26 @@ function projectionElements(
|
||||
const primary = hierarchyEdge;
|
||||
const stroke = active
|
||||
? "var(--accent)"
|
||||
: quiet ? "var(--border-subtle)"
|
||||
: removed ? "var(--danger)" : primary ? "var(--graph-line)" : "var(--graph-line-soft)";
|
||||
return {
|
||||
id: edgeElementId(group.key),
|
||||
source: group.from,
|
||||
target: group.to,
|
||||
type: "transition",
|
||||
className: `${hierarchyEdge ? "graph-edge-primary" : "graph-edge-secondary"}${sourceOnly ? " graph-edge-source" : ""}${previousSource ? " graph-edge-source-baseline" : ""}${active ? " graph-edge-active" : ""}${dimmed ? " graph-edge-dimmed" : ""}`,
|
||||
className: `${hierarchyEdge ? "graph-edge-primary" : "graph-edge-secondary"}${sourceOnly ? " graph-edge-source" : ""}${previousSource ? " graph-edge-source-baseline" : ""}${active ? " graph-edge-active" : ""}${quiet ? " graph-edge-quiet" : ""}`,
|
||||
markerEnd: {
|
||||
type: MarkerType.ArrowClosed,
|
||||
width: active || hierarchyEdge ? 14 : 11,
|
||||
height: active || hierarchyEdge ? 14 : 11,
|
||||
width: active || (hierarchyEdge && !quiet) ? 14 : 11,
|
||||
height: active || (hierarchyEdge && !quiet) ? 14 : 11,
|
||||
color: stroke,
|
||||
},
|
||||
style: {
|
||||
stroke,
|
||||
strokeWidth: active ? 2.2 : hierarchyEdge ? 1.15 : 0.9,
|
||||
strokeWidth: active ? 2.5 : quiet ? 1 : hierarchyEdge ? 1.15 : 0.9,
|
||||
strokeDasharray: !hierarchyEdge && !active && !removed ? "4 7" : undefined,
|
||||
},
|
||||
data: { label, transitionCount: group.transitionIds.length, active, primary, dimmed, sourceOnly, previousSource, ...(tooltip ? { tooltip } : {}) },
|
||||
data: { label, transitionCount: group.transitionIds.length, active, primary, quiet, sourceOnly, previousSource, ...(tooltip ? { tooltip } : {}) },
|
||||
// React Flow renders a positive edge z-index above root nodes. Keep every connection in
|
||||
// the base edge layer so selected/highlighted paths still pass behind screen imagery.
|
||||
zIndex: 0,
|
||||
@@ -433,7 +436,7 @@ function sameTransitionEdge(a: TransitionGraphEdge, b: TransitionGraphEdge) {
|
||||
&& a.data?.transitionCount === b.data?.transitionCount
|
||||
&& a.data?.active === b.data?.active
|
||||
&& a.data?.primary === b.data?.primary
|
||||
&& a.data?.dimmed === b.data?.dimmed;
|
||||
&& a.data?.quiet === b.data?.quiet;
|
||||
}
|
||||
|
||||
function reuseUnchangedElements(
|
||||
@@ -557,7 +560,8 @@ function ConnectionCanvas(props: MapViewProps) {
|
||||
}, [applyHover]);
|
||||
// The arrow keys (or h j k l) walk the map from the selected screen: along an edge in the
|
||||
// layout's flow, across to the neighbour on the same rank otherwise. With nothing selected they
|
||||
// enter the map at its edge, as on the Screens page. A held key keeps walking.
|
||||
// enter the map at its edge, as on the Screens page. A held key keeps walking. Return opens the
|
||||
// selection in the Inspector.
|
||||
const { selectedScreenId } = props;
|
||||
const selectedRef = useRef(selectedScreenId);
|
||||
selectedRef.current = selectedScreenId;
|
||||
@@ -568,22 +572,39 @@ function ConnectionCanvas(props: MapViewProps) {
|
||||
if (!structure) return undefined;
|
||||
return from ? mapKeyTarget(structure, from, direction) : mapKeyEntry(structure, direction);
|
||||
};
|
||||
// A click leaves the keyboard focus on the clicked screen's button, where Return would press it
|
||||
// and open that screen again. A walk lets go of it, so Return reaches the screen walked to.
|
||||
const walkTo = (id: string) => {
|
||||
const focused = document.activeElement;
|
||||
if (focused instanceof HTMLElement && surfaceRef.current?.contains(focused)) focused.blur();
|
||||
selectScreen(id);
|
||||
};
|
||||
const onKeyDown = (event: KeyboardEvent) => {
|
||||
hold.interrupt(event);
|
||||
if (event.repeat && hold.holding(event.code)) { event.preventDefault(); return; }
|
||||
if (event.defaultPrevented || !shortcutsLive(event) || arrowsOwnedBy(event.target)) return;
|
||||
if (event.key === "Enter") {
|
||||
// A focused button or link keeps its own Return; elsewhere on the page it opens the selection.
|
||||
const target = event.target instanceof Element ? event.target : null;
|
||||
const selected = selectedRef.current;
|
||||
if (!selected || event.isComposing || event.metaKey || event.ctrlKey || event.altKey || event.shiftKey) return;
|
||||
if (target && target !== document.body && (target.closest(PRESSABLE) || !surfaceRef.current?.contains(target))) return;
|
||||
event.preventDefault();
|
||||
selectScreen(selected);
|
||||
return;
|
||||
}
|
||||
const direction = mapKeyDirection(event);
|
||||
if (!direction) return;
|
||||
if (!structureRef.current) return;
|
||||
event.preventDefault();
|
||||
let at = move(direction, selectedRef.current);
|
||||
if (!at) return;
|
||||
selectScreen(at);
|
||||
walkTo(at);
|
||||
hold.begin(event.code, () => {
|
||||
const target = move(direction, at);
|
||||
if (!target) return false;
|
||||
at = target;
|
||||
selectScreen(target);
|
||||
walkTo(target);
|
||||
return true;
|
||||
});
|
||||
};
|
||||
@@ -636,9 +657,6 @@ function ConnectionCanvas(props: MapViewProps) {
|
||||
.sort((left, right) => left.depth - right.depth || left.y - right.y || left.x - right.x || left.index - right.index)
|
||||
.map(({ id }) => id), [layout.nodes]);
|
||||
const phone = usePhoneLayout();
|
||||
const selectedScreenVisible = Boolean(
|
||||
props.selectedScreenId && layout.nodes.some((node) => node.id === props.selectedScreenId),
|
||||
);
|
||||
if (props.map.screens.length === 0) {
|
||||
const blockers = props.map.gaps.filter((gap) => gap.status === "open" && !gap.screenId).map((gap) => gap.message);
|
||||
return (
|
||||
@@ -656,10 +674,7 @@ function ConnectionCanvas(props: MapViewProps) {
|
||||
<div ref={surfaceRef} className="connection-canvas-surface map-surface">
|
||||
<CanvasStage
|
||||
ariaLabel="Screen map"
|
||||
className={[
|
||||
"map-canvas",
|
||||
selectedScreenVisible ? "screen-selection-active" : "",
|
||||
].filter(Boolean).join(" ")}
|
||||
className="map-canvas"
|
||||
nodes={layout.nodes}
|
||||
edges={layout.edges}
|
||||
nodeTypes={NODE_TYPES}
|
||||
|
||||
+88
-43
@@ -110,7 +110,6 @@
|
||||
/* How far an item the Changes filter does not cover falls back. Low enough to read as
|
||||
background at a glance, high enough that the canvas keeps its shape. */
|
||||
--dim-out: 0.35;
|
||||
--hover-neighbour-frame: color-mix(in srgb, var(--accent) 55%, var(--border-subtle));
|
||||
--shadow-xs: 0 1px 3px rgba(0, 0, 0, 0.025), 0 1px 2px rgba(0, 0, 0, 0.05);
|
||||
--shadow-md: 0 10px 20px rgba(0, 0, 0, 0.1), 0 3px 6px rgba(0, 0, 0, 0.05);
|
||||
|
||||
@@ -461,6 +460,8 @@ code {
|
||||
--graph-line-soft: #c5c7ce;
|
||||
/* One flat fill for a group — no border, no second tone inside it. */
|
||||
--canvas-group: #f5f5f6;
|
||||
/* The ring a hovered Map card takes: a step past the border scale, short of the connectors. */
|
||||
--hover-ring: #b9bbc6;
|
||||
color: var(--text);
|
||||
background: var(--screen);
|
||||
}
|
||||
@@ -480,6 +481,7 @@ code {
|
||||
--graph-line: #696e77;
|
||||
--graph-line-soft: #3f4349;
|
||||
--canvas-group: #18191b;
|
||||
--hover-ring: #5a6169;
|
||||
}
|
||||
/* The canvas is a fixed map: dragging anywhere pans, while clicking an object selects it. */
|
||||
.graph-canvas .canvas-tool-pan,
|
||||
@@ -499,27 +501,14 @@ code {
|
||||
.graph-canvas .transition-edge-hitarea { cursor: pointer; pointer-events: stroke; }
|
||||
.graph-canvas .transition-edge-path { transition: stroke 100ms ease, stroke-width 100ms ease, opacity 140ms ease; }
|
||||
.graph-canvas .graph-edge-secondary { opacity: 0.72; }
|
||||
.graph-canvas .graph-edge-dimmed { opacity: 0.14; }
|
||||
.graph-canvas .graph-edge-active { opacity: 1; }
|
||||
.graph-canvas .react-flow__node { transition: opacity 180ms ease, filter 180ms ease; }
|
||||
.graph-canvas .canvas-focus-animating .react-flow__node { transition: none; }
|
||||
/* Focus: what the chosen state does not cover only steps back, so the map is still readable. */
|
||||
.graph-canvas .react-flow__node.graph-node-muted { opacity: var(--dim-out); --map-card-opacity: var(--dim-out); }
|
||||
/* A route-selected screenshot stays visually anchored while the surrounding screenshots recede.
|
||||
They fade as focus dims them, by opacity alone: a filter would grey the card's opaque backing.
|
||||
Summary cards retain their normal contrast so the selected screen's semantic context is legible. */
|
||||
.map-canvas.screen-selection-active .react-flow__node-screen:not(.selected) {
|
||||
opacity: var(--dim-out);
|
||||
--map-card-opacity: var(--dim-out);
|
||||
}
|
||||
.map-canvas.screen-selection-active .react-flow__node-screen:not(.selected):hover,
|
||||
.map-canvas.screen-selection-active .react-flow__node-screen:not(.selected):focus-within {
|
||||
opacity: 1;
|
||||
--map-card-opacity: 1;
|
||||
}
|
||||
/* Hover never recedes anything, but where focus or a selection has already dimmed the map, the
|
||||
hovered screen and the screens it connects to come back up, with the transitions between them,
|
||||
so the neighbourhood reads. These come after both dimming rules so the pointer's context wins. */
|
||||
/* Hover never recedes anything, but where the Changes filter has dimmed the map, the hovered
|
||||
screen and the screens it connects to come back up, with the transitions between them, so the
|
||||
neighbourhood reads. These come after the dimming rule so the pointer's context wins. */
|
||||
.connection-canvas-surface.canvas-hovering .react-flow__node-screen.graph-node-hover-related {
|
||||
opacity: 1;
|
||||
--map-card-opacity: 1;
|
||||
@@ -687,7 +676,7 @@ code {
|
||||
/* Hover and selection draw a 3px ring in the accent colour: the 1px border recoloured plus a 2px
|
||||
shadow outside it, so the image keeps its size (a thicker border would shrink the picture inside
|
||||
its box). Changed screens keep their own colour at the same weight: the diff rules below win on
|
||||
specificity. */
|
||||
specificity. The Map leaves the border to the status and rings the card from outside instead. */
|
||||
.screen-node-image:hover img,
|
||||
.screen-screenshot-card.selected .screen-node-image img { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
|
||||
.screen-node-image:hover > .image-placeholder,
|
||||
@@ -707,8 +696,8 @@ code {
|
||||
border-radius: 17px;
|
||||
pointer-events: none;
|
||||
}
|
||||
/* Selection needs no ring: the canvas dims every other screen. The highlight ring stays for the
|
||||
transient pointer-over state that panels project onto the canvas. */
|
||||
/* Selection needs no overlay: the Map rings the screenshot and Screens frames the card. The
|
||||
highlight ring stays for the transient pointer-over state that panels project onto the canvas. */
|
||||
.canvas-active-frame.is-highlighted::after {
|
||||
border-color: var(--accent);
|
||||
box-shadow: 0 0 24px color-mix(in srgb, var(--accent) 24%, transparent);
|
||||
@@ -723,10 +712,9 @@ code {
|
||||
pointer-events: none;
|
||||
}
|
||||
/* A screen's handles are ports on its frame: they take the frame colour, whether that is the
|
||||
status colour of a changed screen or the accent of a hovered or selected one, and a ring in
|
||||
the canvas colour keeps them legible as connection points on the border. */
|
||||
status colour of a changed screen or the accent of a selected one, and a ring in the canvas
|
||||
colour keeps them legible as connection points on the border. */
|
||||
.screen-screenshot-card { --screen-frame: var(--graph-line); }
|
||||
.screen-screenshot-card:has(.screen-node-image:hover),
|
||||
.screen-screenshot-card.selected,
|
||||
.screen-screenshot-card.highlighted { --screen-frame: var(--accent); }
|
||||
.screen-screenshot-card:is(.diff-added, .diff-modified, .diff-removed) { --screen-frame: var(--diff); }
|
||||
@@ -738,23 +726,48 @@ code {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
/* Hover is transient canvas state. Nothing recedes: the pointer's screen gets its ring, the
|
||||
transitions into and out of it turn accent, and the screens at their other ends take a tinted
|
||||
frame, so the neighbourhood reads without the rest of the map changing. Only the symmetric
|
||||
difference of related nodes/edges receives a class, avoiding a React commit across the graph. */
|
||||
.connection-canvas-surface.canvas-hovering .graph-edge-hover-related .transition-edge-path {
|
||||
stroke: var(--accent) !important;
|
||||
stroke-width: 2.2 !important;
|
||||
/* A Map card's border is its status alone. Selection rings it from outside instead: an accent
|
||||
ring past a gap in the canvas colour, outside the status border, with a soft lift; hover draws
|
||||
the same ring in grey. The ring scales with the canvas, so below a readable zoom its unit grows
|
||||
to keep it about a screen pixel and a half wide (--canvas-zoom, set by the zoom bridge). */
|
||||
.map-surface .screen-screenshot-card {
|
||||
--ring-unit: clamp(1px, 0.6px / var(--canvas-zoom, 1), 6px);
|
||||
--ring-status: 0px;
|
||||
}
|
||||
.map-surface .screen-screenshot-card:is(.diff-added, .diff-modified, .diff-removed) { --ring-status: 2px; }
|
||||
.map-surface .screen-screenshot-card .screen-node-image :is(img, .image-placeholder) {
|
||||
border-color: var(--border-subtle);
|
||||
box-shadow: none;
|
||||
}
|
||||
.map-surface .react-flow__node-screen:is(.selected, .graph-node-hover-subject) .screen-screenshot-card .screen-node-image :is(img, .image-placeholder) {
|
||||
box-shadow:
|
||||
0 0 0 var(--ring-status) var(--diff, transparent),
|
||||
0 0 0 calc(var(--ring-status) + 4 * var(--ring-unit)) var(--screen),
|
||||
0 0 0 calc(var(--ring-status) + 6.5 * var(--ring-unit)) var(--ring-color),
|
||||
var(--ring-lift, 0 0 transparent);
|
||||
}
|
||||
.map-surface .react-flow__node-screen.graph-node-hover-subject { --ring-color: var(--hover-ring); }
|
||||
.map-surface .react-flow__node-screen.selected {
|
||||
--ring-color: var(--accent);
|
||||
--ring-lift: 0 calc(10 * var(--ring-unit)) calc(28 * var(--ring-unit)) color-mix(in srgb, var(--accent) 18%, transparent);
|
||||
}
|
||||
.map-surface .react-flow__node-screen.selected .screen-node-title { color: var(--accent-strong); }
|
||||
/* Keyboard focus is dashed, past where a ring would sit, so it never reads as either. */
|
||||
.map-surface .screen-screenshot-target:focus-visible {
|
||||
outline: 2px dashed var(--accent-strong) !important;
|
||||
outline-offset: calc(var(--ring-status) + 9 * var(--ring-unit)) !important;
|
||||
filter: none !important;
|
||||
}
|
||||
|
||||
/* Hover is transient canvas state. Nothing recedes: the pointer's screen takes its grey ring and
|
||||
the transitions into and out of it darken. Only the symmetric difference of related
|
||||
nodes/edges receives a class, avoiding a React commit across the graph. A selected screen's
|
||||
transitions stay accent. */
|
||||
.connection-canvas-surface.canvas-hovering .graph-edge-hover-related:not(.graph-edge-active) .transition-edge-path {
|
||||
stroke: var(--tertiary) !important;
|
||||
stroke-width: 2 !important;
|
||||
stroke-dasharray: none !important;
|
||||
}
|
||||
.connection-canvas-surface.canvas-hovering .react-flow__node-screen.graph-node-hover-related:not(.graph-node-hover-subject)
|
||||
.screen-screenshot-card:not(.selected, .diff-added, .diff-modified, .diff-removed) {
|
||||
--screen-frame: var(--hover-neighbour-frame);
|
||||
}
|
||||
.connection-canvas-surface.canvas-hovering .react-flow__node-screen.graph-node-hover-related:not(.graph-node-hover-subject)
|
||||
.screen-screenshot-card:not(.selected, .diff-added, .diff-modified, .diff-removed) .screen-node-image :is(img, .image-placeholder) {
|
||||
border-color: var(--hover-neighbour-frame);
|
||||
}
|
||||
|
||||
/* Semantic Map: an area is a meaningful destination, never an anonymous "X states" step. */
|
||||
.semantic-summary-node {
|
||||
@@ -928,7 +941,7 @@ code {
|
||||
|
||||
/* The phone map's open hint. The first tap there only selects, so the pill sits in the middle of
|
||||
the selected screenshot (always on the image whatever the slot's shape) and says what the next
|
||||
tap does. In a wider window the card's tooltip carries the message and nothing covers the image. */
|
||||
tap does. In a wider window a click opens the Inspector at once and nothing covers the image. */
|
||||
.screen-screenshot-target { cursor: pointer; }
|
||||
.screen-open-hint {
|
||||
position: absolute;
|
||||
@@ -954,7 +967,7 @@ code {
|
||||
.screen-open-hint > svg { width: 14px; height: 14px; flex: none; }
|
||||
/* Only the phone layout's map shows the pill, on the selected screen, where a second tap or click
|
||||
opens the Inspector. That layout is a width, not a device, and has no tooltips, so a narrow
|
||||
desktop window shows it too. Elsewhere the screenshot button's tooltip says it instead. */
|
||||
desktop window shows it too. */
|
||||
.phone-layout .map-canvas .screen-screenshot-card.selected .screen-open-hint {
|
||||
display: inline-flex;
|
||||
animation: screen-open-hint-in 140ms ease-out;
|
||||
@@ -998,7 +1011,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); }
|
||||
@@ -1105,7 +1118,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;
|
||||
@@ -1117,6 +1133,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);
|
||||
}
|
||||
/* 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-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; }
|
||||
/* When minimised, the inspector actions join the camera controls as one floating toolbar. */
|
||||
.right-float {
|
||||
position: fixed;
|
||||
@@ -2330,7 +2375,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) {
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
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,
|
||||
);
|
||||
}
|
||||
|
||||
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, in the panel's own (unscaled) pixels when the chrome is zoomed by `scale`.
|
||||
*/
|
||||
export function inspectorWidthBounds(windowWidth: number, scale = 1): InspectorWidthBounds {
|
||||
const half = Math.floor(windowWidth / 2 / (scale > 0 ? scale : 1));
|
||||
return { min: INSPECTOR_WIDTH_MIN, max: Math.max(INSPECTOR_WIDTH_MIN, Math.min(INSPECTOR_WIDTH_MAX, half)) };
|
||||
}
|
||||
|
||||
export function clampInspectorWidth(width: number, bounds: InspectorWidthBounds): number {
|
||||
return Math.round(Math.min(bounds.max, Math.max(bounds.min, width)));
|
||||
}
|
||||
Reference in new issue
Block a user