Skip to content
GitHubDiscord

prosekit/pm/transform

Re-exports from prosemirror-transform.

Add a mark to all inline content between two positions.

new AddMarkStep(from: number, to: number, mark: Mark): AddMarkStep

Create a mark step.

Step.constructor

readonly from: number

The start of the marked range.

readonly mark: Mark

The mark to add.

readonly to: number

The end of the marked range.

apply(doc: ProseMirrorNode): StepResult

Applies this step to the given document, returning a result object that either indicates failure, if the step can not be applied to this document, or indicates success by containing a transformed document.

Step.apply

getMap(): StepMap

Get the step map that represents the changes made by this step, and which can be used to transform between positions in the old and the new document.

Step.getMap

invert(): Step

Create an inverted version of this step. Needs the document as it was before the step as argument.

Step.invert

map(mapping: Mappable): null | Step

Map this step through a mappable thing, returning either a version of that step with its positions adjusted, or null if the step was entirely deleted by the mapping.

Step.map

merge(other: Step): null | Step

Try to merge this step with another one, to be applied directly after it. Returns the merged step when possible, null if the steps can’t be merged.

Step.merge

toJSON(): any

Create a JSON-serializeable representation of this step. When defining this for a custom subclass, make sure the result object includes the step type’s JSON id under the stepType property.

Step.toJSON

static fromJSON(schema: Schema, json: any): Step

Deserialize a step from its JSON representation. Will call through to the step class’ own implementation of this method.

Step.fromJSON

static jsonID(id: string, stepClass: object): object

To be able to serialize steps to JSON, each step needs a string ID to attach to its JSON representation. Use this method to register an ID for your step classes. Try to pick something that’s unlikely to clash with steps from other modules.

Step.jsonID


Add a mark to a specific node.

new AddNodeMarkStep(pos: number, mark: Mark): AddNodeMarkStep

Create a node mark step.

Step.constructor

readonly mark: Mark

The mark to add.

readonly pos: number

The position of the target node.

apply(doc: ProseMirrorNode): StepResult

Applies this step to the given document, returning a result object that either indicates failure, if the step can not be applied to this document, or indicates success by containing a transformed document.

Step.apply

getMap(): StepMap

Get the step map that represents the changes made by this step, and which can be used to transform between positions in the old and the new document.

Step.getMap

invert(doc: ProseMirrorNode): Step

Create an inverted version of this step. Needs the document as it was before the step as argument.

Step.invert

map(mapping: Mappable): null | Step

Map this step through a mappable thing, returning either a version of that step with its positions adjusted, or null if the step was entirely deleted by the mapping.

Step.map

merge(other: Step): null | Step

Try to merge this step with another one, to be applied directly after it. Returns the merged step when possible, null if the steps can’t be merged.

Step.merge

toJSON(): any

Create a JSON-serializeable representation of this step. When defining this for a custom subclass, make sure the result object includes the step type’s JSON id under the stepType property.

Step.toJSON

static fromJSON(schema: Schema, json: any): Step

Deserialize a step from its JSON representation. Will call through to the step class’ own implementation of this method.

Step.fromJSON

static jsonID(id: string, stepClass: object): object

To be able to serialize steps to JSON, each step needs a string ID to attach to its JSON representation. Use this method to register an ID for your step classes. Try to pick something that’s unlikely to clash with steps from other modules.

Step.jsonID


Update an attribute in a specific node.

new AttrStep(pos: number, attr: string, value: any): AttrStep

Construct an attribute step.

Step.constructor

readonly attr: string

The attribute to set.

readonly pos: number

The position of the target node.

readonly value: any

apply(doc: ProseMirrorNode): StepResult

Applies this step to the given document, returning a result object that either indicates failure, if the step can not be applied to this document, or indicates success by containing a transformed document.

Step.apply

getMap(): StepMap

Get the step map that represents the changes made by this step, and which can be used to transform between positions in the old and the new document.

Step.getMap

invert(doc: ProseMirrorNode): AttrStep

Create an inverted version of this step. Needs the document as it was before the step as argument.

Step.invert

map(mapping: Mappable): null | AttrStep

Map this step through a mappable thing, returning either a version of that step with its positions adjusted, or null if the step was entirely deleted by the mapping.

Step.map

merge(other: Step): null | Step

Try to merge this step with another one, to be applied directly after it. Returns the merged step when possible, null if the steps can’t be merged.

Step.merge

toJSON(): any

