Skip to content
GitHubDiscord

prosekit/pm/state

Re-exports from prosemirror-state.

A selection type that represents selecting the whole document (which can not necessarily be expressed with a text selection, when there are for example leaf block nodes at the start or end of the document).

new AllSelection(doc: ProseMirrorNode): AllSelection

Create an all-selection over the given document.

Selection.constructor

readonly $anchor: ResolvedPos

The resolved anchor of the selection (the side that stays in place when the selection is modified).

readonly $head: ResolvedPos

The resolved head of the selection (the side that moves when the selection is modified).

ranges: readonly SelectionRange[]

The ranges covered by the selection.

visible: boolean

Controls whether, when a selection of this type is active in the browser, the selected range should be visible to the user. Defaults to true.

get $from(): ResolvedPos

The resolved lower bound of the selection’s main range.

ResolvedPos

Selection.$from

get $to(): ResolvedPos

The resolved upper bound of the selection’s main range.

ResolvedPos

Selection.$to

get anchor(): number

The selection’s anchor, as an unresolved position.

number

Selection.anchor

get empty(): boolean

Indicates whether the selection contains any content.

boolean

Selection.empty

get from(): number

The lower bound of the selection’s main range.

number

Selection.from

get head(): number

The selection’s head.

number

Selection.head

get to(): number

The upper bound of the selection’s main range.

number

Selection.to

content(): Slice

Get the content of this selection as a slice.

Selection.content

eq(other: Selection): boolean

Test whether the selection is the same as another selection.

Selection.eq

getBookmark(): object

Get a bookmark for this selection, which is a value that can be mapped without having access to a current document, and later resolved to a real selection for a given document again. (This is used mostly by the history to track and restore old selections.) The default implementation of this method just converts the selection to a text selection and returns the bookmark for that.

Selection.getBookmark

map(doc: ProseMirrorNode): AllSelection

Map this selection through a mappable thing. doc should be the new document to which we are mapping.

Selection.map

replace(tr: Transaction, content?: Slice): void

Replace the selection with a slice or, if no slice is given, delete the selection. Will append to the given transaction.

Selection.replace

replaceWith(tr: Transaction, node: ProseMirrorNode): void

Replace the selection with the given node, appending the changes to the given transaction.

Selection.replaceWith

toJSON(): any

Convert the selection to a JSON representation. When implementing this for a custom selection class, make sure to give the object a type property whose value matches the ID under which you registered your class.

Selection.toJSON

static atEnd(doc: ProseMirrorNode): Selection

Find the cursor or leaf node selection closest to the end of the given document.

Selection.atEnd

static atStart(doc: ProseMirrorNode): Selection

Find the cursor or leaf node selection closest to the start of the given document. Will return an AllSelection if no valid position exists.

Selection.atStart

static findFrom($pos: ResolvedPos, dir: number, textOnly?: boolean): null | Selection

Find a valid cursor or leaf node selection starting at the given position and searching back if dir is negative, and forward if positive. When textOnly is true, only consider cursor selections. Will return null when no valid selection position is found.

Selection.findFrom

static fromJSON(doc: ProseMirrorNode, json: any): Selection

Deserialize the JSON representation of a selection. Must be implemented for custom classes (as a static class method).

Selection.fromJSON

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

To be able to deserialize selections from JSON, custom selection classes must register themselves with an ID string, so that they can be disambiguated. Try to pick something that’s unlikely to clash with classes from other modules.

Selection.jsonID

static near($pos: ResolvedPos, bias?: number): Selection

Find a valid cursor or leaf node selection near the given position. Searches forward first by default, but if bias is negative, it will search backwards first.

Selection.near


The state of a ProseMirror editor is represented by an object of this type. A state is a persistent data structure—it isn’t updated, but rather a new state value is computed from an old one using the apply method.

A state holds a number of built-in fields, and plugins can define additional fields.

new EditorState(): EditorState

doc: ProseMirrorNode

The current document.

selection: Selection

The selection.

storedMarks: null | readonly Mark[]

A set of marks to apply to the next input. Will be null when no explicit marks have been set.

get plugins(): readonly ProseMirrorPlugin<any>[]

The plugins that are active in this state.

readonly ProseMirrorPlugin<any>[]

get schema(): Schema

The schema of the state’s document.

Schema

get tr(): Transaction

