history

history.beginTransaction

beginTransaction(label?: string): void

Begin an explicit transaction.

All commands issued until endTransaction is called are grouped as a single undo step, regardless of timing or async gaps. Transactions nest — only the outermost endTransaction() commits. Prefer the wrapper transaction to avoid mismatched calls.

labelstringOptional human-readable label used when the transaction is committed.

Returns: void

Example

api.history.beginTransaction("Import data");
await api.nodes.add([...]);
await api.edges.add([...]);
await api.layout.circle();
api.history.endTransaction(); // all above → one undo step