Create a JSON-serializeable representation of this step. When defining this for a custom subclass, make sure the result object includes the step type’s JSON id under the stepType property.

Step.toJSON

static fromJSON(schema: Schema, json: any): AttrStep

Deserialize a step from its JSON representation. Will call through to the step class’ own implementation of this method.

Step.fromJSON

static jsonID(id: string, stepClass: object): object

To be able to serialize steps to JSON, each step needs a string ID to attach to its JSON representation. Use this method to register an ID for your step classes. Try to pick something that’s unlikely to clash with steps from other modules.

Step.jsonID


Update an attribute in the doc node.

new DocAttrStep(attr: string, value: any): DocAttrStep

Construct an attribute step.

Step.constructor

readonly attr: string

The attribute to set.

readonly value: any

apply(doc: ProseMirrorNode): StepResult

Applies this step to the given document, returning a result object that either indicates failure, if the step can not be applied to this document, or indicates success by containing a transformed document.

Step.apply

getMap(): StepMap

Get the step map that represents the changes made by this step, and which can be used to transform between positions in the old and the new document.

Step.getMap

invert(doc: ProseMirrorNode): DocAttrStep

Create an inverted version of this step. Needs the document as it was before the step as argument.

Step.invert

map(mapping: Mappable): this

Map this step through a mappable thing, returning either a version of that step with its positions adjusted, or null if the step was entirely deleted by the mapping.

Step.map

merge(other: Step): null | Step

Try to merge this step with another one, to be applied directly after it. Returns the merged step when possible, null if the steps can’t be merged.

Step.merge

toJSON(): any

Create a JSON-serializeable representation of this step. When defining this for a custom subclass, make sure the result object includes the step type’s JSON id under the stepType property.

Step.toJSON

static fromJSON(schema: Schema, json: any): DocAttrStep

Deserialize a step from its JSON representation. Will call through to the step class’ own implementation of this method.

Step.fromJSON

static jsonID(id: string, stepClass: object): object

To be able to serialize steps to JSON, each step needs a string ID to attach to its JSON representation. Use this method to register an ID for your step classes. Try to pick something that’s unlikely to clash with steps from other modules.

Step.jsonID


A mapping represents a pipeline of zero or more step maps. It has special provisions for losslessly handling mapping positions through a series of steps in which some steps are inverted versions of earlier steps. (This comes up when ‘rebasing’ steps for collaboration or history management.)

new Mapping(maps?: readonly StepMap[], from?: number, to?: number): Mapping

Create a new mapping with the given position maps.

from: number

The starting position in the maps array, used when map or mapResult is called.

to: number

The end position in the maps array.

get maps(): readonly StepMap[]

The step maps in this mapping.

readonly StepMap[]

appendMap(map: StepMap, mirrors?: number): void

Add a step map to the end of this mapping. If mirrors is given, it should be the index of the step map that is the mirror image of this one.

appendMapping(mapping: Mapping): void

Add all the step maps in a given mapping to this one (preserving mirroring information).

appendMappingInverted(mapping: Mapping): void

Append the inverse of the given mapping to this one.

getMirror(n: number): undefined | number

Finds the offset of the step map that mirrors the map at the given offset, in this mapping (as per the second argument to appendMap).

invert(): Mapping

Create an inverted version of this mapping.

map(pos: number, assoc?: number): number

Map a position through this mapping.

Mappable.map

mapResult(pos: number, assoc?: number): MapResult

Map a position through this mapping, returning a mapping result.

Mappable.mapResult

slice(from?: number, to?: number): Mapping

Create a mapping that maps only through a part of this one.


An object representing a mapped position with extra information.

new MapResult(): MapResult

readonly pos: number

The mapped version of the position.

get deleted(): boolean

Tells you whether the position was deleted, that is, whether the step removed the token on the side queried (via the assoc) argument from the document.

boolean

get deletedAcross(): boolean

Tells whether any of the steps mapped through deletes across the position (including both the token before and after the position).

boolean

get deletedAfter(): boolean

True when the token after the mapped position was deleted.

boolean

get deletedBefore(): boolean

Tells you whether the token before the mapped position was deleted.

boolean


Remove a mark from all inline content between two positions.

new RemoveMarkStep(from: number, to: number, mark: Mark): RemoveMarkStep

Create a mark-removing step.

Step.constructor

readonly from: number

The start of the unmarked range.

readonly mark: Mark

The mark to remove.

readonly to: number

The end of the unmarked range.

apply(doc: ProseMirrorNode): StepResult