Start a transaction from this state.

Transaction

apply(tr: Transaction): EditorState

Apply the given transaction to produce a new state.

applyTransaction(rootTr: Transaction): object

Verbose variant of apply that returns the precise transactions that were applied (which might be influenced by the transaction hooks of plugins) along with the new state.

reconfigure(config: object): EditorState

Create a new state based on this one, but with an adjusted set of active plugins. State fields that exist in both sets of plugins are kept unchanged. Those that no longer exist are dropped, and those that are new are initialized using their init method, passing in the new configuration object..

toJSON(pluginFields?: object): any

Serialize this state to JSON. If you want to serialize the state of plugins, pass an object mapping property names to use in the resulting JSON object to plugin objects. The argument may also be a string or number, in which case it is ignored, to support the way JSON.stringify calls toString methods.

static create(config: EditorStateConfig): EditorState

Create a new state.

static fromJSON(config: object, json: any, pluginFields?: object): EditorState

Deserialize a JSON representation of a state. config should have at least a schema field, and should contain array of plugins to initialize the state with. pluginFields can be used to deserialize the state of plugins, by associating plugin instances with the property names they use in the JSON object.


A node selection is a selection that points at a single node. All nodes marked selectable can be the target of a node selection. In such a selection, from and to point directly before and after the selected node, anchor equals from, and head equals to..

new NodeSelection($pos: ResolvedPos): NodeSelection

Create a node selection. Does not verify the validity of its argument.

Selection.constructor

readonly $anchor: ResolvedPos

The resolved anchor of the selection (the side that stays in place when the selection is modified).

readonly $head: ResolvedPos

The resolved head of the selection (the side that moves when the selection is modified).

node: ProseMirrorNode

The selected node.

ranges: readonly SelectionRange[]

The ranges covered by the selection.

visible: boolean

Controls whether, when a selection of this type is active in the browser, the selected range should be visible to the user. Defaults to true.

get $from(): ResolvedPos

The resolved lower bound of the selection’s main range.

ResolvedPos

Selection.$from

get $to(): ResolvedPos

The resolved upper bound of the selection’s main range.

ResolvedPos

Selection.$to

get anchor(): number

The selection’s anchor, as an unresolved position.

number

Selection.anchor

get empty(): boolean

Indicates whether the selection contains any content.

boolean

Selection.empty

get from(): number

The lower bound of the selection’s main range.

number

Selection.from

get head(): number

The selection’s head.

number

Selection.head

get to(): number

The upper bound of the selection’s main range.

number

Selection.to

content(): Slice

Get the content of this selection as a slice.

Selection.content

eq(other: Selection): boolean

Test whether the selection is the same as another selection.

Selection.eq

getBookmark(): NodeBookmark

Get a bookmark for this selection, which is a value that can be mapped without having access to a current document, and later resolved to a real selection for a given document again. (This is used mostly by the history to track and restore old selections.) The default implementation of this method just converts the selection to a text selection and returns the bookmark for that.

Selection.getBookmark

map(doc: ProseMirrorNode, mapping: Mappable): Selection

Map this selection through a mappable thing. doc should be the new document to which we are mapping.

Selection.map

replace(tr: Transaction, content?: Slice): void

Replace the selection with a slice or, if no slice is given, delete the selection. Will append to the given transaction.

Selection.replace

replaceWith(tr: Transaction, node: ProseMirrorNode): void

Replace the selection with the given node, appending the changes to the given transaction.

Selection.replaceWith

toJSON(): any

Convert the selection to a JSON representation. When implementing this for a custom selection class, make sure to give the object a type property whose value matches the ID under which you registered your class.

Selection.toJSON

static atEnd(doc: ProseMirrorNode): Selection

Find the cursor or leaf node selection closest to the end of the given document.

Selection.atEnd

static atStart(doc: ProseMirrorNode): Selection

Find the cursor or leaf node selection closest to the start of the given document. Will return an AllSelection if no valid position exists.

Selection.atStart

static create(doc: ProseMirrorNode, from: number): NodeSelection

Create a node selection from non-resolved positions.

static findFrom($pos: ResolvedPos, dir: number, textOnly?: boolean): null | Selection

Find a valid cursor or leaf node selection starting at the given position and searching back if dir is negative, and forward if positive. When textOnly is true, only consider cursor selections. Will return null when no valid selection position is found.

