Consolidate duplicated editor code, trim comments, refresh README
Split GraphCanvas (1076 -> 831 lines) into EdgeLayer and graphMenus; the port and marker menus were the same list and are now one function. Value specs of the inspector and the list tab share valueSpecs.ts, and the remaining copies (compound commands, type glyphs, typed asset lookup, name rule, play/editor world setup, marquee) are merged. Four copies had already drifted apart; merging them fixes: - "Disconnect N links" in the port menu is one undo step, not N - "+ Add collider" is hidden on a placed container instance, as in the hierarchy menu, instead of always failing - a bool property coerced from the text "false" becomes false - a port command on an unknown node type reports instead of crashing Comment-only edits leave the bundle byte-identical. README corrected in 35 places (step limit, jump-run clock, suite duration, 409 body, ...). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9212e61c4c
commit
8f92a06c84
96 files changed
+999
-1261
No files matched your search
@@ -0,0 +1,68 @@
|
||||
import type { Command } from '../../core/commands/Command';
|
||||
import { oneStep } from '../../core/commands/CompoundCommand';
|
||||
import { CollapseNodesCommand, DisconnectCommand, FoldEdgeCommand } from '../../core/commands/graphCommands';
|
||||
import type { GraphEdge, GraphNode } from '../../core/graph';
|
||||
import { Menu, type MenuItem } from '../../ui';
|
||||
import { removeNodes } from '../actions';
|
||||
import type { EditorState } from '../state';
|
||||
|
||||
/** For the selected nodes; a selection mixing both states offers both directions. */
|
||||
export function openNodeMenu(
|
||||
state: EditorState,
|
||||
assetId: string,
|
||||
nodes: readonly GraphNode[],
|
||||
x: number,
|
||||
y: number,
|
||||
): void {
|
||||
const ids = state.selectedNodeIds;
|
||||
const fold = (list: readonly GraphNode[], verb: string, to: boolean): MenuItem[] => {
|
||||
if (list.length === 0) return [];
|
||||
const listIds = list.map((n) => n.id);
|
||||
const label = list.length > 1 ? `${verb} ${list.length} nodes` : `${verb} node`;
|
||||
return [{ label, onSelect: () => state.execute(new CollapseNodesCommand(assetId, listIds, to)) }];
|
||||
};
|
||||
const expanded = nodes.filter((n) => !n.collapsed);
|
||||
const collapsed = nodes.filter((n) => n.collapsed);
|
||||
new Menu([
|
||||
...fold(expanded, 'Collapse', true),
|
||||
...fold(collapsed, 'Expand', false),
|
||||
{
|
||||
label: ids.length > 1 ? `Delete ${ids.length} nodes` : 'Delete node',
|
||||
danger: true,
|
||||
onSelect: () => removeNodes(state, assetId, ids),
|
||||
},
|
||||
]).open(x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* The links at one port, or behind one fold mark – the mark is the only handle a hidden link has,
|
||||
* so it carries the way back. Every entry is one undo step, however many links it covers.
|
||||
*/
|
||||
export function openLinkMenu(
|
||||
state: EditorState,
|
||||
assetId: string,
|
||||
edges: readonly GraphEdge[],
|
||||
x: number,
|
||||
y: number,
|
||||
): void {
|
||||
if (edges.length === 0) return;
|
||||
const item = (
|
||||
verb: string,
|
||||
single: string,
|
||||
list: readonly GraphEdge[],
|
||||
make: (edgeId: string) => Command,
|
||||
danger = false,
|
||||
): MenuItem[] => {
|
||||
if (list.length === 0) return [];
|
||||
const label = list.length === 1 ? single : `${verb} ${list.length} links`;
|
||||
const commands = () => list.map((e) => make(e.id));
|
||||
return [{ label, danger, onSelect: () => state.execute(oneStep(`${verb} links`, commands())) }];
|
||||
};
|
||||
const shown = edges.filter((e) => !e.folded);
|
||||
const hidden = edges.filter((e) => e.folded);
|
||||
new Menu([
|
||||
...item('Hide', 'Hide link', shown, (id) => new FoldEdgeCommand(assetId, id, true)),
|
||||
...item('Show', 'Show link', hidden, (id) => new FoldEdgeCommand(assetId, id, false)),
|
||||
...item('Disconnect', 'Disconnect', edges, (id) => new DisconnectCommand(assetId, id), true),
|
||||
]).open(x, y);
|
||||
}
|
||||
Reference in new issue
Block a user