Applies this step to the given document, returning a result object that either indicates failure, if the step can not be applied to this document, or indicates success by containing a transformed document.

Step.apply

getMap(): StepMap

Get the step map that represents the changes made by this step, and which can be used to transform between positions in the old and the new document.

Step.getMap

invert(): Step

Create an inverted version of this step. Needs the document as it was before the step as argument.

Step.invert

map(mapping: Mappable): null | Step

Map this step through a mappable thing, returning either a version of that step with its positions adjusted, or null if the step was entirely deleted by the mapping.

Step.map

merge(other: Step): null | Step

Try to merge this step with another one, to be applied directly after it. Returns the merged step when possible, null if the steps can’t be merged.

Step.merge

toJSON(): any

Create a JSON-serializeable representation of this step. When defining this for a custom subclass, make sure the result object includes the step type’s JSON id under the stepType property.

Step.toJSON

static fromJSON(schema: Schema, json: any): Step

Deserialize a step from its JSON representation. Will call through to the step class’ own implementation of this method.

Step.fromJSON

static jsonID(id: string, stepClass: object): object

To be able to serialize steps to JSON, each step needs a string ID to attach to its JSON representation. Use this method to register an ID for your step classes. Try to pick something that’s unlikely to clash with steps from other modules.

Step.jsonID


Remove a mark from a specific node.

new RemoveNodeMarkStep(pos: number, mark: Mark): RemoveNodeMarkStep

Create a mark-removing step.

Step.constructor

readonly mark: Mark

The mark to remove.

readonly pos: number

The position of the target node.

apply(doc: ProseMirrorNode): StepResult

Applies this step to the given document, returning a result object that either indicates failure, if the step can not be applied to this document, or indicates success by containing a transformed document.

Step.apply

getMap(): StepMap

Get the step map that represents the changes made by this step, and which can be used to transform between positions in the old and the new document.

Step.getMap

invert(doc: ProseMirrorNode): Step

Create an inverted version of this step. Needs the document as it was before the step as argument.

Step.invert

map(mapping: Mappable): null | Step

Map this step through a mappable thing, returning either a version of that step with its positions adjusted, or null if the step was entirely deleted by the mapping.

Step.map

merge(other: Step): null | Step

Try to merge this step with another one, to be applied directly after it. Returns the merged step when possible, null if the steps can’t be merged.

Step.merge

toJSON(): any

Create a JSON-serializeable representation of this step. When defining this for a custom subclass, make sure the result object includes the step type’s JSON id under the stepType property.

Step.toJSON

static fromJSON(schema: Schema, json: any): Step

Deserialize a step from its JSON representation. Will call through to the step class’ own implementation of this method.

Step.fromJSON

static jsonID(id: string, stepClass: object): object

To be able to serialize steps to JSON, each step needs a string ID to attach to its JSON representation. Use this method to register an ID for your step classes. Try to pick something that’s unlikely to clash with steps from other modules.

Step.jsonID


Replace a part of the document with a slice of content, but preserve a range of the replaced content by moving it into the slice.

new ReplaceAroundStep(from: number, to: number, gapFrom: number, gapTo: number, slice: Slice, insert: number): ReplaceAroundStep

Create a replace-around step with the given range and gap. insert should be the point in the slice into which the content of the gap should be moved. structure has the same meaning as it has in the ReplaceStep class.

Step.constructor

readonly from: number

The start position of the replaced range.

readonly gapFrom: number

The start of preserved range.

readonly gapTo: number

The end of preserved range.

readonly insert: number

The position in the slice where the preserved range should be inserted.

readonly slice: Slice

The slice to insert.

readonly to: number

The end position of the replaced range.

apply(doc: ProseMirrorNode): StepResult

Applies this step to the given document, returning a result object that either indicates failure, if the step can not be applied to this document, or indicates success by containing a transformed document.

Step.apply

getMap(): StepMap

Get the step map that represents the changes made by this step, and which can be used to transform between positions in the old and the new document.

Step.getMap

invert(doc: ProseMirrorNode): ReplaceAroundStep

Create an inverted version of this step. Needs the document as it was before the step as argument.

Step.invert

map(mapping: Mappable): null | ReplaceAroundStep

Map this step through a mappable thing, returning either a version of that step with its positions adjusted, or null if the step was entirely deleted by the mapping.

Step.map

merge(other: Step): null | Step

Try to merge this step with another one, to be applied directly after it. Returns the merged step when possible, null if the steps can’t be merged.

