@atlaskit/editor-plugin-collab-edit
Version:
Collab Edit plugin for @atlaskit/editor-core
29 lines (28 loc) • 1.48 kB
TypeScript
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
import type { Step } from '@atlaskit/editor-prosemirror/transform-override';
/**
* A step paired with its inverse, as stored in the collab unconfirmed queue.
*/
export type MergeableStep = {
inverted: Step;
step: Step;
};
/**
* Merge two consecutive steps into the single step they are collectively equivalent to.
*
* `second` must be expressed in the coordinate space produced by `first` — that is, the two must be
* consecutive steps of the same document. The returned step maps the document from before `first`
* to after `second`, and the returned inverse maps it back, so the result is safe to use both on
* the wire and as a rebase buffer entry.
*
* Returns `null` whenever the steps do not overlap, or when the merge cannot be proven exact. A
* `null` result always means "keep the two steps as they are", never "the steps are equivalent to
* nothing".
*
* @param first The earlier step and its inverse.
* @param second The later step and its inverse.
* @param docBefore The document `first` applies to. Optional, but without it only ProseMirror's own
* adjacent-step merges can be resolved, because the composed slice otherwise has to be cut out of a
* real document. Callers lose it when the queue has been rebased over a remote step.
*/
export declare function mergeOverlappingSteps(first: MergeableStep, second: MergeableStep, docBefore?: PMNode): MergeableStep | null;