feat(web): Outliner eyedropper picks objects for modifier fields
Desktop's UI_OT_eyedropper_id borrows the ID under the cursor through ED_outliner_give_base_under_cursor. The workbench splits Properties and the Outliner into separate DOM trees, so an armed pick is shared through a small external store: object-valued modifier fields grow a 取物 (pick) button, the Outliner enters a crosshair pick mode, and clicking an object row commits that object's id. Escape cancels, mirroring the modal operator. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@@ -19,7 +19,7 @@ import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const REPO_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
|
||||
const EXPECTED_CASES = ["outliner-tree-baseline-web", "outliner-tools-baseline-web", "outliner-mirror-baseline-web", "outliner-metrics-web", "outliner-display-mode-web", "outliner-filter-web", "outliner-restrict-web", "outliner-select-keys-web", "outliner-delete-web", "outliner-box-select-web", "outliner-id-operation-web", "outliner-id-clipboard-web", "outliner-collection-delete-web", "outliner-mode-dot-web", "outliner-rename-bone-web"];
|
||||
const EXPECTED_CASES = ["outliner-tree-baseline-web", "outliner-tools-baseline-web", "outliner-mirror-baseline-web", "outliner-metrics-web", "outliner-display-mode-web", "outliner-filter-web", "outliner-restrict-web", "outliner-select-keys-web", "outliner-delete-web", "outliner-box-select-web", "outliner-id-operation-web", "outliner-id-clipboard-web", "outliner-collection-delete-web", "outliner-mode-dot-web", "outliner-rename-bone-web", "outliner-eyedropper-web"];
|
||||
/* Desktop Layout geometry the metrics case must reproduce (batch 2: UI sizes). */
|
||||
const GEOMETRY_GOLDEN = path.join(REPO_ROOT, "tests/golden/OUTLINER-DESKTOP-METRICS/outliner-metrics.json");
|
||||
const errors = [];
|
||||
|
||||
@@ -46,6 +46,7 @@ const KNOWN_CASES = [
|
||||
{ id: "outliner-collection-delete-web", title: /\[outliner-collection-delete-web\]/ },
|
||||
{ id: "outliner-mode-dot-web", title: /\[outliner-mode-dot-web\]/ },
|
||||
{ id: "outliner-rename-bone-web", title: /\[outliner-rename-bone-web\]/ },
|
||||
{ id: "outliner-eyedropper-web", title: /\[outliner-eyedropper-web\]/ },
|
||||
];
|
||||
|
||||
function usage() {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { ModifierParameterField } from "./ModifierParameterField";
|
||||
import { acceptOutlinerPick, cancelOutlinerPick, useOutlinerPickActive } from "./outliner-pick";
|
||||
import { Fragment } from 'react';
|
||||
import { NLA_OBJECT_ID_TYPE } from '../../../protocol/nla';
|
||||
import { EDITOR_RESOURCE_MAX_BYTES, isEditorResourcePath, modelResourcePath } from '../../../protocol/editor-resource-path';
|
||||
@@ -2611,6 +2612,18 @@ function Outliner({ snapshot, areaId, onSelect, onToggleVisibility, onRefresh, o
|
||||
const nativeArea = workspace?.areas.find(item => item.editor === 'OUTLINER' &&
|
||||
(!areaId || item.id === areaId) && item.regions.some(region => region.kind === 'MAIN' && region.visible));
|
||||
const tree = nativeArea?.space?.outliner;
|
||||
/* Desktop ui_eyedropper_id arms a pick that ED_outliner_give_base_under_cursor
|
||||
* resolves against the row under the cursor; here the pick rides a store so
|
||||
* the Properties field and this tree share it. */
|
||||
const outlinerPickActive = useOutlinerPickActive();
|
||||
useEffect(() => {
|
||||
if (!outlinerPickActive) return;
|
||||
const onKey = (event: KeyboardEvent) => {
|
||||
if (event.key === 'Escape') { event.preventDefault(); cancelOutlinerPick(); }
|
||||
};
|
||||
window.addEventListener('keydown', onKey, true);
|
||||
return () => window.removeEventListener('keydown', onKey, true);
|
||||
}, [outlinerPickActive]);
|
||||
/* Desktop SO_MODE_COLUMN (outliner_draw.cc): Scenes and View Layer draw a
|
||||
* mode dot on object rows sharing the active object's type while the active
|
||||
* object is in an interaction mode. */
|
||||
@@ -2862,7 +2875,7 @@ function Outliner({ snapshot, areaId, onSelect, onToggleVisibility, onRefresh, o
|
||||
* parent (default view requires Shift); Alt clears completely instead of
|
||||
* keeping the world transform. Drops on a row are handled there and never
|
||||
* reach this container. */}
|
||||
<div ref={treeRoot} tabIndex={-1} className="outliner-tree"
|
||||
<div ref={treeRoot} tabIndex={-1} className={`outliner-tree${outlinerPickActive ? ' outliner-picking' : ''}`}
|
||||
onPointerDownCapture={event => {
|
||||
/* Only empty space or a B-armed press starts a box; presses on a row
|
||||
* stay with the row (selection, rename, drag-drop). */
|
||||
@@ -3012,6 +3025,13 @@ function Outliner({ snapshot, areaId, onSelect, onToggleVisibility, onRefresh, o
|
||||
if (onTreeSelect && nativeArea) onTreeSelect(row.id, row.selected, false, nativeArea.id, false);
|
||||
}}
|
||||
onClick={event => {
|
||||
/* An armed datablock pick takes the base under the cursor instead
|
||||
* of selecting the row (desktop eyedropper over the Outliner). */
|
||||
if (outlinerPickActive && row.objectId) {
|
||||
event.preventDefault(); event.stopPropagation();
|
||||
acceptOutlinerPick(row.objectId);
|
||||
return;
|
||||
}
|
||||
const activatesData = event.target instanceof Element &&
|
||||
!!event.target.closest('.tree-node-name');
|
||||
// Name activation follows the same native intent as the
|
||||
|
||||
@@ -65,3 +65,25 @@
|
||||
flex: 1 1 100px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.modifier-stack-authoring .parameter-eyedropper {
|
||||
min-width: 0;
|
||||
padding: 0 4px;
|
||||
color: #d8d8d8;
|
||||
background: #2e2e2e;
|
||||
border: 1px solid #4a4a4a;
|
||||
border-radius: 2px;
|
||||
font-size: 11px;
|
||||
line-height: 18px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.modifier-stack-authoring .parameter-eyedropper:hover {
|
||||
color: #fff;
|
||||
background: #4a4a4a;
|
||||
}
|
||||
|
||||
.modifier-stack-authoring .parameter-eyedropper:disabled {
|
||||
color: #6a6a6a;
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import { useEffect, useId, useRef, useState } from "react";
|
||||
import type { CSSProperties, PointerEvent as ReactPointerEvent, ReactNode } from "react";
|
||||
import type { ModifierParameterMetadata } from "../../../protocol/modifier";
|
||||
import { ModifierCurveProfileField } from "./ModifierCurveProfileField";
|
||||
import { requestOutlinerPick } from "./outliner-pick";
|
||||
import { finishModifierInput } from './modifier-input-keyboard';
|
||||
import './modifier-curve-tools.css';
|
||||
import zoomInIcon from './curve-icons/zoom_in.svg';
|
||||
@@ -954,13 +955,19 @@ export function ModifierParameterField({ field, onCommit, onCurveGesture, onInte
|
||||
const numericRange = typeof value === 'number' && field.minimum !== undefined && field.maximum !== undefined &&
|
||||
Number.isFinite(field.minimum) && Number.isFinite(field.maximum) && field.minimum < field.maximum;
|
||||
return <label key={`${index}:${String(value)}`} title={field.description}>{label}{field.kind === "enum" || field.kind === "object" || field.kind === "collection" || field.kind === "texture" || field.kind === "cachefile" || (field.kind === "string" && field.suggestionsOnly === false)
|
||||
? <select aria-label={label} disabled={disabled} value={String(value ?? "")} onChange={(event) => commit((field.kind === "object" || field.kind === "collection" || field.kind === "texture" || field.kind === "cachefile") && event.target.value === "" ? null : event.target.value)}>
|
||||
? <><select aria-label={label} disabled={disabled} value={String(value ?? "")} onChange={(event) => commit((field.kind === "object" || field.kind === "collection" || field.kind === "texture" || field.kind === "cachefile") && event.target.value === "" ? null : event.target.value)}>
|
||||
{(field.kind === "object" || field.kind === "collection" || field.kind === "texture" || field.kind === "cachefile") && <option value="" disabled={field.nullable === false}>None</option>}
|
||||
{field.kind === "string" && <option value="">None</option>}
|
||||
{value !== null && value !== "" && !choices.some(item => item.id === value) &&
|
||||
<option value={String(value)} disabled>{String(value)} (unavailable)</option>}
|
||||
{choices.map((option) => <option key={option.id} value={option.id}>{option.label}</option>)}
|
||||
</select>
|
||||
{field.kind === "object" && !field.length
|
||||
? <button type="button" className="parameter-eyedropper" disabled={disabled}
|
||||
aria-label={`取物器 ${label}`} title="取物器:在 Outliner 中点选对象(桌面 UI_OT_eyedropper_id)"
|
||||
onClick={event => { event.preventDefault(); event.stopPropagation(); requestOutlinerPick(objectId => { void commit(objectId); }); }}>取物</button>
|
||||
: null}
|
||||
</>
|
||||
: field.kind === "string"
|
||||
? <><input aria-label={label} disabled={disabled} type="text" defaultValue={String(value)}
|
||||
maxLength={field.maxLength} list={suggestionsId}
|
||||
|
||||
@@ -164,7 +164,7 @@ button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-
|
||||
.tree-node-name { min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap; }
|
||||
.properties-content { position: relative; display: flex; flex-direction: column; min-height: 100%; padding: 4px 7px 12px 40px; color: #d0d0d0; background: #303030; }
|
||||
.outliner-tools { display: flex; gap: 3px; margin: 0 2px 4px; }.outliner-tools input { min-width: 0; height: 23px; flex: 1; padding: 3px 7px; color: #e4e4e4; background: #181818; border: 1px solid #454545; border-radius: 3px; outline: none; }.outliner-tools button { width: 27px; background: #383838; border-radius: 2px; }
|
||||
.tree-row { display: flex; align-items: center; gap: 5px; min-height: 20px; padding: 0 4px; border-radius: 0; }.tree-row:hover { background: #353535; }.tree-row.selected { color: #fff; background: #4775a3; }.tree-icon { height:20px;min-width:16px;padding:0;border:0;background:transparent;color: #d59b44; }.tree-icon.mesh { color: #6999c8; }.tree-action { width: 20px; min-width: 20px; height: 20px; margin-left: auto; padding: 0 2px; color: #a6a6a6; background: transparent; border: 0; border-radius: 2px; }.tree-action:hover { color: #fff; background: #4a4a4a; }
|
||||
.tree-row { display: flex; align-items: center; gap: 5px; min-height: 20px; padding: 0 4px; border-radius: 0; }.tree-row:hover { background: #353535; } .outliner-tree.outliner-picking .tree-row[data-node-id]:not([data-node-id=""]) { cursor: crosshair; }.tree-row.selected { color: #fff; background: #4775a3; }.tree-icon { height:20px;min-width:16px;padding:0;border:0;background:transparent;color: #d59b44; }.tree-icon.mesh { color: #6999c8; }.tree-action { width: 20px; min-width: 20px; height: 20px; margin-left: auto; padding: 0 2px; color: #a6a6a6; background: transparent; border: 0; border-radius: 2px; }.tree-action:hover { color: #fff; background: #4a4a4a; }
|
||||
.tree-restrict { display: inline-flex; align-items: center; flex: 0 0 auto; margin-left: auto; }
|
||||
.tree-restrict-button { width: 20px; min-width: 20px; height: 20px; padding: 0; color: #8d8d8d; background: transparent; border: 0; border-radius: 2px; font-size: 11px; line-height: 20px; }
|
||||
.tree-restrict-button:hover:not(:disabled) { color: #fff; background: #4a4a4a; }
|
||||
|
||||
51
web/app/src/app/outliner-pick.ts
Normal file
51
web/app/src/app/outliner-pick.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { useSyncExternalStore } from "react";
|
||||
|
||||
/* Desktop's datablock eyedropper (UI_OT_eyedropper_id) borrows an ID from the
|
||||
* Outliner under the cursor through ED_outliner_give_base_under_cursor. The
|
||||
* workbench splits Properties (DOM) and the Outliner (DOM) into separate
|
||||
* component trees, so an armed pick is shared through this store instead of
|
||||
* drilling a callback through the whole area layout. */
|
||||
|
||||
type ObjectPickRequest = { accept: (objectId: string) => void };
|
||||
|
||||
let pending: ObjectPickRequest | null = null;
|
||||
const listeners = new Set<() => void>();
|
||||
|
||||
function emit(): void {
|
||||
for (const listener of listeners) listener();
|
||||
}
|
||||
|
||||
/** Arm the picker: the next Outliner object row supplies the ID. */
|
||||
export function requestOutlinerPick(accept: (objectId: string) => void): void {
|
||||
pending = { accept };
|
||||
emit();
|
||||
}
|
||||
|
||||
export function cancelOutlinerPick(): void {
|
||||
if (!pending) return;
|
||||
pending = null;
|
||||
emit();
|
||||
}
|
||||
|
||||
export function acceptOutlinerPick(objectId: string): void {
|
||||
const request = pending;
|
||||
if (!request) return;
|
||||
pending = null;
|
||||
emit();
|
||||
request.accept(objectId);
|
||||
}
|
||||
|
||||
function isActive(): boolean {
|
||||
return pending !== null;
|
||||
}
|
||||
|
||||
function subscribe(listener: () => void): () => void {
|
||||
listeners.add(listener);
|
||||
return () => {
|
||||
listeners.delete(listener);
|
||||
};
|
||||
}
|
||||
|
||||
export function useOutlinerPickActive(): boolean {
|
||||
return useSyncExternalStore(subscribe, isActive, () => false);
|
||||
}
|
||||
@@ -547,4 +547,44 @@ test.describe("Outliner headed baseline", () => {
|
||||
* carry the new bone name in it (TSE_BONE rows renamed in place). */
|
||||
await expect(page.locator('[role="treeitem"][aria-label="UpperArm"]')).toHaveAttribute("data-tree-row-id", /"UpperArm"\]$/);
|
||||
});
|
||||
test("[outliner-eyedropper-web] a modifier Object field picks the object from the Outliner", async ({ page }) => {
|
||||
test.setTimeout(180_000);
|
||||
await openWorkbench(page);
|
||||
/* Duplicate the fixture's mesh so the Boolean modifier has an operand. */
|
||||
const objectRows = page.locator('.outliner-tree .tree-row[data-node-id]:not([data-node-id=""])');
|
||||
await expect.poll(() => objectRows.count(), { timeout: 20_000 }).toBeGreaterThan(0);
|
||||
const source = objectRows.filter({ hasText: "BasicCube" }).first();
|
||||
await source.locator(".tree-node-name").first().click({ button: "right" });
|
||||
await page.getByRole("menuitem", { name: "复制", exact: true }).click();
|
||||
await expect(page.locator('[data-testid="engine-status"]')).toContainText("已复制数据块", { timeout: 20_000 });
|
||||
const before = await objectRows.count();
|
||||
await source.locator(".tree-node-name").first().click({ button: "right" });
|
||||
await page.getByRole("menuitem", { name: "粘贴", exact: true }).click();
|
||||
await expect.poll(() => objectRows.count(), { timeout: 20_000 }).toBe(before + 1);
|
||||
const labels = () => objectRows.evaluateAll(rows => rows.map(row => row.getAttribute("aria-label") ?? ""));
|
||||
const operand = (await labels()).find(label => label.startsWith("BasicCube."));
|
||||
expect(operand).toBeTruthy();
|
||||
|
||||
/* Desktop: the datablock eyedropper (UI_OT_eyedropper_id) samples
|
||||
* ED_outliner_give_base_under_cursor. Add a Boolean modifier whose Object
|
||||
* parameter starts at None, arm its eyedropper, then click the operand's
|
||||
* Outliner row and expect the field to take that object. */
|
||||
await source.locator(".tree-node-name").first().click();
|
||||
await page.getByRole("tab", { name: "修改器" }).click();
|
||||
await page.getByRole("button", { name: "添加修改器", exact: true }).click();
|
||||
await page.getByRole("menuitem", { name: "生成", exact: true }).click();
|
||||
await page.getByRole("menuitem", { name: "布尔 (Boolean)", exact: true }).click();
|
||||
const row = page.locator(".modifier-row").filter({ hasText: "BOOLEAN" }).first();
|
||||
await expect(row).toBeVisible({ timeout: 60_000 });
|
||||
const eyedropper = row.locator('button[aria-label^="取物器 "]').first();
|
||||
await expect(eyedropper).toBeVisible({ timeout: 20_000 });
|
||||
const fieldLabel = ((await eyedropper.getAttribute("aria-label")) ?? "").replace(/^取物器 /, "");
|
||||
const objectSelect = row.getByRole("combobox", { name: fieldLabel, exact: true });
|
||||
await expect(objectSelect).toHaveValue("");
|
||||
await eyedropper.click();
|
||||
await expect(page.locator(".outliner-tree.outliner-picking")).toBeVisible();
|
||||
await page.locator(`.tree-row[aria-label="${operand}"] .tree-node-name`).first().click();
|
||||
await expect(objectSelect).toHaveValue(`object:${operand}`, { timeout: 30_000 });
|
||||
await expect(page.locator(".outliner-tree.outliner-picking")).toHaveCount(0);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user