A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
refactor(editor): graph editors onto canonical tokens + shared context menu
yhh16dd008cf817
diff --git a/desktop/src/main.tsx b/desktop/src/main.tsxindex 6bae5ac4c..2773ebccf 100644--- a/desktop/src/main.tsx+++ b/desktop/src/main.tsx@@ -26,6 +26,7 @@ import './theme/profiler.css';import './theme/tileset.css';import './theme/tilemap.css';import './theme/material.css';+import './theme/nodegraph.css';import './theme/chrome.css';import './theme/menus.css';import './theme/settings.css';diff --git a/desktop/src/panels/BtTreeEditor.tsx b/desktop/src/panels/BtTreeEditor.tsxindex 7c470fece..9647bea7f 100644--- a/desktop/src/panels/BtTreeEditor.tsx+++ b/desktop/src/panels/BtTreeEditor.tsx@@ -10,7 +10,7 @@* Uses the generic <NodeGraphCanvas> (shared with StateMachineEditor):* drag-to-connect reparents a node under the drop target.*/-import { useRef, useState, useSyncExternalStore, type CSSProperties } from 'react';+import { useRef, useState, useSyncExternalStore } from 'react';import { Trash2, Save } from 'lucide-react';import {btNodes, btEdges, addBtChild, addBtOrphan, removeBtNode, moveBtNode, setBtNodeField, reparentBtNode,@@ -62,7 +62,7 @@ export function BtTreeEditor() {const dragBefore = useRef<BtDefinition | null>(null);if (!def || !filePath) {- return <div className="panel" style={S.empty}><p>Open a <code>.esbt</code> from the Content Browser to edit it.</p></div>;+ return <div className="panel ng-placeholder"><p>Open a <code>.esbt</code> from the Content Browser to edit it.</p></div>;}const nodes = btNodes(def).filter((n): n is BtCanvasNode => !!n.id);@@ -82,23 +82,23 @@ export function BtTreeEditor() {const toolbar = (<>- <span style={S.title}>{filePath.split('/').pop()}{dirty && <span style={S.dot} title="Unsaved">●</span>}</span>+ <span className="ng-doc-title">{filePath.split('/').pop()}{dirty && <span className="ng-dirty" title="Unsaved">●</span>}</span><span style={{ flex: 1 }} />{selected && def.root.id !== selected && (- <button type="button" style={S.btn} title="Delete node"+ <button type="button" className="ng-btn" title="Delete node"onClick={() => { BtDocument.edit('Delete node', d => Object.assign(d, removeBtNode(d, selected))); setSelected(null); }}><Trash2 size={13} strokeWidth={1.9} /></button>)}- <button type="button" style={{ ...S.btn, ...S.primary }} disabled={!dirty} onClick={save}>+ <button type="button" className="ng-btn primary" disabled={!dirty} onClick={save}><Save size={13} strokeWidth={1.9} /> Save</button></>);return (- <div style={S.root} data-bt-canvas>- <div style={S.body}>+ <div className="ng-editor" data-bt-canvas>+ <div className="ng-editor-body"><div style={{ flex: 1, minWidth: 0 }}><NodeGraphCanvas<BtCanvasNode, BtEdge>nodes={nodes}@@ -133,8 +133,8 @@ export function BtTreeEditor() {for (const spec of BT_TYPES) items.push({ label: `Add child: ${spec.label}`, onClick: () => BtDocument.edit('Add node', d => Object.assign(d, addBtChild(d, parentId, spec.type, target.x, target.y))) });}if (def.root.id !== parentId) {- if (items.length) items.push({ label: '', sep: true, onClick: () => { /* separator */ } });- items.push({ label: 'Delete node', onClick: () => { BtDocument.edit('Delete node', d => Object.assign(d, removeBtNode(d, parentId))); setSelected(null); } });+ if (items.length) items.push({ sep: true });+ items.push({ label: 'Delete node', danger: true, onClick: () => { BtDocument.edit('Delete node', d => Object.assign(d, removeBtNode(d, parentId))); setSelected(null); } });}return items;}}@@ -143,9 +143,9 @@ export function BtTreeEditor() {renderNode={(n, sel) => {const spec = specOf(n.type);return (- <div style={{ ...S.node, borderColor: sel ? 'var(--accent, #6ea9ff)' : (def.root.id === n.id ? '#c98a93' : CAT_COLOR[spec.cat]) }}>- <div style={S.nodeType}>{def.root.id === n.id ? '▶ ' : ''}{spec.label}</div>- <div style={S.nodeSub}>{leafSummary(n)}</div>+ <div className={`ng-node-box${sel ? ' sel' : ''}`} style={!sel ? { borderColor: def.root.id === n.id ? 'var(--nebula)' : CAT_COLOR[spec.cat] } : undefined}>+ <div className="ng-node-head"><span className="ng-node-name">{def.root.id === n.id ? '▶ ' : ''}{spec.label}</span></div>+ <div className="ng-node-sub">{leafSummary(n)}</div></div>);}}@@ -153,36 +153,36 @@ export function BtTreeEditor() {</div>{selNode && (- <div style={S.inspector}>- <div style={S.inspTitle}>Node</div>- <label style={S.field}>Type- <select style={S.input} value={selNode.type} onChange={e => patch(selNode.id, { type: e.target.value as BtNodeType })}>+ <div className="ng-inspector">+ <div className="ng-insp-title">Node</div>+ <label className="ng-field">Type+ <select className="ng-input" value={selNode.type} onChange={e => patch(selNode.id, { type: e.target.value as BtNodeType })}>{BT_TYPES.map(s => <option key={s.type} value={s.type}>{s.label}</option>)}</select></label>{(selNode.type === 'action' || selNode.type === 'condition') && (- <label style={S.field}>Name- <input style={S.input} list="bt-names" defaultValue={selNode.name ?? ''} key={`${selNode.id}-name`}+ <label className="ng-field">Name+ <input className="ng-input" list="bt-names" defaultValue={selNode.name ?? ''} key={`${selNode.id}-name`}placeholder={selNode.type === 'action' ? 'action name' : 'condition name'}onBlur={e => patch(selNode.id, { name: e.target.value.trim() || undefined })} /></label>)}{selNode.type === 'repeater' && (- <label style={S.field}>Count (0 = forever)- <input style={S.input} type="number" min={0} defaultValue={selNode.count ?? 0} key={`${selNode.id}-count`}+ <label className="ng-field">Count (0 = forever)+ <input className="ng-input" type="number" min={0} defaultValue={selNode.count ?? 0} key={`${selNode.id}-count`}onBlur={e => patch(selNode.id, { count: Number(e.target.value) || 0 })} /></label>)}{selNode.type === 'wait' && (- <label style={S.field}>Seconds- <input style={S.input} type="number" min={0} step={0.1} defaultValue={selNode.seconds ?? 0} key={`${selNode.id}-sec`}+ <label className="ng-field">Seconds+ <input className="ng-input" type="number" min={0} step={0.1} defaultValue={selNode.seconds ?? 0} key={`${selNode.id}-sec`}onBlur={e => patch(selNode.id, { seconds: Number(e.target.value) || 0 })} /></label>)}{selNode.type === 'parallel' && (- <label style={S.field}>Success policy- <select style={S.input} value={selNode.policy ?? 'all'} onChange={e => patch(selNode.id, { policy: e.target.value as 'all' | 'one' })}>+ <label className="ng-field">Success policy+ <select className="ng-input" value={selNode.policy ?? 'all'} onChange={e => patch(selNode.id, { policy: e.target.value as 'all' | 'one' })}><option value="all">all children</option><option value="one">any child</option></select>@@ -191,12 +191,12 @@ export function BtTreeEditor() {{canHaveChildren(selNode.type) && (<>- <div style={S.inspSub}>Add child</div>- <div style={{ display: 'flex', gap: 4 }}>- <select style={{ ...S.input, flex: 1 }} value={addType} onChange={e => setAddType(e.target.value as BtNodeType)}>+ <div className="ng-insp-sub">Add child</div>+ <div className="ng-row">+ <select className="ng-input" style={{ flex: 1 }} value={addType} onChange={e => setAddType(e.target.value as BtNodeType)}>{BT_TYPES.map(s => <option key={s.type} value={s.type}>{s.label}</option>)}</select>- <button type="button" style={S.btn} onClick={() => addChild(selNode.id, addType)}>+ Add</button>+ <button type="button" className="ng-btn" onClick={() => addChild(selNode.id, addType)}>+ Add</button></div></>)}@@ -209,21 +209,3 @@ export function BtTreeEditor() {</div>);}--const S: Record<string, CSSProperties> = {- root: { display: 'flex', flexDirection: 'column', height: '100%' },- empty: { display: 'flex', alignItems: 'center', justifyContent: 'center', height: '100%', opacity: 0.6, fontSize: 13 },- body: { display: 'flex', flex: 1, minHeight: 0 },- title: { fontSize: 12, opacity: 0.85 },- dot: { color: '#e0a03a', marginLeft: 4 },- btn: { display: 'inline-flex', alignItems: 'center', gap: 4, padding: '3px 8px', fontSize: 12, borderRadius: 4, border: '1px solid var(--border, #333)', background: 'var(--panel, #222)', color: 'inherit', cursor: 'pointer' },- primary: { background: 'var(--accent, #3a6ea5)', borderColor: 'transparent' },- node: { boxSizing: 'border-box', width: '100%', height: '100%', borderRadius: 6, border: '1.5px solid #3a4048', background: 'var(--node, #232830)', boxShadow: '0 1px 3px rgba(0,0,0,0.4)', padding: 6, display: 'flex', flexDirection: 'column', justifyContent: 'center' },- nodeType: { fontSize: 12, fontWeight: 600 },- nodeSub: { fontSize: 10, opacity: 0.75, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' },- inspector: { width: 232, flexShrink: 0, borderLeft: '1px solid var(--border, #2a2f36)', padding: 10, overflow: 'auto', fontSize: 12 },- inspTitle: { fontSize: 11, textTransform: 'uppercase', letterSpacing: 0.5, opacity: 0.6, marginBottom: 8 },- inspSub: { fontSize: 11, opacity: 0.6, margin: '10px 0 4px' },- field: { display: 'flex', flexDirection: 'column', gap: 3, marginBottom: 8, fontSize: 11 },- input: { padding: '3px 6px', fontSize: 12, borderRadius: 4, border: '1px solid var(--border, #333)', background: 'var(--input, #1a1d22)', color: 'inherit' },-};diff --git a/desktop/src/panels/NodeGraphCanvas.tsx b/desktop/src/panels/NodeGraphCanvas.tsxindex 2229fb932..37dfa2338 100644--- a/desktop/src/panels/NodeGraphCanvas.tsx+++ b/desktop/src/panels/NodeGraphCanvas.tsx@@ -9,9 +9,13 @@* selection, delete, bezier + self-loops). Everything domain-specific — node body,* edge label, sizes, connect policy — is injected via props, so FSM (arbitrary* guarded edges, cycles) and BT (parent/child tree edges) both drive it. Extracted- * from the proven StateMachineEditor canvas.+ * from the proven StateMachineEditor canvas. Styling lives in theme/nodegraph.css;+ * right-click menus are the shared <ContextMenu>.*/-import { useEffect, useRef, useState, type ReactNode, type CSSProperties, type MouseEvent as ReactMouseEvent } from 'react';+import { useEffect, useRef, useState, type ReactNode, type MouseEvent as ReactMouseEvent } from 'react';+import { ContextMenu, type MenuItem } from '@/components/Menu';++export type { MenuItem };export interface CanvasNode {id: string;@@ -25,14 +29,6 @@ export interface CanvasEdge {to: string;}-export interface MenuItem {- label: string;- onClick: () => void;- disabled?: boolean;- /** Render a separator instead of an item (label/onClick ignored). */- sep?: boolean;-}-export interface ContextTarget {kind: 'canvas' | 'node';nodeId?: string;@@ -208,9 +204,9 @@ export function NodeGraphCanvas<N extends CanvasNode, E extends CanvasEdge>(prop};return (- <div className="panel" style={S.root}>- {toolbar && <div style={S.bar}>{toolbar}</div>}- <div style={{ ...S.canvas, backgroundSize: `${20 * vp.zoom}px ${20 * vp.zoom}px`, backgroundPosition: `${vp.x}px ${vp.y}px` }} ref={canvasRef}+ <div className="panel ng-root">+ {toolbar && <div className="ng-bar">{toolbar}</div>}+ <div className="ng-canvas" style={{ backgroundSize: `${20 * vp.zoom}px ${20 * vp.zoom}px`, backgroundPosition: `${vp.x}px ${vp.y}px` }} ref={canvasRef}onPointerDown={e => {if (e.button === 1) { e.preventDefault(); pan.current = { sx: e.clientX, sy: e.clientY, vx: vp.x, vy: vp.y }; return; }onSelectNode(null); onSelectEdge(null);@@ -228,15 +224,15 @@ export function NodeGraphCanvas<N extends CanvasNode, E extends CanvasEdge>(prop});}}onContextMenu={e => { const p = toCanvas(e.clientX, e.clientY); openMenu(e, { kind: 'canvas', x: p.x, y: p.y }); }}>- {nodes.length === 0 && emptyHint && <div style={S.empty}>{emptyHint}</div>}+ {nodes.length === 0 && emptyHint && <div className="ng-empty">{emptyHint}</div>}<div style={{ position: 'absolute', top: 0, left: 0, transform: `translate(${vp.x}px, ${vp.y}px) scale(${vp.zoom})`, transformOrigin: '0 0' }}>- <svg style={S.svg}>+ <svg className="ng-svg"><defs><marker id="ng-arrow" markerWidth="9" markerHeight="9" refX="7.5" refY="3" orient="auto" markerUnits="userSpaceOnUse">- <path d="M0,0 L7.5,3 L0,6 Z" fill="#7d8794" />+ <path d="M0,0 L7.5,3 L0,6 Z" fill="var(--text-faint)" /></marker><marker id="ng-arrow-sel" markerWidth="9" markerHeight="9" refX="7.5" refY="3" orient="auto" markerUnits="userSpaceOnUse">- <path d="M0,0 L7.5,3 L0,6 Z" fill="var(--accent, #6ea9ff)" />+ <path d="M0,0 L7.5,3 L0,6 Z" fill="var(--star)" /></marker></defs>{edges.map(e => {@@ -249,7 +245,7 @@ export function NodeGraphCanvas<N extends CanvasNode, E extends CanvasEdge>(prop<g key={e.id}><path d={d} stroke="transparent" strokeWidth={12} fill="none" style={{ cursor: 'pointer' }}onPointerDown={ev => { ev.stopPropagation(); onSelectEdge(e.id); onSelectNode(null); }} />- <path d={d} stroke={sel ? 'var(--accent, #6ea9ff)' : '#7d8794'} strokeWidth={sel ? 2.5 : 1.6} fill="none" markerEnd={`url(#ng-arrow${sel ? '-sel' : ''})`} />+ <path d={d} stroke={sel ? 'var(--star)' : 'var(--text-faint)'} strokeWidth={sel ? 2.5 : 1.6} fill="none" markerEnd={`url(#ng-arrow${sel ? '-sel' : ''})`} /></g>);})}@@ -257,7 +253,7 @@ export function NodeGraphCanvas<N extends CanvasNode, E extends CanvasEdge>(propconst from = byId.get(wire.current.from);if (!from) return null;const a = out(from);- return <path d={bezier(a.x, a.y, cursor.x, cursor.y)} stroke="#6ea9ff" strokeWidth={1.6} strokeDasharray="4 3" fill="none" />;+ return <path d={bezier(a.x, a.y, cursor.x, cursor.y)} stroke="var(--star-hi)" strokeWidth={1.6} strokeDasharray="4 3" fill="none" />;})()}</svg>@@ -267,7 +263,7 @@ export function NodeGraphCanvas<N extends CanvasNode, E extends CanvasEdge>(propif (!from || !to) return null;const { mx, my } = edgeGeom(from, to, e);return (- <div key={`lbl-${e.id}`} style={{ ...S.edgeLabel, left: mx - 40, top: my - 9, borderColor: selectedEdge === e.id ? 'var(--accent, #6ea9ff)' : 'transparent' }}+ <div key={`lbl-${e.id}`} className={`ng-edge-label${selectedEdge === e.id ? ' sel' : ''}`} style={{ left: mx - 40, top: my - 9 }}onPointerDown={ev => { ev.stopPropagation(); onSelectEdge(e.id); onSelectNode(null); }}>{renderEdgeLabel(e)}</div>@@ -280,7 +276,7 @@ export function NodeGraphCanvas<N extends CanvasNode, E extends CanvasEdge>(propconst droppable = wiring && wire.current !== null && (allowSelfLoop || wire.current.from !== n.id);const showInput = hasInput?.(n) ?? true;return (- <div key={n.id} style={{ ...S.node, left: nx(n), top: ny(n), width: s.width, height: s.height, outline: droppable ? '2px dashed #6ea9ff' : undefined, outlineOffset: 3 }}+ <div key={n.id} className={`ng-node${droppable ? ' droppable' : ''}`} style={{ left: nx(n), top: ny(n), width: s.width, height: s.height }}onPointerDown={e => {e.stopPropagation();onSelectNode(n.id); onSelectEdge(null);@@ -289,9 +285,9 @@ export function NodeGraphCanvas<N extends CanvasNode, E extends CanvasEdge>(proponMoveNodeStart?.(n.id);}}onContextMenu={e => { e.stopPropagation(); onSelectNode(n.id); const p = toCanvas(e.clientX, e.clientY); openMenu(e, { kind: 'node', nodeId: n.id, x: p.x, y: p.y }); }}>- {showInput && <span style={{ ...S.inAnchor, top: s.height / 2 - 5 }} aria-hidden title="Edges land here" />}+ {showInput && <span className="ng-in-anchor" style={{ top: s.height / 2 - 5 }} aria-hidden title="Edges land here" />}{renderNode(n, selectedNode === n.id)}- <span style={{ ...S.handle, top: s.height / 2 - 7 }} title="Drag to another node to connect"+ <span className="ng-handle" style={{ top: s.height / 2 - 7 }} title="Drag to another node to connect"onPointerDown={e => { e.stopPropagation(); wire.current = { from: n.id }; setWiring(true); setCursor(toCanvas(e.clientX, e.clientY)); }} /></div>);@@ -300,40 +296,8 @@ export function NodeGraphCanvas<N extends CanvasNode, E extends CanvasEdge>(prop</div>{menu && menuItems && (- <>- <div style={S.menuOverlay} onPointerDown={() => setMenu(null)} onContextMenu={e => { e.preventDefault(); setMenu(null); }} />- <div style={{ ...S.menu, left: menu.screenX, top: menu.screenY }}>- {menuItems(menu.target).map((it, i) => it.sep- ? <div key={i} style={S.menuSep} />- : (- <button key={i} type="button" disabled={it.disabled}- style={{ ...S.menuItem, ...(it.disabled ? S.menuItemDisabled : null) }}- onClick={() => { it.onClick(); setMenu(null); }}>- {it.label}- </button>- ))}- </div>- </>+ <ContextMenu x={menu.screenX} y={menu.screenY} items={menuItems(menu.target)} onClose={() => setMenu(null)} />)}</div>);}--const S: Record<string, CSSProperties> = {- root: { display: 'flex', flexDirection: 'column', height: '100%' },- bar: { display: 'flex', alignItems: 'center', gap: 6, padding: '6px 8px', borderBottom: '1px solid var(--border, #2a2f36)' },- canvas: { position: 'relative', flex: 1, overflow: 'hidden', background: 'var(--canvas, #191c20)', backgroundImage: 'radial-gradient(var(--grid, #262b31) 1px, transparent 1px)' },- empty: { position: 'absolute', inset: 0, display: 'flex', alignItems: 'center', justifyContent: 'center', opacity: 0.5, fontSize: 13, pointerEvents: 'none' },- svg: { position: 'absolute', top: 0, left: 0, width: 4000, height: 4000, overflow: 'visible' },- node: { position: 'absolute', boxSizing: 'border-box', cursor: 'grab', userSelect: 'none' },- // Output handle (right): drag it to another node to connect.- handle: { position: 'absolute', right: -7, width: 14, height: 14, borderRadius: '50%', background: '#6ea9ff', border: '2px solid var(--canvas, #191c20)', boxShadow: '0 0 0 1px #6ea9ff88', cursor: 'crosshair', zIndex: 2 },- // Input anchor (left): a visual cue that edges land on this node.- inAnchor: { position: 'absolute', left: -5, width: 10, height: 10, borderRadius: '50%', background: '#5a6470', border: '2px solid var(--canvas, #191c20)', pointerEvents: 'none' },- edgeLabel: { position: 'absolute', width: 80, textAlign: 'center', fontSize: 10, padding: '1px 3px', borderRadius: 3, background: 'var(--canvas, #191c20)', border: '1px solid transparent', color: '#aeb6c0', cursor: 'pointer', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' },- menuOverlay: { position: 'fixed', inset: 0, zIndex: 100 },- menu: { position: 'fixed', zIndex: 101, minWidth: 156, padding: 4, borderRadius: 6, background: 'var(--panel, #232830)', border: '1px solid var(--border, #333)', boxShadow: '0 4px 16px rgba(0,0,0,0.5)', display: 'flex', flexDirection: 'column' },- menuItem: { textAlign: 'left', padding: '4px 10px', fontSize: 12, border: 'none', background: 'transparent', color: 'inherit', cursor: 'pointer', borderRadius: 4 },- menuItemDisabled: { opacity: 0.4, cursor: 'default' },- menuSep: { height: 1, margin: '4px 2px', background: 'var(--border, #333)' },-};diff --git a/desktop/src/panels/StateMachineEditor.tsx b/desktop/src/panels/StateMachineEditor.tsxindex 85e7cceee..5d23cd223 100644--- a/desktop/src/panels/StateMachineEditor.tsx+++ b/desktop/src/panels/StateMachineEditor.tsx@@ -13,7 +13,7 @@* transition trigger·condition·guard. The canvas interaction is the* generic component shared with the behavior-tree editor.*/-import { useRef, useState, useSyncExternalStore, type CSSProperties } from 'react';+import { useRef, useState, useSyncExternalStore } from 'react';import { Plus, Trash2, Save } from 'lucide-react';import {fsmEdges, addState, removeState, moveState, renameState, setStateHook, setInitial,@@ -57,7 +57,7 @@ export function StateMachineEditor() {const dragBefore = useRef<FsmDefinition | null>(null);if (!def || !filePath) {- return <div className="panel" style={S.empty}><p>Open a <code>.esfsm</code> from the Content Browser to edit it.</p></div>;+ return <div className="panel ng-placeholder"><p>Open a <code>.esfsm</code> from the Content Browser to edit it.</p></div>;}const nodes: FsmCanvasNode[] = def.states.map(s => ({ ...s, id: s.name }));@@ -80,17 +80,17 @@ export function StateMachineEditor() {const toolbar = (<>- <button type="button" style={S.btn} onClick={addStateAt} title="Add state"><Plus size={13} strokeWidth={2} /> State</button>- {(selState || selEdge) && <button type="button" style={S.btn} title="Delete selected" onClick={deleteSelected}><Trash2 size={13} strokeWidth={1.9} /></button>}- <span style={S.title}>{filePath.split('/').pop()}{dirty && <span style={S.dot} title="Unsaved">●</span>}</span>+ <button type="button" className="ng-btn" onClick={addStateAt} title="Add state"><Plus size={13} strokeWidth={2} /> State</button>+ {(selState || selEdge) && <button type="button" className="ng-btn" title="Delete selected" onClick={deleteSelected}><Trash2 size={13} strokeWidth={1.9} /></button>}+ <span className="ng-doc-title">{filePath.split('/').pop()}{dirty && <span className="ng-dirty" title="Unsaved">●</span>}</span><span style={{ flex: 1 }} />- <button type="button" style={{ ...S.btn, ...S.primary }} disabled={!dirty} onClick={save}><Save size={13} strokeWidth={1.9} /> Save</button>+ <button type="button" className="ng-btn primary" disabled={!dirty} onClick={save}><Save size={13} strokeWidth={1.9} /> Save</button></>);return (- <div style={S.root}>- <div style={S.body}>+ <div className="ng-editor">+ <div className="ng-editor-body"><div style={{ flex: 1, minWidth: 0 }}><NodeGraphCanvas<FsmCanvasNode, FsmEdge>nodes={nodes}@@ -115,8 +115,8 @@ export function StateMachineEditor() {? [{ label: 'Add State', onClick: () => { const name = uniqueName(def, 'State'); FsmGraphDocument.edit('Add state', d => Object.assign(d, addState(d, name, target.x, target.y))); setSelState(name); setSelEdge(null); } }]: [{ label: 'Set as initial', disabled: def.initial === target.nodeId, onClick: () => FsmGraphDocument.edit('Set initial', d => Object.assign(d, setInitial(d, target.nodeId!))) },- { label: '', sep: true, onClick: () => { /* separator */ } },- { label: 'Delete state', onClick: () => { FsmGraphDocument.edit('Delete state', d => Object.assign(d, removeState(d, target.nodeId!))); setSelState(null); } },+ { sep: true },+ { label: 'Delete state', danger: true, onClick: () => { FsmGraphDocument.edit('Delete state', d => Object.assign(d, removeState(d, target.nodeId!))); setSelState(null); } },]}toolbar={toolbar}emptyHint="Add a state, then drag from its handle to another to add a transition."@@ -125,12 +125,12 @@ export function StateMachineEditor() {const isInitial = def.initial === n.name;const setHooks = HOOKS.filter(h => n[h]).map(h => `${h[2].toUpperCase()}:${n[h]}`).join(' ');return (- <div style={{ ...S.nodeBox, borderColor: sel ? 'var(--accent, #6ea9ff)' : isInitial ? '#7faf9c' : '#3a4048' }}>- <div style={S.nodeHead}>- {isInitial && <span title="Initial state" style={S.initialBadge}>▶</span>}- <span style={S.nodeName}>{n.name}</span>+ <div className={`ng-node-box${sel ? ' sel' : ''}`} style={!sel && isInitial ? { borderColor: 'var(--run)' } : undefined}>+ <div className="ng-node-head">+ {isInitial && <span title="Initial state" className="ng-node-badge" style={{ color: 'var(--run)' }}>▶</span>}+ <span className="ng-node-name">{n.name}</span></div>- <div style={S.nodeHooks}>{setHooks || <span style={{ opacity: 0.4 }}>no actions</span>}</div>+ <div className="ng-node-sub">{setHooks || <span style={{ opacity: 0.4 }}>no actions</span>}</div></div>);}}@@ -138,7 +138,7 @@ export function StateMachineEditor() {</div>{(selState || selEdge) && (- <div style={S.inspector}>+ <div className="ng-inspector">{selState && byName.get(selState) && <StateInspector def={def} state={byName.get(selState)!} onRename={setSelState} />}{selEdge && parseEdgeId(selEdge) && <TransitionInspector def={def} edgeId={selEdge} />}</div>@@ -153,19 +153,19 @@ function StateInspector({ def, state, onRename }: { def: FsmDefinition; state: Fconst isInitial = def.initial === state.name;return (<div>- <div style={S.inspTitle}>State</div>- <label style={S.field}>Name- <input style={S.input} defaultValue={state.name} key={state.name}+ <div className="ng-insp-title">State</div>+ <label className="ng-field">Name+ <input className="ng-input" defaultValue={state.name} key={state.name}onBlur={(e) => { const v = e.target.value.trim(); if (v && v !== state.name) { FsmGraphDocument.edit('Rename state', (d) => Object.assign(d, renameState(d, state.name, v))); onRename(v); } }} /></label>- <label style={S.checkRow}>+ <label className="ng-check-row"><input type="checkbox" checked={isInitial} disabled={isInitial}onChange={() => FsmGraphDocument.edit('Set initial', (d) => Object.assign(d, setInitial(d, state.name)))} />Initial state</label>{HOOKS.map((h) => (- <label style={S.field} key={h}>{h}- <input style={S.input} list="fsm-actions" defaultValue={state[h] ?? ''} key={`${state.name}-${h}-${state[h] ?? ''}`}+ <label className="ng-field" key={h}>{h}+ <input className="ng-input" list="fsm-actions" defaultValue={state[h] ?? ''} key={`${state.name}-${h}-${state[h] ?? ''}`}placeholder="action name"onBlur={(e) => { const v = e.target.value.trim(); if (v !== (state[h] ?? '')) FsmGraphDocument.edit(`Set ${h}`, (d) => Object.assign(d, setStateHook(d, state.name, h, v))); }} /></label>@@ -190,32 +190,32 @@ function TransitionInspector({ def, edgeId }: { def: FsmDefinition; edgeId: stri};return (<div>- <div style={S.inspTitle}>Transition</div>- <label style={S.field}>Target- <select style={S.input} value={t.to} onChange={(e) => patch({ to: e.target.value })}>+ <div className="ng-insp-title">Transition</div>+ <label className="ng-field">Target+ <select className="ng-input" value={t.to} onChange={(e) => patch({ to: e.target.value })}>{def.states.map((s) => <option key={s.name} value={s.name}>{s.name}</option>)}</select></label>- <label style={S.field}>Trigger (event)- <input style={S.input} defaultValue={t.trigger ?? ''} key={`trg-${edgeId}`} placeholder="event name"+ <label className="ng-field">Trigger (event)+ <input className="ng-input" defaultValue={t.trigger ?? ''} key={`trg-${edgeId}`} placeholder="event name"onBlur={(e) => patch({ trigger: e.target.value.trim() || undefined })} /></label>- <label style={S.field}>Condition- <input style={S.input} list="fsm-conditions" defaultValue={t.condition ?? ''} key={`cnd-${edgeId}`} placeholder="condition name"+ <label className="ng-field">Condition+ <input className="ng-input" list="fsm-conditions" defaultValue={t.condition ?? ''} key={`cnd-${edgeId}`} placeholder="condition name"onBlur={(e) => patch({ condition: e.target.value.trim() || undefined })} /></label><datalist id="fsm-conditions">{conditions.map((c) => <option key={c} value={c} />)}</datalist>- <div style={S.inspSub}>Guard (blackboard)</div>- <div style={{ display: 'flex', gap: 4 }}>- <input style={{ ...S.input, flex: 1 }} defaultValue={g?.key ?? ''} key={`gk-${edgeId}`} placeholder="key"+ <div className="ng-insp-sub">Guard (blackboard)</div>+ <div className="ng-row">+ <input className="ng-input" style={{ flex: 1 }} defaultValue={g?.key ?? ''} key={`gk-${edgeId}`} placeholder="key"onBlur={(e) => patchGuard({ key: e.target.value.trim() })} />- <select style={{ ...S.input, width: 62 }} value={g?.op ?? '=='} onChange={(e) => patchGuard({ op: e.target.value as CompareOp })}>+ <select className="ng-input" style={{ width: 62 }} value={g?.op ?? '=='} onChange={(e) => patchGuard({ op: e.target.value as CompareOp })}>{OPS.map((op) => <option key={op} value={op}>{op}</option>)}</select></div>{g && g.op !== 'truthy' && g.op !== 'falsy' && (- <label style={S.field}>Value- <input style={S.input} defaultValue={String(g?.value ?? '')} key={`gv-${edgeId}`} placeholder="value"+ <label className="ng-field">Value+ <input className="ng-input" defaultValue={String(g?.value ?? '')} key={`gv-${edgeId}`} placeholder="value"onBlur={(e) => patchGuard({ value: coerce(e.target.value) })} /></label>)}@@ -245,24 +245,3 @@ function coerce(v: string): number | string | boolean {if (t !== '' && !Number.isNaN(Number(t))) return Number(t);return t;}--const S: Record<string, CSSProperties> = {- root: { display: 'flex', flexDirection: 'column', height: '100%' },- empty: { display: 'flex', alignItems: 'center', justifyContent: 'center', height: '100%', opacity: 0.6, fontSize: 13 },- body: { display: 'flex', flex: 1, minHeight: 0 },- btn: { display: 'inline-flex', alignItems: 'center', gap: 4, padding: '3px 8px', fontSize: 12, borderRadius: 4, border: '1px solid var(--border, #333)', background: 'var(--panel, #222)', color: 'inherit', cursor: 'pointer' },- primary: { background: 'var(--accent, #3a6ea5)', borderColor: 'transparent' },- title: { fontSize: 12, opacity: 0.85, marginLeft: 4 },- dot: { color: '#e0a03a', marginLeft: 4 },- nodeBox: { boxSizing: 'border-box', width: '100%', height: '100%', borderRadius: 6, border: '1.5px solid #3a4048', background: 'var(--node, #232830)', boxShadow: '0 1px 3px rgba(0,0,0,0.4)', padding: 6 },- nodeHead: { display: 'flex', alignItems: 'center', gap: 5, fontSize: 12.5, fontWeight: 600 },- initialBadge: { color: '#7faf9c', fontSize: 10 },- nodeName: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' },- nodeHooks: { marginTop: 5, fontSize: 10.5, opacity: 0.75, lineHeight: 1.4, overflow: 'hidden' },- inspector: { width: 232, flexShrink: 0, borderLeft: '1px solid var(--border, #2a2f36)', padding: 10, overflow: 'auto', fontSize: 12 },- inspTitle: { fontSize: 11, textTransform: 'uppercase', letterSpacing: 0.5, opacity: 0.6, marginBottom: 8 },- inspSub: { fontSize: 11, opacity: 0.6, margin: '10px 0 4px' },- field: { display: 'flex', flexDirection: 'column', gap: 3, marginBottom: 8, fontSize: 11, opacity: 0.95 },- checkRow: { display: 'flex', alignItems: 'center', gap: 6, marginBottom: 8, fontSize: 12 },- input: { padding: '3px 6px', fontSize: 12, borderRadius: 4, border: '1px solid var(--border, #333)', background: 'var(--input, #1a1d22)', color: 'inherit' },-};diff --git a/desktop/src/theme/nodegraph.css b/desktop/src/theme/nodegraph.cssnew file mode 100644index 000000000..fb21436e3--- /dev/null+++ b/desktop/src/theme/nodegraph.css@@ -0,0 +1,190 @@+/* =============================================================================+ @file nodegraph.css+ @brief Shared node-graph editor chrome — the generic canvas (NodeGraphCanvas)+ plus the editor shell around it (toolbar buttons, doc title, side+ inspector, fields). One visual vocabulary for every graph editor.+ ========================================================================== */++/* — editor shell — */+.ng-editor { display: flex; flex-direction: column; height: 100%; }+.ng-editor-body { display: flex; flex: 1; min-height: 0; }+.ng-placeholder {+ display: flex;+ align-items: center;+ justify-content: center;+ height: 100%;+ color: var(--text-faint);+ font-size: var(--fs-md);+}++/* — canvas — */+.ng-root { display: flex; flex-direction: column; height: 100%; }+.ng-bar {+ display: flex;+ align-items: center;+ gap: 6px;+ padding: 6px 8px;+ border-bottom: 1px solid var(--line);+}+.ng-canvas {+ position: relative;+ flex: 1;+ overflow: hidden;+ background: var(--srf-1);+ background-image: radial-gradient(var(--srf-3) 1px, transparent 1px);+}+.ng-svg { position: absolute; top: 0; left: 0; width: 4000px; height: 4000px; overflow: visible; }+.ng-empty {+ position: absolute;+ inset: 0;+ display: flex;+ align-items: center;+ justify-content: center;+ color: var(--text-faint);+ font-size: var(--fs-md);+ pointer-events: none;+}++.ng-node { position: absolute; box-sizing: border-box; cursor: grab; user-select: none; }+.ng-node.droppable { outline: 2px dashed var(--star-line); outline-offset: 3px; }++/* Output handle (right): drag it to another node to connect. */+.ng-handle {+ position: absolute;+ right: -7px;+ width: 14px;+ height: 14px;+ border-radius: 50%;+ background: var(--star);+ border: 2px solid var(--srf-1);+ box-shadow: 0 0 0 1px var(--star-line);+ cursor: crosshair;+ z-index: 2;+}+.ng-handle:hover { background: var(--star-hi); }+/* Input anchor (left): a visual cue that edges land on this node. */+.ng-in-anchor {+ position: absolute;+ left: -5px;+ width: 10px;+ height: 10px;+ border-radius: 50%;+ background: var(--srf-6);+ border: 2px solid var(--srf-1);+ pointer-events: none;+}++.ng-edge-label {+ position: absolute;+ width: 80px;+ text-align: center;+ font-size: var(--fs-2xs);+ padding: 1px 3px;+ border-radius: var(--r-sm);+ background: var(--srf-1);+ border: 1px solid transparent;+ color: var(--text-dim);+ cursor: pointer;+ white-space: nowrap;+ overflow: hidden;+ text-overflow: ellipsis;+}+.ng-edge-label.sel { border-color: var(--star); color: var(--text); }++/* — node body (FSM state / BT node) — */+.ng-node-box {+ box-sizing: border-box;+ width: 100%;+ height: 100%;+ border-radius: var(--r-lg);+ border: 1.5px solid var(--line-strong);+ background: var(--srf-3);+ box-shadow: var(--shadow-1);+ padding: 6px;+ display: flex;+ flex-direction: column;+ justify-content: center;+}+.ng-node-box.sel { border-color: var(--star); }+.ng-node-head { display: flex; align-items: center; gap: 4px; font-size: var(--fs-sm); font-weight: 600; }+.ng-node-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }+.ng-node-badge { font-size: var(--fs-2xs); }+.ng-node-sub {+ margin-top: 4px;+ font-size: var(--fs-2xs);+ color: var(--text-dim);+ line-height: 1.4;+ overflow: hidden;+ text-overflow: ellipsis;+ white-space: nowrap;+}++/* — toolbar buttons + document title — */+.ng-btn {+ display: inline-flex;+ align-items: center;+ gap: 4px;+ padding: 3px 8px;+ font-size: var(--fs-sm);+ border-radius: var(--r-md);+ border: 1px solid var(--line);+ background: var(--srf-3);+ color: var(--text);+ cursor: pointer;+ transition: background var(--t-fast) var(--e-out);+}+.ng-btn:not(:disabled):hover { background: var(--srf-4); }+.ng-btn:not(:disabled):active { background: var(--srf-5); }+.ng-btn:disabled { opacity: 0.45; cursor: default; }+.ng-btn.primary { background: var(--star); border-color: transparent; color: var(--on-accent); }+.ng-btn.primary:not(:disabled):hover { background: var(--star-hi); }+.ng-btn.primary:not(:disabled):active { background: var(--star-deep); }++.ng-doc-title {+ display: inline-flex;+ align-items: center;+ gap: 4px;+ font-size: var(--fs-sm);+ color: var(--text-dim);+ margin-left: 4px;+}+/* Unsaved marker — same voice as the menubar's scene dirty dot. */+.ng-dirty { color: var(--sel); font-size: 0.7em; line-height: 1; }++/* — side inspector — */+.ng-inspector {+ width: 232px;+ flex-shrink: 0;+ border-left: 1px solid var(--line);+ padding: 10px;+ overflow: auto;+ font-size: var(--fs-sm);+}+.ng-insp-title {+ font-size: var(--fs-xs);+ text-transform: uppercase;+ letter-spacing: 0.5px;+ color: var(--text-faint);+ margin-bottom: 8px;+}+.ng-insp-sub { font-size: var(--fs-xs); color: var(--text-faint); margin: 10px 0 4px; }+.ng-field {+ display: flex;+ flex-direction: column;+ gap: 3px;+ margin-bottom: 8px;+ font-size: var(--fs-xs);+ color: var(--text-dim);+}+.ng-check-row { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; font-size: var(--fs-sm); }+.ng-row { display: flex; gap: 4px; }+.ng-input {+ font: inherit;+ font-size: var(--fs-sm);+ padding: 3px 6px;+ border-radius: var(--r-sm);+ border: 1px solid var(--line);+ background: var(--input);+ color: var(--text);+}+.ng-input:focus { outline: none; border-color: var(--star-line); }