feat(web): draggable floating panels and a non-hanging tutorial demo open
Some checks failed
M6 deployable RC / quick (push) Has been cancelled
M6 deployable RC / chromium (push) Has been cancelled
M6 deployable RC / release (push) Has been cancelled

- add a shared useDraggablePanel hook (pointer capture, clamping, offset
  persistence in localStorage, double-click / button / menu reset) and use it
  for the tutorial step panel, the quick toolbar, the adjust-last-operation
  panel and the robot tool drawer
- quick toolbar drags out of the dock into a compact floating bar and can be
  folded; robot tool scrim is transparent and click-through so the 3D scene
  stays visible and usable while the tool is open
- 窗口 > 恢复默认面板位置 clears every stored panel offset
- fix a pre-existing hang: tutorial demo scene opens went through the
  "save current project?" prompt and waited forever; course demos now persist
  the current OPFS project like the dialog's 保存后继续 and continue
- PBR tutorial spec: demos must not auto-download .blend (OPFS-only rule)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
mes123456
2026-11-23 21:43:40 +08:00
parent cb2829cad1
commit 2c8449f422
15 changed files with 716 additions and 92 deletions

View File

@@ -0,0 +1,176 @@
import { expect, test, type Locator, type Page } from "@playwright/test";
import fs from "node:fs";
import path from "node:path";
import { observeNative } from "../fixtures/native-ui-workflow";
const root = path.resolve(import.meta.dirname, "../../..");
const outputDir = path.join(root, "tests/golden/WEB-PANEL-DRAG-20261123");
fs.mkdirSync(outputDir, { recursive: true });
const OFFSET_KEY = "web-blender.panel-offsets.v1";
async function storedOffsets(page: Page): Promise<Record<string, { x: number; y: number }>> {
return page.evaluate((key) => {
try { return JSON.parse(window.localStorage.getItem(key) ?? "{}") as Record<string, { x: number; y: number }>; }
catch { return {}; }
}, OFFSET_KEY);
}
function offsetOf(panel: Locator): Promise<{ x: number; y: number }> {
return panel.getAttribute("data-panel-offset").then((value) => {
const [x, y] = (value ?? "0,0").split(",").map(Number);
return { x, y };
});
}
/** Drag `handle` by (dx, dy) with real pointer input. */
async function dragBy(page: Page, handle: Locator, dx: number, dy: number): Promise<void> {
const box = await handle.boundingBox();
expect(box, "drag handle must be laid out").toBeTruthy();
const startX = box!.x + Math.min(24, box!.width / 2);
const startY = box!.y + box!.height / 2;
await page.mouse.move(startX, startY);
await page.mouse.down();
await page.mouse.move(startX + dx / 2, startY + dy / 2, { steps: 4 });
await page.mouse.move(startX + dx, startY + dy, { steps: 4 });
await page.mouse.up();
}
test("tutorial step panel (PBR Studio Ground) drags, remembers its offset and resets", async ({ page }) => {
test.setTimeout(240_000);
await observeNative(page);
await page.goto("/?ui=web&tutorial=pbr&start=1");
const panel = page.locator(".parts-tutorial-overlay").first();
await expect(panel).toBeVisible({ timeout: 120_000 });
await expect(page.locator(".tutorial-drag-grip")).toBeVisible();
const before = await offsetOf(panel);
expect(before).toEqual({ x: 0, y: 0 });
await dragBy(page, panel.locator("header.tutorial-head"), 160, 120);
await expect.poll(async () => (await offsetOf(panel)).x, { timeout: 10_000 }).not.toBe(0);
const dragged = await offsetOf(panel);
expect(dragged.y).toBeGreaterThan(50);
expect((await storedOffsets(page)).tutorial).toEqual(dragged);
/* A reload must land the panel where the learner parked it. */
await page.reload();
await expect(panel).toBeVisible({ timeout: 120_000 });
expect(await offsetOf(panel)).toEqual(dragged);
/* The header carries an explicit reset for learners who cannot double-click. */
await page.getByLabel("复位教程面板位置").click();
await expect.poll(async () => (await offsetOf(panel)).x, { timeout: 10_000 }).toBe(0);
expect(await offsetOf(panel)).toEqual({ x: 0, y: 0 });
/* Double-clicking the header does the same after a fresh drag. */
await dragBy(page, panel.locator("header.tutorial-head"), 90, 60);
await expect.poll(async () => (await offsetOf(panel)).x, { timeout: 10_000 }).not.toBe(0);
await panel.locator("header.tutorial-head").dblclick();
await expect.poll(async () => (await offsetOf(panel)).x, { timeout: 10_000 }).toBe(0);
fs.writeFileSync(path.join(outputDir, "tutorial-panel.json"), JSON.stringify({
schemaVersion: 1, browser: "chromium", storage: "OPFS",
workflow: "/?ui=web&tutorial=pbr&start=1 -> drag step panel -> reload -> 复位 -> drag -> double-click reset",
before, dragged, stored: (await storedOffsets(page)).tutorial ?? null,
status: "PASS", acceptance: "NOT_CLAIMED",
}, null, 2));
});
test("quick toolbar floats out of the viewport top and can be folded", async ({ page }) => {
test.setTimeout(240_000);
await observeNative(page);
await page.goto("/?ui=web");
await page.getByTestId("blend-file-input").setInputFiles(path.join(root, "tests/files/web/basic_scene.blend"));
await expect(page.getByTestId("engine-status")).toContainText(/SceneIR r\d+/, { timeout: 120_000 });
const bar = page.locator(".legacy-quick-toolbar").first();
await expect(bar).toBeVisible({ timeout: 60_000 });
await expect(bar).toHaveAttribute("data-quick-toolbar-floating", "false");
/* Before the drag the bar spans the workspace and covers the viewport top. */
const coveredBefore = await page.evaluate(() => {
const bar = document.querySelector(".legacy-quick-toolbar");
const rect = bar!.getBoundingClientRect();
const hit = document.elementFromPoint(rect.left + rect.width / 2, rect.top + rect.height / 2);
return Boolean(hit && bar!.contains(hit));
});
expect(coveredBefore).toBe(true);
await dragBy(page, bar.locator(".quick-toolbar-grip"), 120, 150);
await expect(bar).toHaveAttribute("data-quick-toolbar-floating", "true", { timeout: 10_000 });
const offset = await offsetOf(bar);
expect(offset.y).toBeGreaterThan(80);
expect((await storedOffsets(page))["quick-toolbar"]).toEqual(offset);
/* Floating, it is a compact bar: the canvas top-centre is no longer the bar. */
const coveredAfter = await page.evaluate(() => {
const bar = document.querySelector(".legacy-quick-toolbar") as HTMLElement;
const rect = bar.getBoundingClientRect();
const hit = document.elementFromPoint(window.innerWidth / 2, rect.bottom + 4);
return Boolean(hit && bar.contains(hit));
});
expect(coveredAfter).toBe(false);
await page.getByLabel("折叠快捷操作栏").click();
await expect(bar).toHaveAttribute("data-quick-tools-collapsed", "true");
await expect(page.getByLabel("展开快捷操作栏")).toBeVisible();
await page.getByLabel("展开快捷操作栏").click();
await expect(bar).toHaveAttribute("data-quick-tools-collapsed", "false");
await page.getByLabel("复位快捷操作栏位置").click();
await expect.poll(async () => (await offsetOf(bar)).y, { timeout: 10_000 }).toBe(0);
fs.writeFileSync(path.join(outputDir, "quick-toolbar.json"), JSON.stringify({
schemaVersion: 1, browser: "chromium", storage: "OPFS",
workflow: "drag quick toolbar out of the dock -> floating -> fold/unfold -> reset",
coveredBefore, coveredAfter, offset,
status: "PASS", acceptance: "NOT_CLAIMED",
}, null, 2));
});
test("adjust-last-operation and robot tool panels can be moved off the model", async ({ page }) => {
test.setTimeout(240_000);
await observeNative(page);
await page.goto("/?ui=web");
await page.getByTestId("blend-file-input").setInputFiles(path.join(root, "tests/files/web/basic_scene.blend"));
await expect(page.getByTestId("engine-status")).toContainText(/SceneIR r\d+/, { timeout: 120_000 });
/* The quick toolbar's Add Monkey goes through invokeNativeOperator, which is
* the path that keeps the operator recorded for 调整上一步操作. */
await page.locator(".legacy-quick-toolbar").getByRole("button", { name: "Add Monkey", exact: true }).click();
await expect(page.getByTestId("engine-status")).toContainText(/mesh\.primitive_monkey_add/, { timeout: 120_000 });
const adjust = page.locator(".last-operator-panel").first();
await expect(adjust).toBeVisible({ timeout: 60_000 });
await page.getByLabel("调整上一步操作").first().click();
await expect(adjust.locator("form header")).toBeVisible({ timeout: 30_000 });
await dragBy(page, adjust.locator("form header"), 180, -120);
await expect.poll(async () => (await offsetOf(adjust)).x, { timeout: 10_000 }).not.toBe(0);
const adjustOffset = await offsetOf(adjust);
expect((await storedOffsets(page))["last-operator"]).toEqual(adjustOffset);
/* Robot tool: the scrim is transparent and the drawer is draggable. */
await page.getByLabel("六轴机器人工具").click();
const robot = page.locator(".robot-tool").first();
await expect(robot).toBeVisible({ timeout: 60_000 });
const scrim = await page.evaluate(() => {
const style = getComputedStyle(document.querySelector(".robot-tool-backdrop")!);
return { background: style.backgroundColor, pointerEvents: style.pointerEvents };
});
expect(["transparent", "rgba(0, 0, 0, 0)"]).toContain(scrim.background);
expect(scrim.pointerEvents).toBe("none");
await dragBy(page, robot.locator("header"), -260, 90);
await expect.poll(async () => (await offsetOf(robot)).x, { timeout: 10_000 }).not.toBe(0);
const robotOffset = await offsetOf(robot);
expect(robotOffset.x).toBeLessThan(0);
expect((await storedOffsets(page))["robot-tool"]).toEqual(robotOffset);
fs.writeFileSync(path.join(outputDir, "tool-panels.json"), JSON.stringify({
schemaVersion: 1, browser: "chromium", storage: "OPFS",
workflow: "add monkey -> adjust-last-operation drag -> open robot tool -> transparent scrim -> drag drawer",
adjustOffset, robotOffset, scrim,
status: "PASS", acceptance: "NOT_CLAIMED",
}, null, 2));
});

View File

@@ -43,6 +43,8 @@ test("PBR tutorial runs every demo through the real asset library and renderer",
"render-setup", "download-save", "summary",
]));
expect(downloads.some((name) => /\.png$/i.test(name))).toBe(true);
expect(downloads.some((name) => /\.blend$/i.test(name))).toBe(true);
/* 铁律:工程只写入 OPFS;本地 .blend 必须由用户显式点「下载 .blend」触发,
* 保存流程(含教程演示的 save 动作)不得自动下载。 */
expect(downloads.some((name) => /\.blend$/i.test(name))).toBe(false);
await expect(overlay).toContainText("12 张材质对比");
});