diff --git a/web/docs/current/desktop-parity-continuation.md b/web/docs/current/desktop-parity-continuation.md index 3f3b5682..60bc262f 100644 --- a/web/docs/current/desktop-parity-continuation.md +++ b/web/docs/current/desktop-parity-continuation.md @@ -28,6 +28,19 @@ - 输出 `Part-web.png` 与 `Part-web-audit.json`;0 错误/0 溢出; 缺失菜单仅 `Part_ColorPerFace`(解析器伪菜单,后续修正)。 +## 已完成(P1 骨架) + +- `web/src/shell/`: + - `command-registry.ts`:加载 `desktop-gui-manifest.json`,提供 workbench/命令元数据; + - `menu-bar.tsx`:File/Edit/View/Tools/Macro/Windows/Help + 工作台菜单,支持子菜单与命令; + - `toolbar.tsx`:按 manifest 渲染工作台工具栏; + - `shell-preview.tsx` + `shell-preview.html`:29 个 workbench 选择器、菜单/工具栏、 + three.js 预览视口(网格/坐标轴/Box)、属性/树/状态栏。 +- 页面检查:`http://127.0.0.1:5181/shell-preview.html` 29 个 workbench、3 个工具栏、 + 0 pageError、0 横向溢出;截图 + `web/docs/current/desktop-parity-evidence/shell-preview.png`。 +- 说明:预览页仅渲染清单与命令回调(记录 last command),尚未接入统一文档/执行路由。 + ## 真实残余 - 统一桌面壳尚未实现:project-shell 仍只支持 9 个 workbench、菜单仅 Start/File/Edit/View/Part; @@ -42,9 +55,9 @@ 1. 清理并提交:`tools/parity/extract-desktop-gui.mjs`、`audit-web-gui.mjs`、 `web/public/api/{desktop-gui-manifest,gui-command-gap-report}.json`、 `web/docs/current/desktop-parity-*`;桌面 3 个源码修复单独提交。 -2. P1:新建 `web/src/shell/{app-shell,menu-bar,toolbar,dock-layout,task-view, - command-registry,workbench-registry}.tsx`,先挂 Part 一个 workbench 到统一壳; - 旧页面重定向。 +2. 把 `shell-preview` 的菜单/工具栏挂入 `project-shell.tsx`,用 command registry + 替换静态菜单;Part 先接通 `activatePartAction`,其余 workbench 接 `desktopCommands`/ + `workbench-registry`;旧页面重定向。 3. 修正解析器:去掉空/伪菜单,保留菜单层级;补 Python InitGui 的菜单/工具栏。 4. 每完成一个 workbench:`audit-web-gui.mjs --workbench ` 截图 + 差异 JSON。 diff --git a/web/docs/current/desktop-parity-evidence/shell-preview.png b/web/docs/current/desktop-parity-evidence/shell-preview.png new file mode 100644 index 00000000..0b9482be Binary files /dev/null and b/web/docs/current/desktop-parity-evidence/shell-preview.png differ diff --git a/web/shell-preview.html b/web/shell-preview.html new file mode 100644 index 00000000..418784f4 --- /dev/null +++ b/web/shell-preview.html @@ -0,0 +1,13 @@ + + + + + + +Web FreeCAD · Desktop Shell Preview + + +
+ + + diff --git a/web/src/shell-preview-main.tsx b/web/src/shell-preview-main.tsx new file mode 100644 index 00000000..ec26e313 --- /dev/null +++ b/web/src/shell-preview-main.tsx @@ -0,0 +1,5 @@ +import React from "react"; +import { createRoot } from "react-dom/client"; +import { ShellPreview } from "./shell/shell-preview.js"; + +createRoot(document.querySelector("#app")!).render(); diff --git a/web/src/shell/command-registry.ts b/web/src/shell/command-registry.ts new file mode 100644 index 00000000..790885bd --- /dev/null +++ b/web/src/shell/command-registry.ts @@ -0,0 +1,68 @@ +export type DesktopCommandMetadata = { + menuText: string; + toolTip: string; + icon: string; + accel: string; +}; + +export type DesktopMenuItem = { + type: "command" | "submenu" | "separator"; + id?: string; + label?: string; + ref?: string; + items?: DesktopMenuItem[]; +}; + +export type DesktopMenu = { label: string; items: DesktopMenuItem[] }; +export type DesktopToolbar = { name: string; items: string[] }; +export type DesktopWorkbench = { + id: string; + source: string; + menus: DesktopMenu[]; + toolbars: DesktopToolbar[]; + docks: string[]; +}; +export type DesktopManifest = { + schema: string; + generatedAt: string; + workbenchCount: number; + workbenches: DesktopWorkbench[]; + commandMetadata: Record; + commandCount: number; + menuCommandCount: number; + toolbarCommandCount: number; +}; + +let cache: DesktopManifest | null = null; + +export async function loadDesktopManifest(url = "/api/desktop-gui-manifest.json"): Promise { + if (cache) return cache; + const response = await fetch(url); + if (!response.ok) throw new Error(`desktop manifest HTTP ${response.status}`); + cache = (await response.json()) as DesktopManifest; + return cache; +} + +export function workbenchById(manifest: DesktopManifest, id: string): DesktopWorkbench | undefined { + return manifest.workbenches.find(item => item.id === id); +} + +export function commandLabel(manifest: DesktopManifest, command: string): string { + return manifest.commandMetadata[command]?.menuText?.trim() || command; +} + +export function commandTooltip(manifest: DesktopManifest, command: string): string { + return manifest.commandMetadata[command]?.toolTip?.trim() || command; +} + +export function menuCommandIds(menu: DesktopMenu): string[] { + const out: string[] = []; + const walk = (items: DesktopMenuItem[] = []) => { + for (const item of items) { + if (item.type === "command" && item.id) out.push(item.id); + if (item.items) walk(item.items); + } + }; + walk(menu.items); + return out; +} diff --git a/web/src/shell/menu-bar.tsx b/web/src/shell/menu-bar.tsx new file mode 100644 index 00000000..2057ce9d --- /dev/null +++ b/web/src/shell/menu-bar.tsx @@ -0,0 +1,78 @@ +import React, { useState } from "react"; +import type { DesktopManifest, DesktopMenu, DesktopMenuItem, DesktopWorkbench } from "./command-registry.js"; +import { commandLabel, commandTooltip } from "./command-registry.js"; + +const STANDARD_MENUS: Array<{ label: string; items: string[] }> = [ + { label: "File", items: ["Std_New", "Std_Open", "Std_Save", "Std_Export", "Std_Close"] }, + { label: "Edit", items: ["Std_Undo", "Std_Redo"] }, + { label: "View", items: ["Std_ViewFitAll", "Std_ViewIsometric", "Std_ViewTop", "Std_ViewFront"] }, + { label: "Tools", items: ["Std_DlgPreferences", "Std_DlgCustomize", "Std_UnitsCalculator"] }, + { label: "Macro", items: ["Std_MacroStartDebug", "Std_MacroStopDebug"] }, + { label: "Windows", items: ["Std_DockViewMenu", "Std_TileWindows"] }, + { label: "Help", items: ["Std_About", "Std_OnlineHelp"] }, +]; + +function MenuItems({ items, manifest, onCommand }: { + items: DesktopMenuItem[]; + manifest: DesktopManifest; + onCommand?: (id: string) => void; +}) { + return
+ {items.map((item, index) => { + if (item.type === "separator") return
; + if (item.type === "submenu") return
+ {item.label ?? "Submenu"} + +
; + if (!item.id) return null; + return ; + })} +
; +} + +export function DesktopMenuBar({ manifest, workbench, onCommand, initialOpen }: { + manifest: DesktopManifest; + workbench: DesktopWorkbench; + onCommand?: (id: string) => void; + initialOpen?: string; +}) { + const [open, setOpen] = useState(initialOpen ?? ""); + const menus: DesktopMenu[] = workbench.menus; + return ; +} diff --git a/web/src/shell/shell-preview.tsx b/web/src/shell/shell-preview.tsx new file mode 100644 index 00000000..2f5f15e1 --- /dev/null +++ b/web/src/shell/shell-preview.tsx @@ -0,0 +1,110 @@ +import React, { useEffect, useRef, useState } from "react"; +import * as THREE from "three"; +import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js"; +import { DesktopMenuBar } from "./menu-bar.js"; +import { DesktopToolbars } from "./toolbar.js"; +import { loadDesktopManifest, workbenchById, type DesktopManifest } from "./command-registry.js"; + +function PreviewViewport() { + const host = useRef(null); + useEffect(() => { + const container = host.current; + if (!container) return; + const scene = new THREE.Scene(); + scene.background = new THREE.Color(0x0d1318); + const camera = new THREE.PerspectiveCamera(45, 1, 0.1, 10000); + camera.up.set(0, 0, 1); + camera.position.set(160, -220, 160); + const renderer = new THREE.WebGLRenderer({ antialias: true }); + renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2)); + container.appendChild(renderer.domElement); + renderer.domElement.style.width = "100%"; + renderer.domElement.style.height = "100%"; + renderer.domElement.style.display = "block"; + scene.add(new THREE.HemisphereLight(0xffffff, 0x223344, 1.8)); + const light = new THREE.DirectionalLight(0xffffff, 1.6); light.position.set(200, -300, 400); scene.add(light); + const grid = new THREE.GridHelper(400, 20, 0x3f5a66, 0x223039); + grid.rotation.x = Math.PI / 2; scene.add(grid); + const axes = new THREE.AxesHelper(80); scene.add(axes); + const box = new THREE.Mesh(new THREE.BoxGeometry(80, 60, 20), new THREE.MeshStandardMaterial({ color: 0x73c6d4, metalness: 0.2, roughness: 0.6 })); + box.position.set(0, 0, 10); scene.add(box); + const controls = new OrbitControls(camera, renderer.domElement); + controls.enableDamping = true; controls.target.set(0, 0, 0); controls.update(); + const resize = () => { + const width = container.clientWidth || 600; const height = container.clientHeight || 400; + renderer.setSize(width, height, false); camera.aspect = width / height; camera.updateProjectionMatrix(); + }; + resize(); const observer = new ResizeObserver(resize); observer.observe(container); + let frame = 0; + const animate = () => { frame = requestAnimationFrame(animate); controls.update(); renderer.render(scene, camera); }; + animate(); + return () => { cancelAnimationFrame(frame); observer.disconnect(); controls.dispose(); renderer.dispose(); if (renderer.domElement.parentElement === container) container.removeChild(renderer.domElement); }; + }, []); + return
; +} + +export function ShellPreview() { + const [manifest, setManifest] = useState(null); + const [workbenchId, setWorkbenchId] = useState("Part"); + const [lastCommand, setLastCommand] = useState(""); + const [error, setError] = useState(""); + useEffect(() => { + loadDesktopManifest().then(setManifest).catch(loadError => setError(String(loadError?.message ?? loadError))); + }, []); + const workbench = manifest ? workbenchById(manifest, workbenchId) : undefined; + return
+ +
+ Web FreeCAD · Desktop Shell Preview + + {manifest ? `${manifest.workbenches.length} workbenches · ${manifest.commandCount} commands` : "loading manifest…"} + {lastCommand ? `last: ${lastCommand}` : ""} +
+ {error &&

{error}

} + {manifest && workbench && setLastCommand(command)} />} + {manifest && workbench && setLastCommand(command)} />} +
+ + + +
+
+ Ready + {workbench ? `${workbench.menus.length} menus` : ""} + {workbench ? `${workbench.toolbars.length} toolbars` : ""} + {workbench?.source ?? ""} +
+
; +} diff --git a/web/src/shell/toolbar.tsx b/web/src/shell/toolbar.tsx new file mode 100644 index 00000000..d85c7d28 --- /dev/null +++ b/web/src/shell/toolbar.tsx @@ -0,0 +1,26 @@ +import React from "react"; +import type { DesktopManifest, DesktopWorkbench } from "./command-registry.js"; +import { commandLabel, commandTooltip } from "./command-registry.js"; + +export function DesktopToolbars({ manifest, workbench, onCommand }: { + manifest: DesktopManifest; + workbench: DesktopWorkbench; + onCommand?: (id: string) => void; +}) { + return
+ + {workbench.toolbars.map(toolbar =>
+ {toolbar.name} + {toolbar.items.slice(0, 18).map(command => )} +
)} +
; +} diff --git a/web/vite.config.ts b/web/vite.config.ts index 010ff10a..2dcacda0 100644 --- a/web/vite.config.ts +++ b/web/vite.config.ts @@ -31,6 +31,7 @@ export default defineConfig({ document: "document.html", "main-chain": "main-chain.html", project: "project.html", + "shell-preview": "shell-preview.html", full: "full.html", workbench: "workbench.html", python: "python.html",