diff --git a/tools/web/check-outliner-headed.mjs b/tools/web/check-outliner-headed.mjs index 50bfe5bc5..3d672fcbf 100644 --- a/tools/web/check-outliner-headed.mjs +++ b/tools/web/check-outliner-headed.mjs @@ -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"]; +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"]; /* 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 = []; diff --git a/tools/web/run-outliner-headed.mjs b/tools/web/run-outliner-headed.mjs index a172c8b00..e9bed41f2 100644 --- a/tools/web/run-outliner-headed.mjs +++ b/tools/web/run-outliner-headed.mjs @@ -39,6 +39,7 @@ const KNOWN_CASES = [ { id: "outliner-filter-web", title: /\[outliner-filter-web\]/ }, { id: "outliner-restrict-web", title: /\[outliner-restrict-web\]/ }, { id: "outliner-select-keys-web", title: /\[outliner-select-keys-web\]/ }, + { id: "outliner-delete-web", title: /\[outliner-delete-web\]/ }, ]; function usage() { diff --git a/web/app/src/app/App.tsx b/web/app/src/app/App.tsx index 1e45b8092..b91b265f2 100644 --- a/web/app/src/app/App.tsx +++ b/web/app/src/app/App.tsx @@ -2521,12 +2521,13 @@ const OUTLINER_RESTRICT_POPOVER_LABELS: Record void; onToggleVisibility: (id: string, visible: boolean) => void; onRefresh?: () => void; onSelectAll?: (operation: 'SELECT' | 'DESELECT' | 'INVERT' | 'TOGGLE') => void; + onDeleteObject?: (objectId: string) => void; areaId?: string; onToggleExpand?: (rowId: string, toggleAll: boolean, areaId: string) => void; onTreeSelect?: (rowId: string, extend: boolean, range: boolean, areaId: string, activateData: boolean, activateProperties?: boolean, recursive?: boolean) => void; @@ -2741,7 +2742,7 @@ function Outliner({ snapshot, areaId, onSelect, onToggleVisibility, onRefresh, o {/* Desktop SpaceOutliner display_mode selector (View Layer, Blender File, …). */} {onSetDisplayMode && tree?.displayModes?.length ? : null} { setMenuRow(null); setDataMenu(!dataMenu); }} - onClose={() => setDataMenu(false)} items={[{label: '重命名 (F2)', disabled: treeRenameBusy || remapBusy || !onRemap || !workspace?.writable || !menuTarget || !renameTarget(menuTarget), reason: '重命名受支持的本地数据块', action: () => { if (menuTarget) beginTreeRename(menuTarget); }}, {label: 'Remap Users', + onClose={() => setDataMenu(false)} items={[{label: '重命名 (F2)', disabled: treeRenameBusy || remapBusy || !onRemap || !workspace?.writable || !menuTarget || !renameTarget(menuTarget), reason: '重命名受支持的本地数据块', action: () => { if (menuTarget) beginTreeRename(menuTarget); }}, {label: '删除 (X)', disabled: treeRenameBusy || remapBusy || !onDeleteObject || !menuTarget?.objectId, reason: '删除所选对象(桌面 OUTLINER_OT_delete)', action: () => { if (menuTarget?.objectId) onDeleteObject?.(menuTarget.objectId); }}, {label: 'Remap Users', disabled: remapBusy || treeRenameBusy || !onRemap || !workspace?.writable || !menuTarget?.remapId || tree?.remapIds?.filter(id => id.id === menuTarget.remapId).length !== 1, reason: 'Remap all local usages of this data-block to another one of the same type', action: openRemap}]} /> @@ -2804,6 +2805,11 @@ function Outliner({ snapshot, areaId, onSelect, onToggleVisibility, onRefresh, o const row = rowId ? tree.rows.find((candidate) => candidate.id === rowId) : undefined; if (!row) return; if (event.key === "F2" && !event.ctrlKey && !event.metaKey && !event.altKey && !event.shiftKey) { event.preventDefault(); event.stopPropagation(); beginTreeRename(row); return; } + /* Desktop keymap binds outliner.delete to X and Del; the object row + * carries the id the deleteObject edit needs. */ + if ((event.key === "Delete" || selectKey === "x") && !event.ctrlKey && !event.metaKey && !event.altKey && !event.shiftKey && row.objectId && onDeleteObject) { + event.preventDefault(); event.stopPropagation(); onDeleteObject(row.objectId); return; + } if (event.key === "ContextMenu" || (event.shiftKey && event.key === "F10")) { event.preventDefault(); event.stopPropagation(); setMenuRow(row.id); setDataMenu(true); return; } if (event.key === "Enter" || event.key === " ") { event.preventDefault(); event.stopPropagation(); onTreeSelect?.(row.id, event.ctrlKey || event.metaKey, event.shiftKey, nativeArea.id, true, true); return; } if (row.hasChildren && ((event.key === "ArrowRight" && !row.expanded) || (event.key === "ArrowLeft" && row.expanded))) { event.preventDefault(); event.stopPropagation(); onToggleExpand?.(row.id, event.altKey, nativeArea.id); } @@ -10291,7 +10297,8 @@ else: onToggleExpand={toggleOutlinerExpand} onTreeSelect={selectOutlinerRow} onSetDisplayMode={(displayMode) => setOutlinerDisplayMode(displayMode, area.id)} onSetFilter={(filter) => setOutlinerFilter(filter, area.id)} onSetSyncSelect={(sync) => setOutlinerSyncSelect(sync, area.id)} onRemap={(command, feedback) => applyEditCommand(command, undefined, feedback)} onReparent={(ids, parentId, keepTransform) => void applyEditCommand({ type: 'setParents', objectIds: ids, parentId, keepTransform })} onMoveToCollection={(ids, collectionId, keepExistingLinks) => { for (const id of ids) void applyEditCommand({ type: 'moveObjectToCollection', objectId: id, collectionId, keepExistingLinks }); }} onMoveCollection={(collectionId, parentCollectionId) => void applyEditCommand(coreSceneCommands.moveCollection(collectionId, parentCollectionId))} onSelect={(id,additive,range)=>selectObject(id,additive,range,area.id)} onRefresh={()=>refreshOutliner(area.id)} onSelectAll={operation=>selectAllOutliner(operation,area.id)} - onToggleVisibility={(id,visible)=>void applyEditCommand({type:'setObjectVisibility',objectId:id,visible})}/>; + onToggleVisibility={(id,visible)=>void applyEditCommand({type:'setObjectVisibility',objectId:id,visible})} + onDeleteObject={(id)=>void applyEditCommand({type:'deleteObject',objectId:id})}/>; if(area.editor==='VIEW_3D')return { const client=webClientRef.current;if(!client||!nativeWorkspace)return false; const current=(await client.snapshot()).snapshot; @@ -10468,7 +10475,7 @@ else: case "3D Viewport": return void applyEditCommand({ type: "setObjectTransform", objectId, translation, rotationEuler, scale })} onDiagnostic={recordDiagnostic} mode={uiState.context.mode} onMeshEdit={runMeshEdit} onMeshSelectionMode={setMeshSelectionMode} onSelectAllMeshElements={selectAllMeshElements} onAddPrimitive={(primitive) => void applyEditCommand(coreSceneCommands.createPrimitive(primitive))} onFocusSculptProperties={() => focusProperty('[data-testid="sculpt-editor"]')} onVoxelRemesh={(voxelSize) => void invokeNativeOperator('object.voxel_remesh', { voxel_size: voxelSize })} />; case "Outliner": - return applyEditCommand(command, undefined, feedback)} onReparent={(ids, parentId, keepTransform) => void applyEditCommand({ type: 'setParents', objectIds: ids, parentId, keepTransform })} onMoveToCollection={(ids, collectionId, keepExistingLinks) => { for (const id of ids) void applyEditCommand({ type: 'moveObjectToCollection', objectId: id, collectionId, keepExistingLinks }); }} onMoveCollection={(collectionId, parentCollectionId) => void applyEditCommand(coreSceneCommands.moveCollection(collectionId, parentCollectionId))} onSelect={selectObject} onRefresh={refreshOutliner} onSelectAll={selectAllOutliner} onToggleVisibility={(id, visible) => void applyEditCommand({ type: "setObjectVisibility", objectId: id, visible })} />; + return applyEditCommand(command, undefined, feedback)} onReparent={(ids, parentId, keepTransform) => void applyEditCommand({ type: 'setParents', objectIds: ids, parentId, keepTransform })} onMoveToCollection={(ids, collectionId, keepExistingLinks) => { for (const id of ids) void applyEditCommand({ type: 'moveObjectToCollection', objectId: id, collectionId, keepExistingLinks }); }} onMoveCollection={(collectionId, parentCollectionId) => void applyEditCommand(coreSceneCommands.moveCollection(collectionId, parentCollectionId))} onSelect={selectObject} onRefresh={refreshOutliner} onSelectAll={selectAllOutliner} onToggleVisibility={(id, visible) => void applyEditCommand({ type: "setObjectVisibility", objectId: id, visible })} onDeleteObject={(id) => void applyEditCommand({ type: "deleteObject", objectId: id })} />; case "Properties": return queueLocalDesktopOperator("fluid." + operation, {}, true, objectId, "OBJECT") : undefined} pointCacheBusy={headerBusy || Boolean(localInvokePending) || localInvokeActive || nativeModalActive || projectActionLocked} onPointCacheOperation={localOnly ? operation => queueLocalDesktopOperator(operation === "BAKE_ALL" ? "ptcache.bake_all" : "ptcache.free_bake_all", operation === "BAKE_ALL" ? { bake: true } : {}, true) : undefined} selectedEdgeIndices={meshSelection.mode === "EDGE" ? [...meshSelection.indices] : []} nonMeshGeometryBuffers={nonMeshGeometryBuffers} client={webClientRef.current} snapshot={snapshot} uiMode={uiState.context.mode} onSetMode={(mode) => dispatchUI({type:'setMode', mode})} editorWorkflow={editorWorkflow} onExecutePython={executePythonAndApply} objectCameraId={objectCameraId} onObjectCameraChange={setObjectCameraId} onSimulatePhysics={simulatePhysicsRange} physicsSimulationRange={snapshot?.scenes[0]?.renderSettings ? { start: snapshot.scenes[0].renderSettings.frameStart, end: snapshot.scenes[0].renderSettings.frameEnd } : undefined} onImportSequencerMedia={importSequencerMedia} onRestoreSequencerMedia={restoreSequencerMedia} selectedFaceIndices={meshSelection.mode === "FACE" ? [...meshSelection.indices] : []} selectedVertexIndices={meshSelection.mode === "VERT" ? [...meshSelection.indices] : []} greasePencilSelection={greasePencilSelection} onGreasePencilCanvasPointSelect={(point, mode, baseSelectionRevision) => { commitGreasePencilSelection("CANVAS_2D", mode === "ADD" ? "TOGGLE" : mode, [point], baseSelectionRevision, point); }} onCommand={(command) => applyEditCommand(command)} onImportImage={(file) => void importImage(file)} onImportVFont={(file) => void importVFont(file)} onRequestAsset={(assetId) => { const client = webClientRef.current; if (!client) return; void client.requestAsset(assetId).then((asset) => setEngineStatus(`Asset: ${asset.assetId} (${asset.status})`)).catch((error: unknown) => setEngineStatus(recordDiagnostic("ENGINE", "PBR_ASSET_INVALID", error, { assetId }))); }} onAppendLibraryObject={async (source, request) => { const client = webClientRef.current; if (!client) return; const appendProjectId = projectIdRef.current; const isCurrent = () => client === webClientRef.current && appendProjectId === projectIdRef.current; @@ -10635,9 +10642,9 @@ else: {localOnly ? fileInputRef.current?.click()} onSearch={() => dispatchUI({ type: "toggleOperatorSearch", open: true })} /> : workspace === "Geometry Nodes" ? : null} {scriptingMounted.current ? !projectActionMutexRef.current.owner} onDraftChanged={dirty=>{if(dirty)textDraftAreas.current.add('web-tools-text');else textDraftAreas.current.delete('web-tools-text');textDraftDirty.current=textDraftAreas.current.size>0;}} onNativeRun={localOnly?undefined:(name,source)=>void runNativeWorkflow({kind:'PYTHON',context:nativeContext(),python:{source,textName:name,console:false}})} onPythonRun={pythonSession?(name,source)=>pythonSession.run(source,name,false):undefined} pythonBusy={pythonState?.status==='running'||pythonState?.status==='stopping'}/> - {pythonSession?:} fileInputRef.current?.click()} onSearch={() => dispatchUI({ type: "toggleOperatorSearch", open: true })} /> applyEditCommand(command, undefined, feedback)} onReparent={(ids, parentId, keepTransform) => void applyEditCommand({ type: 'setParents', objectIds: ids, parentId, keepTransform })} onMoveToCollection={(ids, collectionId, keepExistingLinks) => { for (const id of ids) void applyEditCommand({ type: 'moveObjectToCollection', objectId: id, collectionId, keepExistingLinks }); }} onMoveCollection={(collectionId, parentCollectionId) => void applyEditCommand(coreSceneCommands.moveCollection(collectionId, parentCollectionId))} onSelect={selectObject} onRefresh={refreshOutliner} onSelectAll={selectAllOutliner} onToggleVisibility={(id, visible) => void applyEditCommand({ type: "setObjectVisibility", objectId: id, visible })} /> : null} + {pythonSession?:} fileInputRef.current?.click()} onSearch={() => dispatchUI({ type: "toggleOperatorSearch", open: true })} /> applyEditCommand(command, undefined, feedback)} onReparent={(ids, parentId, keepTransform) => void applyEditCommand({ type: 'setParents', objectIds: ids, parentId, keepTransform })} onMoveToCollection={(ids, collectionId, keepExistingLinks) => { for (const id of ids) void applyEditCommand({ type: 'moveObjectToCollection', objectId: id, collectionId, keepExistingLinks }); }} onMoveCollection={(collectionId, parentCollectionId) => void applyEditCommand(coreSceneCommands.moveCollection(collectionId, parentCollectionId))} onSelect={selectObject} onRefresh={refreshOutliner} onSelectAll={selectAllOutliner} onToggleVisibility={(id, visible) => void applyEditCommand({ type: "setObjectVisibility", objectId: id, visible })} onDeleteObject={(id) => void applyEditCommand({ type: "deleteObject", objectId: id })} /> : null} setCameraLocks(current=>({...current,"viewport-area":locked}))} onSelect={selectObject} onBoxSelect={selectObjectsInBox} onElementBoxSelect={selectMeshElementsInBox} onElementSelect={selectMeshElement} onGreasePencilPointSelect={selectGreasePencilPoint} onGreasePencilMarqueeSelect={selectGreasePencilMarquee} onTransform={transformActive} transformSettings={viewportTransformSettings} elementGizmo={elementGizmoFrame} onGizmoDrag={onGizmoDrag}onSetObjectTransform={(objectId, translation, rotationEuler, scale) => void applyEditCommand({ type: "setObjectTransform", objectId, translation, rotationEuler, scale })} onDiagnostic={recordDiagnostic} mode={uiState.context.mode} onMeshEdit={runMeshEdit} onMeshSelectionMode={setMeshSelectionMode} onSelectAllMeshElements={selectAllMeshElements} onAddPrimitive={(primitive) => void applyEditCommand(coreSceneCommands.createPrimitive(primitive))} onFocusSculptProperties={() => focusProperty('[data-testid="sculpt-editor"]')} onVoxelRemesh={(voxelSize) => void invokeNativeOperator('object.voxel_remesh', { voxel_size: voxelSize })} /> - applyEditCommand(command, undefined, feedback)} onReparent={(ids, parentId, keepTransform) => void applyEditCommand({ type: 'setParents', objectIds: ids, parentId, keepTransform })} onMoveToCollection={(ids, collectionId, keepExistingLinks) => { for (const id of ids) void applyEditCommand({ type: 'moveObjectToCollection', objectId: id, collectionId, keepExistingLinks }); }} onMoveCollection={(collectionId, parentCollectionId) => void applyEditCommand(coreSceneCommands.moveCollection(collectionId, parentCollectionId))} onSelect={selectObject} onRefresh={refreshOutliner} onSelectAll={selectAllOutliner} onToggleVisibility={(id, visible) => void applyEditCommand({ type: "setObjectVisibility", objectId: id, visible })} /> + applyEditCommand(command, undefined, feedback)} onReparent={(ids, parentId, keepTransform) => void applyEditCommand({ type: 'setParents', objectIds: ids, parentId, keepTransform })} onMoveToCollection={(ids, collectionId, keepExistingLinks) => { for (const id of ids) void applyEditCommand({ type: 'moveObjectToCollection', objectId: id, collectionId, keepExistingLinks }); }} onMoveCollection={(collectionId, parentCollectionId) => void applyEditCommand(coreSceneCommands.moveCollection(collectionId, parentCollectionId))} onSelect={selectObject} onRefresh={refreshOutliner} onSelectAll={selectAllOutliner} onToggleVisibility={(id, visible) => void applyEditCommand({ type: "setObjectVisibility", objectId: id, visible })} onDeleteObject={(id) => void applyEditCommand({ type: "deleteObject", objectId: id })} /> queueLocalDesktopOperator("fluid." + operation, {}, true, objectId, "OBJECT") : undefined} pointCacheBusy={headerBusy || Boolean(localInvokePending) || localInvokeActive || nativeModalActive || projectActionLocked} onPointCacheOperation={localOnly ? operation => queueLocalDesktopOperator(operation === "BAKE_ALL" ? "ptcache.bake_all" : "ptcache.free_bake_all", operation === "BAKE_ALL" ? { bake: true } : {}, true) : undefined} selectedEdgeIndices={meshSelection.mode === "EDGE" ? [...meshSelection.indices] : []} nonMeshGeometryBuffers={nonMeshGeometryBuffers} client={webClientRef.current} snapshot={snapshot} uiMode={uiState.context.mode} onSetMode={(mode) => dispatchUI({type:'setMode', mode})} editorWorkflow={editorWorkflow} onExecutePython={executePythonAndApply} objectCameraId={objectCameraId} onObjectCameraChange={setObjectCameraId} onSimulatePhysics={simulatePhysicsRange} physicsSimulationRange={snapshot?.scenes[0]?.renderSettings ? { start: snapshot.scenes[0].renderSettings.frameStart, end: snapshot.scenes[0].renderSettings.frameEnd } : undefined} onImportSequencerMedia={importSequencerMedia} onRestoreSequencerMedia={restoreSequencerMedia} selectedFaceIndices={meshSelection.mode === "FACE" ? [...meshSelection.indices] : []} selectedVertexIndices={meshSelection.mode === "VERT" ? [...meshSelection.indices] : []} greasePencilSelection={greasePencilSelection} onGreasePencilCanvasPointSelect={(point, mode, baseSelectionRevision) => { commitGreasePencilSelection("CANVAS_2D", mode === "ADD" ? "TOGGLE" : mode, [point], baseSelectionRevision, point); }} onCommand={(command) => applyEditCommand(command)} onImportImage={(file) => void importImage(file)} onImportVFont={(file) => void importVFont(file)} onRequestAsset={(assetId) => { const client = webClientRef.current; if (!client) return; void client.requestAsset(assetId).then((asset) => setEngineStatus(`Asset: ${asset.assetId} (${asset.status})`)).catch((error: unknown) => setEngineStatus(recordDiagnostic("ENGINE", "PBR_ASSET_INVALID", error, { assetId }))); }} onAppendLibraryObject={async (source, request) => { const client = webClientRef.current; if (!client) return; const appendProjectId = projectIdRef.current; const isCurrent = () => client === webClientRef.current && appendProjectId === projectIdRef.current; try { const result = await client.appendLibraryObject(source, request); if (!isCurrent()) return; const logicalRevision = Math.max(projectRevisionRef.current + 1, result.snapshot.revision); projectRevisionRef.current = logicalRevision; const ownsRevision = () => isCurrent() && projectRevisionRef.current === logicalRevision; setSnapshot(result.snapshot); setSelectedObjectIds(selectionFromSnapshot(result.snapshot)); setGeometryBuffers(result.geometryBuffers); setNonMeshGeometryBuffers(result.nonMeshGeometryBuffers ?? []); setFrame(result.snapshot.frame.current); setPreview(null); setLodLevels(null); setDirtyState(current => { const accepted = acceptMainTransaction(current, logicalRevision); return accepted.ok ? accepted.state : current; }); diff --git a/web/tests/e2e/outliner-headed-production.spec.ts b/web/tests/e2e/outliner-headed-production.spec.ts index 07ce45019..08636d357 100644 --- a/web/tests/e2e/outliner-headed-production.spec.ts +++ b/web/tests/e2e/outliner-headed-production.spec.ts @@ -321,6 +321,32 @@ test.describe("Outliner headed baseline", () => { await expect.poll(selectedObjects, { timeout: 15_000 }).toBe(0); }); + test("[outliner-delete-web] X and the Data menu delete objects through the native Main", async ({ page }) => { + test.setTimeout(150_000); + await openWorkbench(page); + 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 before = await objectRows.count(); + + /* Desktop keymap binds outliner.delete to X (and Del); the focused row is + * the deletion target. */ + const lastRow = objectRows.last(); + const label = (await lastRow.getAttribute("aria-label"))!; + await lastRow.locator('.tree-node-name').click(); + await expect.poll(async () => page.locator('.outliner-tree [role="treeitem"]:focus').count(), { timeout: 15_000 }).toBe(1); + await page.keyboard.press("x"); + await expect.poll(() => objectRows.count(), { timeout: 15_000 }).toBe(before - 1); + await expect(page.locator(`.outliner-tree [role="treeitem"][aria-label="${label}"]`)).toHaveCount(0); + + /* The Data menu carries the same OUTLINER_OT_delete entry. */ + const nextRow = objectRows.first(); + const menuLabel = (await nextRow.getAttribute("aria-label"))!; + await nextRow.locator('.tree-node-name').click({ button: "right" }); + await page.getByRole("menuitem", { name: "删除 (X)", exact: true }).click(); + await expect.poll(() => objectRows.count(), { timeout: 15_000 }).toBe(before - 2); + await expect(page.locator(`.outliner-tree [role="treeitem"][aria-label="${menuLabel}"]`)).toHaveCount(0); + }); + test("[outliner-mirror-baseline-web] the desktop mirror hands the Outliner to the DOM workspace", async ({ page }) => { test.setTimeout(120_000); await page.goto("/");