Selection.findFrom

static fromJSON(doc: ProseMirrorNode, json: any): Selection

Deserialize the JSON representation of a selection. Must be implemented for custom classes (as a static class method).

Selection.fromJSON

static isSelectable(node: ProseMirrorNode): boolean

Determines whether the given node may be selected as a node selection.

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

To be able to deserialize selections from JSON, custom selection classes must register themselves with an ID string, so that they can be disambiguated. Try to pick something that’s unlikely to clash with classes from other modules.

Selection.jsonID

static near($pos: ResolvedPos, bias?: number): Selection

Find a valid cursor or leaf node selection near the given position. Searches forward first by default, but if bias is negative, it will search backwards first.

Selection.near


A key is used to tag plugins in a way that makes it possible to find them, given an editor state. Assigning a key does mean only one plugin of that type can be active in a state.

Type Parameter Default type

PluginState

any

new PluginKey<PluginState>(name?: string): PluginKey<PluginState>

Create a plugin key.

get(state: EditorState): undefined | ProseMirrorPlugin<PluginState>

Get the active plugin with this key, if any, from an editor state.

getState(state: EditorState): undefined | PluginState

Get the plugin’s state from an editor state.


Plugins bundle functionality that can be added to an editor. They are part of the editor state and may influence that state and the view that contains it.

Type Parameter Default type

PluginState

any

new ProseMirrorPlugin<PluginState>(spec: PluginSpec<PluginState>): ProseMirrorPlugin<PluginState>

Create a plugin.

readonly props: EditorProps<ProseMirrorPlugin<PluginState>>

The props exported by this plugin.

readonly spec: PluginSpec<PluginState>

The plugin’s spec object.

getState(state: EditorState): undefined | PluginState

Extract the plugin’s state field from an editor state.


Superclass for editor selections. Every selection type should extend this. Should not be instantiated directly.

new Selection($anchor: ResolvedPos, $head: ResolvedPos, ranges?: readonly SelectionRange[]): Selection

Initialize a selection with the head and anchor and ranges. If no ranges are given, constructs a single range across $anchor and $head.

readonly $anchor: ResolvedPos

The resolved anchor of the selection (the side that stays in place when the selection is modified).

readonly $head: ResolvedPos

The resolved head of the selection (the side that moves when the selection is modified).

ranges: readonly SelectionRange[]

The ranges covered by the selection.

visible: boolean

Controls whether, when a selection of this type is active in the browser, the selected range should be visible to the user. Defaults to true.

get $from(): ResolvedPos

The resolved lower bound of the selection’s main range.

ResolvedPos

get $to(): ResolvedPos

The resolved upper bound of the selection’s main range.

ResolvedPos

get anchor(): number

The selection’s anchor, as an unresolved position.

number

get empty(): boolean

Indicates whether the selection contains any content.

boolean

get from(): number

The lower bound of the selection’s main range.

number

get head(): number

The selection’s head.

number

get to(): number

The upper bound of the selection’s main range.

number

content(): Slice

Get the content of this selection as a slice.

abstract eq(selection: Selection): boolean

Test whether the selection is the same as another selection.

getBookmark(): SelectionBookmark

Get a bookmark for this selection, which is a value that can be mapped without having access to a current document, and later resolved to a real selection for a given document again. (This is used mostly by the history to track and restore old selections.) The default implementation of this method just converts the selection to a text selection and returns the bookmark for that.

abstract map(doc: ProseMirrorNode, mapping: Mappable): Selection

Map this selection through a mappable thing. doc should be the new document to which we are mapping.

replace(tr: Transaction, content?: Slice): void

Replace the selection with a slice or, if no slice is given, delete the selection. Will append to the given transaction.

replaceWith(tr: Transaction, node: ProseMirrorNode): void

Replace the selection with the given node, appending the changes to the given transaction.

abstract toJSON(): any

Convert the selection to a JSON representation. When implementing this for a custom selection class, make sure to give the object a type property whose value matches the ID under which you registered your class.

static atEnd(doc: ProseMirrorNode): Selection

Find the cursor or leaf node selection closest to the end of the given document.

static atStart(doc: ProseMirrorNode): Selection

Find the cursor or leaf node selection closest to the start of the given document. Will return an AllSelection if no valid position exists.

static findFrom($pos: ResolvedPos, dir: number, textOnly?: boolean): null | Selection

