Skip to main content

Creating an Extension

Use the static create method to define a new extension.
Partial<ExtensionConfig<Options, Storage>> | (() => Partial<ExtensionConfig<Options, Storage>>)
The extension configuration object or a function that returns a configuration object.

Configuration Options

name

The unique name for the extension.
string
required
A unique identifier for the extension. This must be unique across all extensions.
Example

priority

The priority of the extension. Higher values are called earlier.
number
default:"100"
Extensions with higher priority take precedence. Core extensions typically use 100.
Example

addOptions()

Define options for the extension.
Example

addStorage()

Define storage for the extension to persist data.
Example

addGlobalAttributes()

Add attributes to specific node or mark types.
Example

addCommands()

Add commands to the editor.
Example

addKeyboardShortcuts()

Register keyboard shortcuts.
Example

addInputRules()

Add input rules that trigger on typing patterns.
Example

addPasteRules()

Add paste rules that trigger on pasting content.
Example

addProseMirrorPlugins()

Add ProseMirror plugins.
Example

addExtensions()

Add additional extensions (useful for extension kits).
Example

Lifecycle Hooks

onBeforeCreate()

Called before the editor is created.

onCreate()

Called when the editor is ready.

onUpdate()

Called when the content changes.

onSelectionUpdate()

Called when the selection changes.

onTransaction()

Called after each transaction.

onFocus()

Called when the editor gains focus.

onBlur()

Called when the editor loses focus.

onDestroy()

Called when the editor is destroyed.

Methods

configure()

Create a configured version of the extension.
Partial<Options>
Options to override the default options.
Example

extend()

Extend the extension with additional configuration.
Partial<ExtendedConfig> | (() => Partial<ExtendedConfig>)
Additional configuration or a function that returns configuration.
Example

Complete Example