Constructor
Create a new editor instance.
Configuration options for the editor. element Element | { mount: HTMLElement } | ((editor: HTMLElement) => void) | null
The DOM element to mount the editor to. If null, the editor won’t be mounted automatically.
The initial content of the editor (HTML, JSON, or a JSON array).
Array of Tiptap extensions to use.
Whether the editor is editable.
autofocus FocusPosition
default: "false"
The editor’s initial focus position. Can be true, false, 'start', 'end', a number, or 'all'.
Whether to inject base CSS styles.
A nonce to use for CSP while injecting styles.
textDirection 'ltr' | 'rtl' | 'auto' | undefined
The default text direction for all content. When set, all nodes will have the corresponding dir attribute.
ProseMirror EditorProps to pass to the view.
Options for parsing content.
enableInputRules EnableRules
default: "true"
Whether to enable input rules.
enablePasteRules EnableRules
default: "true"
Whether to enable paste rules.
enableCoreExtensions boolean | Partial<Record<CoreExtensionName, false>>
default: "true"
Whether to enable core extensions. Can be false to disable all, or an object to disable specific extensions.
If true, the editor will check content for errors on initialization.
onBeforeCreate (props: { editor: Editor }) => void
Called before the editor is constructed.
onCreate (props: { editor: Editor }) => void
Called after the editor is constructed.
onMount (props: { editor: Editor }) => void
Called when the editor is mounted.
onUnmount (props: { editor: Editor }) => void
Called when the editor is unmounted.
onUpdate (props: { editor: Editor; transaction: Transaction }) => void
Called when the editor’s content is updated.
onSelectionUpdate (props: { editor: Editor; transaction: Transaction }) => void
Called when the editor’s selection is updated.
onTransaction (props: { editor: Editor; transaction: Transaction }) => void
Called after a transaction is applied.
onFocus (props: { editor: Editor; event: FocusEvent; transaction: Transaction }) => void
Called on focus events.
onBlur (props: { editor: Editor; event: FocusEvent; transaction: Transaction }) => void
Called on blur events.
Called when the editor is destroyed.
onContentError (props: { editor: Editor; error: Error; disableCollaboration: () => void }) => void
Called when the editor encounters an error while parsing content.
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.
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.
An object with the same commands as editor.commands, but they return true/false instead of executing.
Example
setOptions()
Update editor options.
options Partial<EditorOptions>
required
Options to update.
Example
setEditable()
Update the editable state of the editor.
Whether the editor should be editable.
Whether to emit an update event.
Example
mount()
Attach the editor to a DOM element.
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.
The editor content as a JSON object.
Example
getHTML()
Get the document as HTML.
The editor content as an HTML string.
Example
getText()
Get the document as plain text.
blockSeparator string
default: "'\\\\n\\\\n'"
The string to use between block nodes.
textSerializers Record<string, TextSerializer>
default: "{}"
Custom text serializers for specific node types.
The editor content as plain text.
Example
getAttributes()
Get attributes of the currently selected node or mark.
nameOrType string | NodeType | MarkType
required
The name or type of the node or mark.
The attributes of the node or mark.
Example
isActive()
Check if a node or mark is active at the current selection.
The name of the node or mark.
Optional attributes to match.
Whether the node or mark is active.
Example
registerPlugin()
Register a ProseMirror plugin.
The ProseMirror plugin to register.
handlePlugins (newPlugin: Plugin, plugins: Plugin[]) => Plugin[]
Optional function to control how the plugin is merged into existing plugins.
Example
unregisterPlugin()
Unregister a ProseMirror plugin.
nameOrPluginKey string | PluginKey | (string | PluginKey)[]
required
The plugin name or PluginKey to remove.
The new editor state, or undefined if the plugin wasn’t found.
Example
$node()
Query for a single node using a CSS-like selector.
A CSS-like selector (e.g., 'paragraph', 'heading[level=1]').
Additional attributes to match.
A NodePos object if found, otherwise null.
Example
$nodes()
Query for multiple nodes using a CSS-like selector.
Additional attributes to match.
An array of NodePos objects if found, otherwise null.
Example
$pos()
Get a resolved position at the given position.
The position in the document.
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