Find a valid cursor or leaf node selection starting at the given position and searching back if dir is negative, and forward if positive. When textOnly is true, only consider cursor selections. Will return null when no valid selection position is found.

static fromJSON(doc: ProseMirrorNode, json: any): Selection

Deserialize the JSON representation of a selection. Must be implemented for custom classes (as a static class method).

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

To be able to deserialize selections from JSON, custom selection classes must register themselves with an ID string, so that they can be disambiguated. Try to pick something that’s unlikely to clash with classes from other modules.

static near($pos: ResolvedPos, bias?: number): Selection

Find a valid cursor or leaf node selection near the given position. Searches forward first by default, but if bias is negative, it will search backwards first.


Represents a selected range in a document.

new SelectionRange($from: ResolvedPos, $to: ResolvedPos): SelectionRange

Create a range.

readonly $from: ResolvedPos

The lower bound of the range.

readonly $to: ResolvedPos

The upper bound of the range.


A text selection represents a classical editor selection, with a head (the moving side) and anchor (immobile side), both of which point into textblock nodes. It can be empty (a regular cursor position).

new TextSelection($anchor: ResolvedPos, $head?: ResolvedPos): TextSelection

Construct a text selection between the given points.

Selection.constructor

readonly $anchor: ResolvedPos

The resolved anchor of the selection (the side that stays in place when the selection is modified).

readonly $head: ResolvedPos

The resolved head of the selection (the side that moves when the selection is modified).

ranges: readonly SelectionRange[]

The ranges covered by the selection.

visible: boolean

Controls whether, when a selection of this type is active in the browser, the selected range should be visible to the user. Defaults to true.

get $cursor(): null | ResolvedPos

Returns a resolved position if this is a cursor selection (an empty text selection), and null otherwise.

null | ResolvedPos

get $from(): ResolvedPos

The resolved lower bound of the selection’s main range.

ResolvedPos

Selection.$from

get $to(): ResolvedPos

The resolved upper bound of the selection’s main range.

ResolvedPos

Selection.$to

get anchor(): number

The selection’s anchor, as an unresolved position.

number

Selection.anchor

get empty(): boolean

Indicates whether the selection contains any content.

boolean

Selection.empty

get from(): number

The lower bound of the selection’s main range.

number

Selection.from

get head(): number

The selection’s head.

number

Selection.head

get to(): number

The upper bound of the selection’s main range.

number

Selection.to

content(): Slice

Get the content of this selection as a slice.

Selection.content

eq(other: Selection): boolean

Test whether the selection is the same as another selection.

Selection.eq

getBookmark(): TextBookmark

Get a bookmark for this selection, which is a value that can be mapped without having access to a current document, and later resolved to a real selection for a given document again. (This is used mostly by the history to track and restore old selections.) The default implementation of this method just converts the selection to a text selection and returns the bookmark for that.

Selection.getBookmark

map(doc: ProseMirrorNode, mapping: Mappable): Selection

Map this selection through a mappable thing. doc should be the new document to which we are mapping.

Selection.map

replace(tr: Transaction, content?: Slice): void

Replace the selection with a slice or, if no slice is given, delete the selection. Will append to the given transaction.

Selection.replace

replaceWith(tr: Transaction, node: ProseMirrorNode): void

Replace the selection with the given node, appending the changes to the given transaction.

Selection.replaceWith

toJSON(): any

Convert the selection to a JSON representation. When implementing this for a custom selection class, make sure to give the object a type property whose value matches the ID under which you registered your class.

Selection.toJSON

static atEnd(doc: ProseMirrorNode): Selection

Find the cursor or leaf node selection closest to the end of the given document.

Selection.atEnd

static atStart(doc: ProseMirrorNode): Selection

Find the cursor or leaf node selection closest to the start of the given document. Will return an AllSelection if no valid position exists.

Selection.atStart

static between($anchor: ResolvedPos, $head: ResolvedPos, bias?: number): Selection

Return a text selection that spans the given positions or, if they aren’t text positions, find a text selection near them. bias determines whether the method searches forward (default) or backwards (negative number) first. Will fall back to calling Selection.near when the document doesn’t contain a valid text position.

static create(doc: ProseMirrorNode, anchor: number, head?: number): TextSelection

Create a text selection from non-resolved positions.

