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:
rootandClaude Opus 5 committed 2026-09-11 11:00:30 +02:00
1 parent 9212e61c4c
commit 8f92a06c84
96 files changed
+999 -1261

No files matched your search

+10 -10
View File
@@ -6,7 +6,14 @@
import { Button, HStack, Label, ScrollContainer, Spacer, Theme, VStack, type Widget } from '../../ui';
import { textOf, type ListValue, type PropertyValue } from '../../core/model/Properties';
import { type StructDef, structOf } from '../../core/properties/PropertySchema';
import { createField, type FieldContext, primitiveDef, type PrimitiveDef } from '../inspector/fieldFactory';
import {
addValue,
createField,
type FieldContext,
primitiveDef,
type PrimitiveDef,
removeButton,
} from '../inspector/fieldFactory';
import type { EditorState } from '../state';
import { type ListAccess, type ListDef, resolveList } from './slot';
@@ -124,15 +131,8 @@ export class ListEditor extends VStack {
if (tall) label.minHeight = Theme.rowHeight;
row.add(label);
const field = createField(this.ctx, itemDef(access.def, index), item, access.itemHandlers(index));
row.add(field.widget, field.grow ? 1 : 0);
if (!field.grow) row.add(new Spacer(), 1);
row.add(
new Button('×', {
variant: 'ghost',
width: Theme.controlHeight,
onClick: () => access.replace(access.value.filter((_, i) => i !== index)),
}),
);
addValue(row, field);
row.add(removeButton(() => access.replace(access.value.filter((_, i) => i !== index))));
this.setters.push(field.setValue);
this.fields.push({ widget: field.widget, parts: field.parts });
return row;
+12 -42
View File
@@ -1,14 +1,8 @@
/**
* Resolves a `ListSlot` to the list in it and to the two ways of writing it back. Each of the
* three cases is the spec the matching inspector section already uses, so an item edited in the
* List tab goes through the same command, the same coercion and the same undo step as the row
* it replaces. A slot with a `field` names a list *inside* a struct: the same three owners, one
* level deeper, and the writes still go through the owner's command as a whole bundle.
* Resolves a `ListSlot` to its list and write-back, reusing each inspector section's spec so a List tab
* edit gets the same command, coercion and undo step. A `field` slot still writes the whole struct.
*/
import { SetAssetPropertyCommand } from '../../core/commands/assetCommands';
import { SetNodeParamCommand } from '../../core/commands/graphCommands';
import { SetOverrideCommand } from '../../core/commands/sceneObjectCommands';
import { edgesInto, findNode, type Graph, type GraphNode } from '../../core/graph/Graph';
import { edgesInto, type Graph, type GraphNode } from '../../core/graph/Graph';
import { resolveDef } from '../../core/graph/nested';
import { inlineInputDef, inlineInputs, type NodeDef } from '../../core/graph/NodeRegistry';
import type { Asset } from '../../core/model/Asset';
@@ -28,6 +22,7 @@ import { resolveAssetProps } from '../../core/properties/resolve';
import type { FieldHandlers } from '../inspector/fieldFactory';
import { currentProps, currentRef } from '../inspector/objectQueries';
import { previewingHandlers, type PreviewedValue } from '../inspector/previewHandlers';
import { assetValue, currentNode, nodeParamValue, overrideValue } from '../inspector/valueSpecs';
import type { EditorState, ListSlot } from '../state';
export type ListDef = Extract<PropertyDef, { kind: 'list' }>;
@@ -157,20 +152,14 @@ function assetOwner(state: EditorState, slot: Extract<ListSlot, { kind: 'asset'
const asset = findAsset(state.project, slot.assetId);
const def = asset && schemaForAsset(asset).find((d) => d.key === slot.key);
if (!asset || !def) return null;
const at = () => findAsset(state.project, slot.assetId);
return {
def,
title: `${asset.name} · ${def.label}`,
current: () => {
const now = at();
return now ? resolveAssetProps(now)[slot.key] : undefined;
},
spec: {
target: at,
read: (found) => found.props[slot.key],
write: (found, value) => (found.props[slot.key] = value),
commit: (value) => new SetAssetPropertyCommand(slot.assetId, slot.key, value),
const now = findAsset(state.project, slot.assetId);
return now && resolveAssetProps(now)[slot.key];
},
spec: assetValue(state, slot.assetId, slot.key),
};
}
@@ -186,18 +175,12 @@ function objectOwner(
def,
title: `${ref.object.name} · ${def.label}`,
current: () => currentProps(state, slot.holderId, slot.objectId)?.[slot.key],
spec: {
target: () => currentRef(state, slot.holderId, slot.objectId),
read: (found) => found.object.overrides[slot.key],
write: (found, value) => found.setOverride(slot.key, value),
remove: (found) => found.setOverride(slot.key, undefined),
commit: (value) => new SetOverrideCommand(slot.holderId, slot.objectId, slot.key, value),
},
spec: overrideValue(state, slot.holderId, slot.objectId, slot.key),
};
}
function nodeOwner(state: EditorState, slot: Extract<ListSlot, { kind: 'node' }>): Owner<GraphNode> | null {
const found = nodeIn(state, slot);
const found = currentNode(state.project, slot.assetId, slot.nodeId);
if (!found) return null;
const nodeDef = resolveDef(found.node, found.graph, behaviorLookup(state.project));
const def =
@@ -206,14 +189,9 @@ function nodeOwner(state: EditorState, slot: Extract<ListSlot, { kind: 'node' }>
return {
def,
title: `${nodeDef.label} · ${def.label}`,
current: () => nodeIn(state, slot)?.node.params[slot.key] ?? def.default,
spec: {
target: () => nodeIn(state, slot)?.node,
read: (node) => node.params[slot.key],
write: (node, value) => (node.params[slot.key] = value),
remove: (node) => delete node.params[slot.key],
commit: (value) => new SetNodeParamCommand(slot.assetId, slot.nodeId, slot.key, value),
},
current: () =>
currentNode(state.project, slot.assetId, slot.nodeId)?.node.params[slot.key] ?? def.default,
spec: nodeParamValue(state, slot.assetId, slot.nodeId, slot.key),
};
}
@@ -228,11 +206,3 @@ function inlineListDef(def: NodeDef, found: { node: GraphNode; graph: Graph }, k
const inline = inlineInputDef(port);
return inline.kind === 'list' ? inline : null;
}
/** The node together with its graph, because `resolveDef` needs both. */
function nodeIn(state: EditorState, slot: Extract<ListSlot, { kind: 'node' }>) {
const asset = findAsset(state.project, slot.assetId);
if (asset?.type !== 'behavior') return null;
const node = findNode(asset.graph, slot.nodeId);
return node ? { node, graph: asset.graph } : null;
}