Step.merge

toJSON(): any

Create a JSON-serializeable representation of this step. When defining this for a custom subclass, make sure the result object includes the step type’s JSON id under the stepType property.

Step.toJSON

static fromJSON(schema: Schema, json: any): Step

Deserialize a step from its JSON representation. Will call through to the step class’ own implementation of this method.

Step.fromJSON

static jsonID(id: string, stepClass: object): object

To be able to serialize steps to JSON, each step needs a string ID to attach to its JSON representation. Use this method to register an ID for your step classes. Try to pick something that’s unlikely to clash with steps from other modules.

Step.jsonID


Replace a part of the document with a slice of new content.

new ReplaceStep(from: number, to: number, slice: Slice): ReplaceStep

The given slice should fit the ‘gap’ between from and to—the depths must line up, and the surrounding nodes must be able to be joined with the open sides of the slice. When structure is true, the step will fail if the content between from and to is not just a sequence of closing and then opening tokens (this is to guard against rebased replace steps overwriting something they weren’t supposed to).

Step.constructor

readonly from: number

The start position of the replaced range.

readonly slice: Slice

The slice to insert.

readonly to: number

The end position of the replaced range.

apply(doc: ProseMirrorNode): StepResult

Applies this step to the given document, returning a result object that either indicates failure, if the step can not be applied to this document, or indicates success by containing a transformed document.

Step.apply

getMap(): StepMap

Get the step map that represents the changes made by this step, and which can be used to transform between positions in the old and the new document.

Step.getMap

invert(doc: ProseMirrorNode): ReplaceStep

Create an inverted version of this step. Needs the document as it was before the step as argument.

Step.invert

map(mapping: Mappable): null | ReplaceStep

Map this step through a mappable thing, returning either a version of that step with its positions adjusted, or null if the step was entirely deleted by the mapping.

Step.map

merge(other: Step): null | ReplaceStep

Try to merge this step with another one, to be applied directly after it. Returns the merged step when possible, null if the steps can’t be merged.

Step.merge

toJSON(): any

Create a JSON-serializeable representation of this step. When defining this for a custom subclass, make sure the result object includes the step type’s JSON id under the stepType property.

Step.toJSON

static fromJSON(schema: Schema, json: any): Step

Deserialize a step from its JSON representation. Will call through to the step class’ own implementation of this method.

Step.fromJSON

static jsonID(id: string, stepClass: object): object

To be able to serialize steps to JSON, each step needs a string ID to attach to its JSON representation. Use this method to register an ID for your step classes. Try to pick something that’s unlikely to clash with steps from other modules.

Step.jsonID


A step object represents an atomic change. It generally applies only to the document it was created for, since the positions stored in it will only make sense for that document.

New steps are defined by creating classes that extend Step, overriding the apply, invert, map, getMap and fromJSON methods, and registering your class with a unique JSON-serialization identifier using Step.jsonID.

new Step(): Step

abstract apply(doc: ProseMirrorNode): StepResult

Applies this step to the given document, returning a result object that either indicates failure, if the step can not be applied to this document, or indicates success by containing a transformed document.

getMap(): StepMap

Get the step map that represents the changes made by this step, and which can be used to transform between positions in the old and the new document.

abstract invert(doc: ProseMirrorNode): Step

Create an inverted version of this step. Needs the document as it was before the step as argument.

abstract map(mapping: Mappable): null | Step

Map this step through a mappable thing, returning either a version of that step with its positions adjusted, or null if the step was entirely deleted by the mapping.

merge(other: Step): null | Step

Try to merge this step with another one, to be applied directly after it. Returns the merged step when possible, null if the steps can’t be merged.

abstract toJSON(): any

Create a JSON-serializeable representation of this step. When defining this for a custom subclass, make sure the result object includes the step type’s JSON id under the stepType property.

static fromJSON(schema: Schema, json: any): Step

Deserialize a step from its JSON representation. Will call through to the step class’ own implementation of this method.

static jsonID(id: string, stepClass: object): object

To be able to serialize steps to JSON, each step needs a string ID to attach to its JSON representation. Use this method to register an ID for your step classes. Try to pick something that’s unlikely to clash with steps from other modules.


A map describing the deletions and insertions made by a step, which can be used to find the correspondence between positions in the pre-step version of a document and the same position in the post-step version.

new StepMap(): StepMap

Create a position map. The modifications to the document are represented as an array of numbers, in which each group of three represents a modified chunk as [start, oldSize, newSize].