static findFrom($pos: ResolvedPos, dir: number, textOnly?: boolean): null | Selection

Find a valid cursor or leaf node selection starting at the given position and searching back if dir is negative, and forward if positive. When textOnly is true, only consider cursor selections. Will return null when no valid selection position is found.

Selection.findFrom

static fromJSON(doc: ProseMirrorNode, json: any): Selection

Deserialize the JSON representation of a selection. Must be implemented for custom classes (as a static class method).

Selection.fromJSON

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

To be able to deserialize selections from JSON, custom selection classes must register themselves with an ID string, so that they can be disambiguated. Try to pick something that’s unlikely to clash with classes from other modules.

Selection.jsonID

static near($pos: ResolvedPos, bias?: number): Selection

Find a valid cursor or leaf node selection near the given position. Searches forward first by default, but if bias is negative, it will search backwards first.

Selection.near


An editor state transaction, which can be applied to a state to create an updated state. Use EditorState.tr to create an instance.

Transactions track changes to the document (they are a subclass of Transform), but also other state changes, like selection updates and adjustments of the set of stored marks. In addition, you can store metadata properties in a transaction, which are extra pieces of information that client code or plugins can use to describe what a transaction represents, so that they can update their own state accordingly.

The editor view uses a few metadata properties: it will attach a property "pointer" with the value true to selection transactions directly caused by mouse or touch input, a "composition" property holding an ID identifying the composition that caused it to transactions caused by composed DOM input, and a "uiEvent" property of that may be "paste", "cut", or "drop".

new Transaction(doc: ProseMirrorNode): Transaction

Create a transform that starts with the given document.

Transform.constructor

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.

storedMarks: null | readonly Mark[]

The stored marks set by this transaction, if any.

time: number

The timestamp associated with this transaction, in the same format as Date.now().

get before(): ProseMirrorNode

The starting document.

ProseMirrorNode

Transform.before

get docChanged(): boolean

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

boolean

Transform.docChanged

get isGeneric(): boolean

Returns true if this transaction doesn’t contain any metadata, and can thus safely be extended.

boolean

get scrolledIntoView(): boolean

True when this transaction has had scrollIntoView called on it.

boolean

get selection(): Selection

The transaction’s current selection. This defaults to the editor selection mapped through the steps in the transaction, but can be overwritten with setSelection.

Selection

get selectionSet(): boolean

Whether the selection was explicitly updated by this transaction.

boolean

get storedMarksSet(): boolean

Whether the stored marks were explicitly set for this transaction.

boolean

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

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

Transform.addMark

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

Add a mark to the node at position pos.

Transform.addNodeMark

addStoredMark(mark: Mark): this

Add a mark to the set of stored marks.

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.

Transform.clearIncompatible

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

Delete the content between the given positions.

Transform.delete

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

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

Transform.deleteRange

deleteSelection(): this

Delete the selection.

ensureMarks(marks: readonly Mark[]): this

Make sure the current stored marks or, if that is null, the marks at the selection, match the given set of marks. Does nothing if this is already the case.

getMeta(key: string | ProseMirrorPlugin<any> | PluginKey<any>): any

Retrieve a metadata property for a given name or plugin.

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

Insert the given content at the given position.

Transform.insert

insertText(text: string, from?: number, to?: number): this

Replace the given range, or the selection if no range is given, with a text node containing the given string.

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.

Transform.join

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.

Transform.lift

maybeStep(step: Step): StepResult

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

Transform.maybeStep

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.

Transform.removeMark

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

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

Transform.removeNodeMark

removeStoredMark(mark: MarkType | Mark): this

Remove a mark or mark type from the set of stored marks.

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

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

Transform.replace

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.

Transform.replaceRange

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.

Transform.replaceRangeWith

replaceSelection(slice: Slice): this

Replace the current selection with the given slice.

replaceSelectionWith(node: ProseMirrorNode, inheritMarks?: boolean): this

Replace the selection with the given node. When inheritMarks is true and the content is inline, it inherits the marks from the place where it is inserted.

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.

Transform.replaceWith

scrollIntoView(): this

Indicate that the editor should scroll the selection into view when updated to the state produced by this transaction.

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.

Transform.setBlockType

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

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

Transform.setDocAttribute

setMeta(key: string | ProseMirrorPlugin<any> | PluginKey<any>, value: any): this

