Files
outline/shared/editor/lib/chainTransactions.ts
T
Tom Moor bf45e97641 chore: Enforce type import consistency (#10968)
* Update types

* fix circular dep

* type imports

* lint type imports and --fix
2025-12-19 23:07:02 -05:00

22 lines
625 B
TypeScript

import type { Command, Transaction } from "prosemirror-state";
/**
* Chain multiple commands into a single command and collects state as it goes.
*
* @param commands The commands to chain
* @returns The chained command
*/
export function chainTransactions(
...commands: (Command | undefined)[]
): Command {
return (state, dispatch): boolean => {
const dispatcher = (tr: Transaction): void => {
state = state.apply(tr);
dispatch?.(tr);
};
const last = commands.pop();
commands.map((command) => command?.(state, dispatcher));
return last !== undefined && last(state, dispatch);
};
}