mirror of
https://github.com/outline/outline.git
synced 2026-12-06 11:12:32 +03:00
* fix: Correct logic errors in shared utilities * fix: Restore per-column cells in getCellsInRow and convert every attachment url The g flag made the attachment regex skip every second match, and removing duplicate cells broke callers that index getCellsInRow by column. * test: Cover uppercase attachment URLs * revert: Remove uncertain fixes
28 lines
984 B
TypeScript
28 lines
984 B
TypeScript
import type { Command, Transaction } from "prosemirror-state";
|
|
|
|
/**
|
|
* Chain multiple commands into a single command and collects state as it goes.
|
|
*
|
|
* When a view is available the state for the next command is read from the
|
|
* view after each dispatch, as the view may have applied further transactions
|
|
* (e.g. from plugin views) that a locally derived state would not include.
|
|
*
|
|
* @param commands The commands to chain
|
|
* @returns The chained command
|
|
*/
|
|
export function chainTransactions(
|
|
...commands: (Command | undefined)[]
|
|
): Command {
|
|
return (state, dispatch, view): boolean => {
|
|
const dispatcher = (tr: Transaction): void => {
|
|
const before = view?.state;
|
|
dispatch?.(tr);
|
|
state = view && view.state !== before ? view.state : state.apply(tr);
|
|
};
|
|
const list = [...commands];
|
|
const last = list.pop();
|
|
list.forEach((command) => command?.(state, dispatcher, view));
|
|
return last !== undefined && last(state, dispatch, view);
|
|
};
|
|
}
|