Store a metadata property in this transaction, keyed either by name or by plugin.

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.

Transform.setNodeAttribute

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,

Transform.setNodeMarkup

setSelection(selection: Selection): this

Update the transaction’s current selection. Will determine the selection that the editor gets when the transaction is applied.

setStoredMarks(marks: null | readonly Mark[]): this

Set the current stored marks.

setTime(time: number): this

Update the timestamp for the transaction.

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).

Transform.split

step(step: Step): this

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

Transform.step

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.

Transform.wrap

The type of object passed to EditorState.create.

doc?: ProseMirrorNode

The starting document. Either this or schema must be provided.

plugins?: readonly ProseMirrorPlugin<any>[]

The plugins that should be active in this state.

schema?: Schema<any, any>

The schema to use (only relevant if no doc is specified).

selection?: Selection

A valid selection in the document.

storedMarks?: null | readonly Mark[]

The initial set of stored marks.


This is the type passed to the Plugin constructor. It provides a definition for a plugin.

Type Parameter

PluginState

[key: string]: any

Additional properties are allowed on plugin specs, which can be read via Plugin.spec.

appendTransaction?: (transactions: readonly Transaction[], oldState: EditorState, newState: EditorState) => undefined | null | Transaction

Allows the plugin to append another transaction to be applied after the given array of transactions. When another plugin appends a transaction after this was called, it is called again with the new state and new transactions—but only the new transactions, i.e. it won’t be passed transactions that it already saw.

filterTransaction?: (tr: Transaction, state: EditorState) => boolean

When present, this will be called before a transaction is applied by the state, allowing the plugin to cancel it (by returning false).

key?: PluginKey<any>

Can be used to make this a keyed plugin. You can have only one plugin with a given key in a given state, but it is possible to access the plugin’s configuration and state through the key, without having access to the plugin instance object.

props?: EditorProps<ProseMirrorPlugin<PluginState>>

The view props added by this plugin. Props that are functions will be bound to have the plugin instance as their this binding.

state?: StateField<PluginState>

Allows a plugin to define a state field, an extra slot in the state object in which it can keep its own data.

view?: (view: EditorView) => PluginView

When the plugin needs to interact with the editor view, or set something up in the DOM, use this field. The function will be called when the plugin’s state is associated with an editor view.


A lightweight, document-independent representation of a selection. You can define a custom bookmark type for a custom selection class to make the history handle it well.

map: (mapping: Mappable) => SelectionBookmark

Map the bookmark through a set of changes.

resolve: (doc: ProseMirrorNode) => Selection

Resolve the bookmark to a real selection again. This may need to do some error checking and may fall back to a default (usually TextSelection.between) if mapping made the bookmark invalid.


A plugin spec may provide a state field (under its state property) of this type, which describes the state it wants to keep. Functions provided here are always called with the plugin instance as their this binding.

Type Parameter

T

apply: (tr: Transaction, value: T, oldState: EditorState, newState: EditorState) => T

Apply the given transaction to this state field, producing a new field value. Note that the newState argument is again a partially constructed state does not yet contain the state from plugins coming after this one.

fromJSON?: (config: EditorStateConfig, value: any, state: EditorState) => T

Deserialize the JSON representation of this field. Note that the state argument is again a half-initialized state.

init: (config: EditorStateConfig, instance: EditorState) => T

Initialize the value of the field. config will be the object passed to EditorState.create. Note that instance is a half-initialized state instance, and will not have values for plugin fields initialized after this one.

toJSON?: (value: T) => any

Convert this field to JSON. Optional, can be left off to disable JSON serialization for the field.

type Command = (state: EditorState, dispatch?: (tr: Transaction) => void, view?: EditorView) => boolean

Commands are functions that take a state and a an optional transaction dispatch function and…

  • determine whether they apply to this state
  • if not, return false
  • if dispatch was passed, perform their effect, possibly by passing a transaction to dispatch
  • return true

In some cases, the editor view is passed as a third argument.


type PluginView = { destroy?: () => void; update?: (view: EditorView, prevState: EditorState) => void; }

A stateful object that can be installed in an editor by a plugin.

destroy?: () => void

Called when the view is destroyed or receives a state with different plugins.

update?: (view: EditorView, prevState: EditorState) => void

Called whenever the view’s state is updated.

Renames and re-exports ProseMirrorPlugin