Several transitions between the same pair of states: make transition onto a state that is already connected in that direction adds another transition, which gets its own name right away (Transition 2, Transition 3, skipping names that already leave the state), so two unnamed transitions between one pair never exist; renaming is refused when another transition between the same pair in the same direction already carries the name, the empty name included, while equal names to other targets are only warned about as before; the behavior graph keeps Already connected; self transitions may repeat too, each further loop drawn as a ring around the previous one with the preview showing the next ring, and transition labels that would cover another one slide along their own edge until they are free (pure function freeLabelSpot); test hook transitionLabelAt also returns width and height, e2e 26e6 (#162)
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
010b6a7f6c
commit
25ec7879a0
9 files changed
+402
-34
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { textOf } from '../model/Properties';
|
||||
import { flatDef } from '../properties/PropertySchema';
|
||||
import { edgesInto, type Graph, type GraphNode, type PortType } from './Graph';
|
||||
import { edgesInto, type Graph, type GraphEdge, type GraphNode, type PortType } from './Graph';
|
||||
import type { MachineState, MachineTransition, StateMachine } from './lookup';
|
||||
import type { NodeDef, PortDef, PortSource } from './NodeRegistry';
|
||||
|
||||
@@ -99,6 +99,25 @@ export function nextStateName(graph: Graph): string {
|
||||
return `${State.label} ${statesOf(graph).length + 1}`;
|
||||
}
|
||||
|
||||
/** Transition edges joining the same two states in the same direction as `edge`, itself left out. */
|
||||
export function parallelTransitions(graph: Graph, edge: GraphEdge): GraphEdge[] {
|
||||
return graph.edges.filter(
|
||||
(e) => e.id !== edge.id && e.from.node === edge.from.node && e.to.node === edge.to.node,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* What a further transition between the same two states is called: "Transition 3" for the third,
|
||||
* counting up past any name already leaving that state – two of one name out of a state would
|
||||
* both be dead, and two unnamed ones between the same pair could not be told apart.
|
||||
*/
|
||||
export function nextTransitionName(graph: Graph, edge: GraphEdge): string {
|
||||
const taken = new Set(graph.edges.filter((e) => e.from.node === edge.from.node).map((e) => e.label));
|
||||
let n = parallelTransitions(graph, edge).length + 1;
|
||||
while (taken.has(`Transition ${n}`)) n++;
|
||||
return `Transition ${n}`;
|
||||
}
|
||||
|
||||
/** The `machine` input; unconnected, it shows the machine picker. */
|
||||
export const machinePort = (): PortDef => ({
|
||||
key: MACHINE_PORT,
|
||||
|
||||
Reference in new issue
Block a user