Skip to main content

Constructor

Create a new editor instance.
Partial<EditorOptions>
Configuration options for the editor.

Properties

schema

The ProseMirror schema used by the editor.

view

The ProseMirror EditorView instance.

state

The current ProseMirror EditorState.

commands

An object of all registered commands. Each command returns a boolean indicating success.

storage

The editor storage object. Extensions can store data here.

isEditable

Whether the editor is currently editable.

isFocused

Whether the editor is currently focused.

isEmpty

Whether the editor content is empty.

isDestroyed

Whether the editor has been destroyed.

isInitialized

Whether the editor is initialized (after the create event has been emitted).

instanceId

A unique ID for this editor instance.

Methods

chain()

Create a command chain to call multiple commands at once.
ChainedCommands
A chainable command object. End with .run() to execute.
Example

can()

Check if a command or command chain can be executed without actually executing it.
CanCommands
An object with the same commands as editor.commands, but they return true/false instead of executing.
Example

setOptions()

Update editor options.
Partial<EditorOptions>
required
Options to update.
Example

setEditable()

Update the editable state of the editor.
boolean
required
Whether the editor should be editable.
boolean
default:"true"
Whether to emit an update event.
Example

mount()

Attach the editor to a DOM element.
Element
required
The DOM element to mount the editor to.
Example

unmount()

Remove the editor from the DOM, but allow remounting later.
Example

destroy()

Destroy the editor instance and cleanup.
Example

getJSON()

Get the document as JSON.
JSONContent
The editor content as a JSON object.
Example

getHTML()

Get the document as HTML.
string
The editor content as an HTML string.
Example

getText()

Get the document as plain text.
object
string
The editor content as plain text.
Example

getAttributes()

Get attributes of the currently selected node or mark.
string | NodeType | MarkType
required
The name or type of the node or mark.
Record<string, any>
The attributes of the node or mark.
Example

isActive()

Check if a node or mark is active at the current selection.
string
The name of the node or mark.
Record<string, any>
Optional attributes to match.
boolean
Whether the node or mark is active.
Example

registerPlugin()

Register a ProseMirror plugin.
Plugin
required
The ProseMirror plugin to register.
(newPlugin: Plugin, plugins: Plugin[]) => Plugin[]
Optional function to control how the plugin is merged into existing plugins.
EditorState
The new editor state.
Example

unregisterPlugin()

Unregister a ProseMirror plugin.
string | PluginKey | (string | PluginKey)[]
required
The plugin name or PluginKey to remove.
EditorState | undefined
The new editor state, or undefined if the plugin wasn’t found.
Example

$node()

Query for a single node using a CSS-like selector.
string
required
A CSS-like selector (e.g., 'paragraph', 'heading[level=1]').
Record<string, any>
Additional attributes to match.
NodePos | null
A NodePos object if found, otherwise null.
Example

$nodes()

Query for multiple nodes using a CSS-like selector.
string
required
A CSS-like selector.
Record<string, any>
Additional attributes to match.
NodePos[] | null
An array of NodePos objects if found, otherwise null.
Example

$pos()

Get a resolved position at the given position.
number
required
The position in the document.
NodePos
A NodePos object for the given position.
Example

$doc

Get a NodePos for the document root.
Example

Events

The editor extends EventEmitter and emits the following events:

beforeCreate

Emitted before the editor is created.

create

Emitted when the editor is ready.

mount

Emitted when the editor is mounted.

unmount

Emitted when the editor is unmounted.

update

Emitted when the content changes.

selectionUpdate

Emitted when the selection changes.

transaction

Emitted after each transaction.

focus

Emitted when the editor gains focus.

blur

Emitted when the editor loses focus.

destroy

Emitted when the editor is destroyed.

contentError

Emitted when there’s an error parsing content.

Example