The Editor
The Editor is the central object you'll interact with at runtime. It wraps a ProseMirror EditorView and exposes typed shortcuts for the schema, commands, nodes, and marks contributed by your extensions.
Creating an editor
Section titled “Creating an editor”createEditor accepts:
| Option | Type | Notes |
|---|---|---|
extension | Extension | Required. Usually a union(...) of define* calls. |
defaultContent | NodeJSON | string | Element | Optional initial document. It can be a ProseMirror node JSON object, an HTML string, or a DOM element instance. |
defaultSelection | SelectionJSON | Optional initial selection (only used when defaultContent is set). |
Mounting and unmounting
Section titled “Mounting and unmounting”The editor doesn't render anything until you mount it on a DOM element.
Framework integrations call mount/unmount for you. See Frameworks.
Live properties
Section titled “Live properties”| Property | Type | What it gives you |
|---|---|---|
mounted | boolean | Whether the editor is currently attached to the DOM. |
view | EditorView | Underlying ProseMirror view (only valid after mount). |
state | EditorState | The current ProseMirror state. |
schema | Schema | The merged schema, narrowed to the union of nodes/marks you defined. |
focused | boolean | Whether the editor currently has focus. |
commands | CommandActions | Typed command actions, keyed by every defined command. |
nodes | NodeActions | Typed node creators (also exposes .isActive(attrs?)). |
marks | MarkActions | Typed mark creators (also exposes .isActive(attrs?)). |
Methods
Section titled “Methods”| Method | Purpose |
|---|---|
setContent(content, sel?) | Replace the document. content is NodeJSON | string | Element. |
getDocJSON() | Return the current document as JSON. |
getDocHTML(options?) | Render the document as an HTML string. |
exec(command) | Run a raw ProseMirror Command. Returns true on success. |
canExec(command) | Test whether a raw command would succeed without running it. |
use(extension) | Hot-add an extension at runtime. Returns a function that removes it. |
focus() / blur() | Imperatively change focus. |
mount(el) / unmount() | Attach / detach from the DOM. |
commands.<name>.canExec() is typically what you want for toolbar buttons. It returns true when the command would apply, which is the right signal for "is this button enabled?".
Hot-replacing extensions
Section titled “Hot-replacing extensions”editor.use registers an extension after the editor has been created. Use it for features that depend on runtime state (e.g., a search panel that's only active while open).