Wire manifest workbench menus into project shell
Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
67
web/src/shell/workbench-menu.tsx
Normal file
67
web/src/shell/workbench-menu.tsx
Normal file
@@ -0,0 +1,67 @@
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { commandLabel, commandTooltip, loadDesktopManifest, workbenchById,
|
||||
type DesktopManifest, type DesktopMenuItem, type DesktopWorkbench } from "./command-registry.js";
|
||||
|
||||
function Items({ items, manifest, onCommand }: {
|
||||
items: DesktopMenuItem[];
|
||||
manifest: DesktopManifest;
|
||||
onCommand: (id: string) => void;
|
||||
}) {
|
||||
return <div className="parity-menu-items">
|
||||
{items.map((item, index) => {
|
||||
if (item.type === "separator") return <hr key={`sep-${index}`} />;
|
||||
if (item.type === "submenu") return <details key={`sub-${index}`}>
|
||||
<summary>{item.label}</summary>
|
||||
<Items items={item.items ?? []} manifest={manifest} onCommand={onCommand} />
|
||||
</details>;
|
||||
if (!item.id) return null;
|
||||
return <button key={item.id} type="button" title={commandTooltip(manifest, item.id)}
|
||||
onClick={() => onCommand(item.id!)}>
|
||||
<span>{commandLabel(manifest, item.id)}</span>
|
||||
{manifest.commandMetadata[item.id]?.accel ? <kbd>{manifest.commandMetadata[item.id].accel}</kbd> : null}
|
||||
</button>;
|
||||
})}
|
||||
</div>;
|
||||
}
|
||||
|
||||
export function ParityWorkbenchMenu({ workbench, onCommand }: {
|
||||
workbench: string;
|
||||
onCommand: (id: string) => void;
|
||||
}) {
|
||||
const [manifest, setManifest] = useState<DesktopManifest | null>(null);
|
||||
const [desktop, setDesktop] = useState<DesktopWorkbench | null>(null);
|
||||
const [open, setOpen] = useState(false);
|
||||
useEffect(() => {
|
||||
if (workbench === "Part") return;
|
||||
let cancelled = false;
|
||||
loadDesktopManifest().then(data => {
|
||||
if (cancelled) return;
|
||||
setManifest(data);
|
||||
setDesktop(workbenchById(data, workbench) ?? null);
|
||||
}).catch(() => { if (!cancelled) setDesktop(null); });
|
||||
return () => { cancelled = true; };
|
||||
}, [workbench]);
|
||||
useEffect(() => setOpen(false), [workbench]);
|
||||
if (workbench === "Part" || !manifest || !desktop) return null;
|
||||
return <details className="parity-workbench-menu" open={open}>
|
||||
<style>{`
|
||||
.parity-workbench-menu{position:relative;display:inline-block}
|
||||
.parity-workbench-menu>summary{list-style:none;cursor:pointer;padding:4px 10px;border-radius:3px;color:#dbe6ee}
|
||||
.parity-workbench-menu>summary::-webkit-details-marker{display:none}
|
||||
.parity-workbench-menu[open]>summary,.parity-workbench-menu>summary:hover{background:#3d4a52}
|
||||
.parity-workbench-menu .parity-menu-items{position:absolute;top:100%;left:0;min-width:280px;max-height:72vh;overflow:auto;background:#0f1419;border:1px solid #3f3f3f;box-shadow:0 12px 32px #0009;padding:6px;z-index:40;border-radius:0 0 6px 6px}
|
||||
.parity-menu-items>button{display:flex;width:100%;justify-content:space-between;gap:16px;background:transparent;border:0;color:#dbe6ee;padding:3px 7px;text-align:left;border-radius:3px;font-size:12.5px;cursor:pointer}
|
||||
.parity-menu-items>button:hover{background:#29444b}
|
||||
.parity-menu-items kbd{color:#93a6b3;font-size:11px}
|
||||
.parity-menu-items summary{cursor:pointer;padding:3px 7px;border-radius:3px;font-size:12.5px}
|
||||
.parity-menu-items summary:hover{background:#22313b}
|
||||
.parity-menu-items details .parity-menu-items{padding-left:12px;border-left:1px solid #2a3a45;margin-left:8px}
|
||||
.parity-menu-items hr{border:0;border-top:1px solid #2a3a45;margin:4px 0}
|
||||
`}</style>
|
||||
<summary aria-label={`${workbench} menu`} onClick={event => { event.preventDefault(); setOpen(value => !value); }}>
|
||||
{workbench}
|
||||
</summary>
|
||||
<Items items={desktop.menus.map(menu => ({ type: "submenu" as const, label: menu.label, items: menu.items }))}
|
||||
manifest={manifest} onCommand={id => { setOpen(false); onCommand(id); }} />
|
||||
</details>;
|
||||
}
|
||||
Reference in New Issue
Block a user