Add React task frame bridge for manifest commands

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
2026-11-13 16:46:09 +08:00
parent 452f0b976f
commit 4a45ffaf47
4 changed files with 35 additions and 32 deletions

View File

@@ -83,8 +83,7 @@ import { RecoveryController } from "./recovery-controller.js";
import { mountQueueRecoveryPanel } from "./queue-recovery-panel.js";
import { PartDesignWorkspace } from "./partdesign-workspace-component.js";
import { ParityWorkbenchMenu } from "./shell/workbench-menu.js";
import { DesktopCommandDispatcher } from "./desktop-command-dispatcher.js";
import type { WorkbenchCommandRecord } from "./workbench-command-facade.js";
import { TaskFrame } from "./shell/task-frame.js";
import { DocumentTree, type DocumentTreeNode } from "./document-tree.js";
import { PARTDESIGN_DOCUMENT_COMMAND, PARTDESIGN_DOCUMENT_SCHEMA, type DesignAction, type DesignPayload, type DesignResult } from "./partdesign-document-facade.js";
@@ -313,8 +312,7 @@ function App() {
const [designSnapshots, setDesignSnapshots] = useState<Record<string, DesignResult>>({});
const [workbenches, setWorkbenches] = useState<Record<string, "Part" | "Sketcher" | "PartDesign" | "Spreadsheet" | "Surface" | "Assembly" | "Draft" | "Architecture" | "TechDraw" | "CAM">>(() => initialWorkbench ? { [initialDocumentId]: initialWorkbench } : {});
const workbench = workbenches[active] ?? "Part";
const desktopDispatcher = useRef<DesktopCommandDispatcher | null>(null);
const desktopCommandRecords = useRef<Promise<Array<Record<string, unknown>>> | null>(null);
const [parityTask, setParityTask] = useState<{ module: string; command: string } | null>(null);
const [selectedSheets, setSelectedSheets] = useState<Record<string, string>>({});
const [csvPanel, setCsvPanel] = useState<{ id: string; mode: "import" | "export"; selected?: string; done(result: Record<string, unknown>): void } | null>(null);
const [sheetRanges, setSheetRanges] = useState<Record<string, string>>({});
@@ -1704,32 +1702,10 @@ function App() {
|| !!workspaceTask || !!viewCommand || !!csvPanel
|| item.command === "Part_ColorPerFace" && (compoundSelection.length !== 1
|| !partSnapshots[active]?.objects?.some(object => object.name === compoundSelection[0] && object.topology?.Face && object.type !== "App::Link"));
const executeManifestCommand = async (command: string) => {
const executeManifestCommand = (command: string) => {
if (!active) return;
setStatus(`${command}: running`);
try {
desktopDispatcher.current ??= new DesktopCommandDispatcher(router);
if (!desktopCommandRecords.current) {
desktopCommandRecords.current = fetch("/api/workbench-command-matrix.json").then(async response => {
if (!response.ok) throw new Error(`command matrix HTTP ${response.status}`);
const payload = await response.json() as { records?: WorkbenchCommandRecord[] };
return payload.records ?? [];
});
}
const records = await desktopCommandRecords.current as WorkbenchCommandRecord[];
const record = records.find(item => item.command === command
&& [workbench, "Web", "Std"].includes(item.module))
?? records.find(item => item.command === command);
if (!record) throw new Error("no command matrix record");
const response = await Promise.race([
desktopDispatcher.current.execute(record, {}, nativeName(active)),
new Promise<never>((_, reject) => setTimeout(() => reject(new Error("command timed out; open its workbench task")), 20000)),
]);
if (response.kind === "error") setStatus(`${command}: ${response.error.message}`);
else setStatus(`${command}: executed`);
} catch (error) {
setStatus(`${command}: ${String((error as Error)?.message ?? error)}`);
}
setParityTask({ module: workbench, command });
setStatus(`${command}: opened React task frame`);
};
const activatePartAction = (item: PartUiAction) => {
@@ -3148,6 +3124,8 @@ function App() {
<div className="stat"><strong>Recent files</strong><small>{store.recent().length}</small></div>
{developerMode && <div className="stat"><strong>Checkpoint</strong><small>localStorage metadata only</small></div>}
</aside>{referenceOpen && <DeltaReferencePanel onClose={() => setReferenceOpen(false)} />}
{parityTask && <TaskFrame module={parityTask.module} command={parityTask.command}
onClose={() => setParityTask(null)} />}
{lineReferenceOpen && <LineReferencePanel onClose={() => setLineReferenceOpen(false)} />}</div><footer className="desktop-status-bar" aria-label="Status bar"><p role="status" data-import-phase={importPhase} className={`status ${response?.kind === "error" ? "error" : response?.kind === "result" ? "ok" : ""}`}>{status}</p></footer></PersistentToolbarWorkspace></div>;
}

View File

@@ -0,0 +1,24 @@
import React from "react";
export function TaskFrame({ module, command, onClose }: {
module: string;
command: string;
onClose: () => void;
}) {
const src = `/workbench.html?module=${encodeURIComponent(module)}&command=${encodeURIComponent(command)}`;
return <div className="parity-task-frame" role="dialog" aria-label={`${module} task: ${command}`}>
<style>{`
.parity-task-frame{position:fixed;inset:0;background:#000b;z-index:80;display:flex;align-items:center;justify-content:center;padding:20px}
.parity-task-frame>section{width:min(1280px,96vw);height:min(860px,92vh);background:#0f1419;border:1px solid #3f3f3f;border-radius:8px;display:flex;flex-direction:column;overflow:hidden}
.parity-task-frame header{display:flex;align-items:center;gap:10px;padding:8px 12px;background:#1b242c;border-bottom:1px solid #3f3f3f;color:#dbe6ee;font:13px system-ui,"Noto Sans SC",sans-serif}
.parity-task-frame header strong{font-size:13px}
.parity-task-frame header button{margin-left:auto;background:#2b2b2b;color:#dbe6ee;border:1px solid #555;border-radius:4px;padding:3px 10px;cursor:pointer}
.parity-task-frame iframe{flex:1;width:100%;border:0;background:#0f1419}
`}</style>
<section>
<header><strong>{module} · {command}</strong><span style={{ color: "#93a6b3" }}>任务桥(复用工作台任务面板)</span>
<button type="button" aria-label="Close task frame" onClick={onClose}>关闭</button></header>
<iframe title={`${module} ${command} task`} src={src} />
</section>
</div>;
}