Editor class is the core of Tiptap. It manages the editor state, handles transactions, and provides methods to interact with your content.
Creating an Editor
The simplest way to create an editor is to instantiate theEditor class:
Editor Options
TheEditor constructor accepts a configuration object with the following options:
The DOM element where the editor should be mounted. Can be
null if you want to mount it later.The initial content of the editor. Can be HTML string or JSON.
An array of extensions to use in the editor. Extensions add functionality like nodes, marks, and commands.
Whether the editor is editable.
Whether the editor should be focused on initialization.
trueor'start': Focus at the start'end': Focus at the endnumber: Focus at a specific position
Whether to inject the default Tiptap CSS styles.
Whether to enable input rules (e.g., markdown shortcuts).
Whether to enable paste rules.
Whether to enable core extensions (required for basic functionality).
Event Handlers
The editor emits events at different stages of its lifecycle:Called when the editor is created and ready.
Called whenever the document changes.
Called when the selection changes.
Called for every transaction (even if the document didn’t change).
Called when the editor receives focus.
Called when the editor loses focus.
Called when the editor is destroyed.
Core Methods
Content Methods
Replace the entire document with new content.Source:
/home/daytona/workspace/source/packages/core/src/commands/setContent.ts:35Get the current document as HTML.Source:
/home/daytona/workspace/source/packages/core/src/Editor.ts:737Get the current document as JSON.Source:
/home/daytona/workspace/source/packages/core/src/Editor.ts:727Get the current document as plain text.Source:
/home/daytona/workspace/source/packages/core/src/Editor.ts:744Focus Methods
Focus the editor at a specific position.
Remove focus from the editor.
Lifecycle Methods
Mount the editor to a DOM element.Source:
/home/daytona/workspace/source/packages/core/src/Editor.ts:161Unmount the editor from the DOM (but keep it in memory for later remounting).Source:
/home/daytona/workspace/source/packages/core/src/Editor.ts:190Destroy the editor and clean up all resources.Source:
/home/daytona/workspace/source/packages/core/src/Editor.ts:766Properties
Access to all registered commands.Source:
/home/daytona/workspace/source/packages/core/src/Editor.ts:232The ProseMirror schema generated from your extensions.Source:
/home/daytona/workspace/source/packages/core/src/Editor.ts:65The ProseMirror editor view.Source:
/home/daytona/workspace/source/packages/core/src/Editor.ts:305The current ProseMirror editor state.Source:
/home/daytona/workspace/source/packages/core/src/Editor.ts:353Whether the editor currently has focus.Source:
/home/daytona/workspace/source/packages/core/src/Editor.ts:69Whether the editor is editable.Source:
/home/daytona/workspace/source/packages/core/src/Editor.ts:295Whether the editor content is empty.Source:
/home/daytona/workspace/source/packages/core/src/Editor.ts:759Whether the editor has been destroyed.Source:
/home/daytona/workspace/source/packages/core/src/Editor.ts:777Access to extension storage.Source:
/home/daytona/workspace/source/packages/core/src/Editor.ts:225Advanced Usage
Making the Editor Read-only
Checking Active State
Getting Attributes
Working with Selection
TypeScript Types
Best Practices
Clean Up Resources
Always call
editor.destroy() when you’re done with an editor instance to prevent memory leaks.Batch Updates
Use command chains to batch multiple updates into a single transaction.
Check Before Acting
Use
editor.can() to check if a command can be executed before running it.Related
Commands
Learn about the command system
Extensions
Learn about extensions
Schema
Learn about the ProseMirror schema
Nodes & Marks
Learn about content structure