ProseMirror Trailing Node Plugin

3.0.0 · active · verified Sun Apr 19

prosemirror-trailing-node is a plugin for the ProseMirror rich text editor that ensures there's always an editable node at the end of the document. This is particularly useful for preventing users from getting stuck within non-editable or complex nodes, allowing for continuous input. It automatically appends a configurable default node, such as a paragraph, when the last node in the document is not empty. The current stable version is 3.0.0, aligning with the major version 3 of the Remirror ecosystem, of which it is a part. Remirror, and by extension its associated plugins like this one, maintains an active release cadence with frequent patch updates to address issues and align with ProseMirror core updates, as seen in recent changelogs. Its key differentiator is its simple, focused solution for a common ProseMirror UX problem, integrated within a broader, actively developed framework.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a basic ProseMirror editor with the `prosemirror-trailing-node` plugin, configuring it to append a paragraph node and ignore specific node types. It sets up the editor state and view, making it runnable in a browser environment.

import { schema } from 'prosemirror-schema-basic';
import { EditorState } from 'prosemirror-state';
import { EditorView } from 'prosemirror-view';
import { trailingNode } from 'prosemirror-trailing-node';

const editorSchema = schema;

// Initialize the editor state with the trailingNode plugin.
const state = EditorState.create({
  schema: editorSchema,
  plugins: [
    trailingNode({
      ignoredNodes: ['code_block'], // Example: don't add trailing node after code blocks
      nodeName: 'paragraph' // The node type to append
    })
  ]
});

// Create the editor view and mount it to the DOM.
const view = new EditorView(document.body, { 
  state,
  dispatchTransaction(transaction) {
    const newState = view.state.apply(transaction);
    view.updateState(newState);
  }
});

console.log('ProseMirror editor with trailing node plugin initialized.');

view raw JSON →