static empty: StepMap

A StepMap that contains no changed ranges.

forEach(f: (oldStart: number, oldEnd: number, newStart: number, newEnd: number) => void): void

Calls the given function on each of the changed ranges included in this map.

invert(): StepMap

Create an inverted version of this map. The result can be used to map positions in the post-step document to the pre-step document.

map(pos: number, assoc?: number): number

Map a position through this object. When given, assoc (should be -1 or 1, defaults to 1) determines with which side the position is associated, which determines in which direction to move when a chunk of content is inserted at the mapped position.

Mappable.map

mapResult(pos: number, assoc?: number): MapResult

Map a position, and return an object containing additional information about the mapping. The result’s deleted field tells you whether the position was deleted (completely enclosed in a replaced range) during the mapping. When content on only one side is deleted, the position itself is only considered deleted when assoc points in the direction of the deleted content.

Mappable.mapResult

static offset(n: number): StepMap

Create a map that moves all positions by offset n (which may be negative). This can be useful when applying steps meant for a sub-document to a larger document, or vice-versa.


The result of applying a step. Contains either a new document or a failure value.

new StepResult(): StepResult

readonly doc: null | ProseMirrorNode

The transformed document, if successful.

readonly failed: null | string

The failure message, if unsuccessful.

static fail(message: string): StepResult

Create a failed step result.

static fromReplace(doc: ProseMirrorNode, from: number, to: number, slice: Slice): StepResult

Call Node.replace with the given arguments. Create a successful result if it succeeds, and a failed one if it throws a ReplaceError.

static ok(doc: ProseMirrorNode): StepResult

Create a successful step result.


Abstraction to build up and track an array of steps representing a document transformation.

Most transforming methods return the Transform object itself, so that they can be chained.

new Transform(doc: ProseMirrorNode): Transform

Create a transform that starts with the given document.

doc: ProseMirrorNode

The current document (the result of applying the steps in the transform).

readonly docs: ProseMirrorNode[]

The documents before each of the steps.

readonly mapping: Mapping

A mapping with the maps for each of the steps in this transform.

readonly steps: Step[]

The steps in this transform.

get before(): ProseMirrorNode

The starting document.

ProseMirrorNode

get docChanged(): boolean

True when the document has been changed (when there are any steps).

boolean

addMark(from: number, to: number, mark: Mark): this

Add the given mark to the inline content between from and to.

addNodeMark(pos: number, mark: Mark): this

Add a mark to the node at position pos.

clearIncompatible(pos: number, parentType: NodeType, match?: ContentMatch): this

Removes all marks and nodes from the content of the node at pos that don’t match the given new parent node type. Accepts an optional starting content match as third argument.

delete(from: number, to: number): this

Delete the content between the given positions.

deleteRange(from: number, to: number): this

Delete the given range, expanding it to cover fully covered parent nodes until a valid replace is found.

insert(pos: number, content: ProseMirrorNode | ProseMirrorFragment | readonly ProseMirrorNode[]): this

Insert the given content at the given position.

join(pos: number, depth?: number): this

Join the blocks around the given position. If depth is 2, their last and first siblings are also joined, and so on.

lift(range: NodeRange, target: number): this

Split the content in the given range off from its parent, if there is sibling content before or after it, and move it up the tree to the depth specified by target. You’ll probably want to use liftTarget to compute target, to make sure the lift is valid.

maybeStep(step: Step): StepResult

Try to apply a step in this transformation, ignoring it if it fails. Returns the step result.

removeMark(from: number, to: number, mark?: null | MarkType | Mark): this

Remove marks from inline nodes between from and to. When mark is a single mark, remove precisely that mark. When it is a mark type, remove all marks of that type. When it is null, remove all marks of any type.

removeNodeMark(pos: number, mark: MarkType | Mark): this

Remove a mark (or all marks of the given type) from the node at position pos.

replace(from: number, to?: number, slice?: Slice): this

Replace the part of the document between from and to with the given slice.

replaceRange(from: number, to: number, slice: Slice): this

Replace a range of the document with a given slice, using from, to, and the slice’s openStart property as hints, rather than fixed start and end points. This method may grow the replaced area or close open nodes in the slice in order to get a fit that is more in line with WYSIWYG expectations, by dropping fully covered parent nodes of the replaced region when they are marked non-defining as context, or including an open parent node from the slice that is marked as defining its content.

This is the method, for example, to handle paste. The similar replace method is a more primitive tool which will not move the start and end of its given range, and is useful in situations where you need more precise control over what happens.

