Common
Common plugin provides the foundational editor components and utilities. It includes the core ReactEditor, ReactEditorContent, and ReactPlainText components, along with essential editor services, node types, and data source management for building rich text editing experiences.
import { Common } from '@lobehub/editor';Introduction
Common plugin serves as the foundation of the editor system, providing essential components and utilities that other plugins depend on. It includes the core React components for rendering editor content, managing plain text input, and handling fundamental editor operations. This plugin also provides data source management, utility functions, and base node types that are used throughout the editor ecosystem.
Basic Usage
Components
ReactEditor
The core editor wrapper component that provides the editing environment.
ReactEditorContent
Component for rendering rich text editor content with full formatting support.
ReactPlainText
Simplified component for plain text editing without rich formatting.
Heading Anchors and Folding
Every heading gets a DOM id slug derived from its text, unique within the document (intro, intro-1, ...). The same slugs are produced by LexicalRenderer, so links work in both the editor and read-only output. Slugs are view-only and never written to JSON, Markdown or LiteXML.
Hovering a heading in the editor shows two actions after its text:
- Copy link: copies
getHeadingLink(slug)(default: the current URL with#slug). - Fold: hides the content until the next heading of the same or higher level. Fold state lives in the editor view only; it is never serialized and does not change any export. Moving the selection into folded content unfolds it.
<Editor
enableHeadingFold={false}
getHeadingLink={(slug) => `https://example.com/docs/page#${slug}`}
/>Fold state can also be driven through the IHeadingService:
import { IHeadingService } from '@lobehub/editor';
const headings = editor.requireService(IHeadingService);
headings?.toggleFolded(headingNodeKey);Core Architecture
Plugin System
- Plugin Interface: Standardized plugin architecture for extending editor functionality
- Service Registration: Centralized service container for plugin communication
- Command System: Event-driven command pattern for editor operations
Data Sources
- Content Management: Unified content storage and retrieval
- State Synchronization: Real-time state management across components
- Serialization: Content serialization for persistence and transport
Node System
- Base Nodes: Fundamental node types (text, paragraph, etc.)
- Custom Nodes: Framework for creating specialized content types
- Node Transformations: Utilities for node manipulation and conversion
Utilities
- Editor Helpers: Common editor operation utilities
- DOM Management: Cross-browser DOM manipulation helpers
- Event Handling: Standardized event processing and delegation
APIs
ReactEditor
| Property | Description | Type | Default |
|---|---|---|---|
| children | Editor content | ReactNode | - |
| className | Custom CSS class | string | - |
| style | Custom inline styles | CSSProperties | - |
ReactEditorContent
| Property | Description | Type | Default |
|---|---|---|---|
| content | Editor content data | EditorContentProps | - |
| onChange | Content change handler | (content) => void | - |
ReactPlainText
| Property | Description | Type | Default |
|---|---|---|---|
| enableHeadingAnchor | Heading id slugs and the hover "copy link" action | boolean | true (false for variant="chat") |
| enableHeadingFold | Hover toggle that folds the section under a heading | boolean | true (false for variant="chat") |
| getHeadingLink | Build the link copied by the heading "copy link" action | (slug: string) => string | current URL with #slug |
| theme | Text theme | PlainTextTheme | - |
| variant | Display variant | PlainTextVariant | - |
| value | Text content | string | - |
| onChange | Change handler | (value: string) => void | - |