replaceRangeWith(from: number, to: number, node: ProseMirrorNode): this

Replace the given range with a node, but use from and to as hints, rather than precise positions. When from and to are the same and are at the start or end of a parent node in which the given node doesn’t fit, this method may move them out towards a parent that does allow the given node to be placed. When the given range completely covers a parent node, this method may completely replace that parent node.

replaceWith(from: number, to: number, content: ProseMirrorNode | ProseMirrorFragment | readonly ProseMirrorNode[]): this

Replace the given range with the given content, which may be a fragment, node, or array of nodes.

setBlockType(from: number, to: undefined | number, type: NodeType, attrs?: null | Attrs | (oldNode: ProseMirrorNode) => Attrs): this

Set the type of all textblocks (partly) between from and to to the given node type with the given attributes.

setDocAttribute(attr: string, value: any): this

Set a single attribute on the document to a new value.

setNodeAttribute(pos: number, attr: string, value: any): this

Set a single attribute on a given node to a new value. The pos addresses the document content. Use setDocAttribute to set attributes on the document itself.

setNodeMarkup(pos: number, type?: null | NodeType, attrs?: null | Attrs, marks?: readonly Mark[]): this

Change the type, attributes, and/or marks of the node at pos. When type isn’t given, the existing node type is preserved,

split(pos: number, depth?: number, typesAfter?: (null | { attrs?: null | Attrs; type: NodeType; })[]): this

Split the node at the given position, and optionally, if depth is greater than one, any number of nodes above that. By default, the parts split off will inherit the node type of the original node. This can be changed by passing an array of types and attributes to use after the split (with the outermost nodes coming first).

step(step: Step): this

Apply a new step in this transform, saving the result. Throws an error when the step fails.

wrap(range: NodeRange, wrappers: readonly object[]): this

Wrap the given range in the given set of wrappers. The wrappers are assumed to be valid in this position, and should probably be computed with findWrapping.

There are several things that positions can be mapped through. Such objects conform to this interface.

map: (pos: number, assoc?: number) => number

Map a position through this object. When given, assoc (should be -1 or 1, defaults to 1) determines with which side the position is associated, which determines in which direction to move when a chunk of content is inserted at the mapped position.

mapResult: (pos: number, assoc?: number) => MapResult

Map a position, and return an object containing additional information about the mapping. The result’s deleted field tells you whether the position was deleted (completely enclosed in a replaced range) during the mapping. When content on only one side is deleted, the position itself is only considered deleted when assoc points in the direction of the deleted content.

function canJoin(doc: ProseMirrorNode, pos: number): boolean

Test whether the blocks before and after a given position can be joined.


function canSplit(doc: ProseMirrorNode, pos: number, depth?: number, typesAfter?: (null | { attrs?: null | Attrs; type: NodeType; })[]): boolean

Check whether splitting at the given position is allowed.


function dropPoint(doc: ProseMirrorNode, pos: number, slice: Slice): null | number

Finds a position at or around the given position where the given slice can be inserted. Will look at parent nodes’ nearest boundary and try there, even if the original position wasn’t directly at the start or end of that node. Returns null when no position was found.


function findWrapping(range: NodeRange, nodeType: NodeType, attrs?: null | Attrs, innerRange?: NodeRange): null | object[]

Try to find a valid way to wrap the content in the given range in a node of the given type. May introduce extra nodes around and inside the wrapper node, if necessary. Returns null if no valid wrapping could be found. When innerRange is given, that range’s content is used as the content to fit into the wrapping, instead of the content of range.


function insertPoint(doc: ProseMirrorNode, pos: number, nodeType: NodeType): null | number

Try to find a point where a node of the given type can be inserted near pos, by searching up the node hierarchy when pos itself isn’t a valid place but is at the start or end of a node. Return null if no position was found.


function joinPoint(doc: ProseMirrorNode, pos: number, dir?: number): undefined | number

Find an ancestor of the given position that can be joined to the block before (or after if dir is positive). Returns the joinable point, if any.


function liftTarget(range: NodeRange): null | number

Try to find a target depth to which the content in the given range can be lifted. Will not go across isolating parent nodes.


function replaceStep(doc: ProseMirrorNode, from: number, to?: number, slice?: Slice): null | Step

‘Fit’ a slice into a given position in the document, producing a step that inserts it. Will return null if there’s no meaningful way to insert the slice here, or inserting it would be a no-op (an empty slice over an empty range).