Editor Frontend Module
Editor Frontend
ProseMirror-based rich text editor module providing document schema, command system, plugin architecture, and Svelte UI components for the authoring surface.
Responsibilities
- Define the document schema (nodes and marks) that governs legal document structure
- Provide 40+ formatting and structural commands with a fluent CommandChain API
- Assemble and manage ProseMirror plugins (history, keymaps, tables, cursors, search, spellcheck, glossary, context menu, file handling)
- Expose clean serialization API (HTML, plain text, ProseMirror JSON)
- Render the formatting toolbar and context menu UI via Svelte 5 components
- Integrate with Glossary, Search, and Spellcheck systems via plugin providers
Public API Surface
| Export | Kind | Source File | Description |
|---|---|---|---|
schema |
const | schema.ts | ProseMirror Schema instance with all nodes and marks |
ProseMirrorEditor |
class | ProseMirrorEditor.ts | Main editor wrapper with lifecycle, serialization, and plugin API |
ProseMirrorEditorOptions |
type | ProseMirrorEditor.ts | Constructor options interface |
CommandChain |
class | commands.ts | Fluent command composition with inter-command state refresh |
Command |
type | commands.ts | (state, dispatch?, view?) => boolean command signature |
toggleBold, toggleItalic, ... |
const | commands.ts | 6 mark toggle commands |
setParagraph, setHeading, ... |
const/fn | commands.ts | Block type and structural commands |
isMarkActive, isNodeActive |
function | commands.ts | Toolbar active state helpers |
findWordAtPos, selectWordAtPos, getSelectedText |
function | wordSelection.ts | Unicode-aware word boundary detection |
findNearestAncestorOfType, isInsideNodeType, getBlockRange, ... |
function | pmUtils.ts | ResolvedPos/NodeRange/Slice utilities |
searchHighlightKey, createSearchHighlightPlugin |
const/fn | searchHighlight.ts | Search match decoration plugin (documented in search-frontend) |
textAnnotationKey, createTextAnnotationPlugin, ... |
const/fn | textAnnotation.ts | Spellcheck/grammar decoration plugin |
createGlossaryMarkPlugin, setGlossaryMarkProvider, ... |
fn | glossaryMark.ts | Glossary tooltip/click plugin (documented in glossary-frontend) |
createContextMenuPlugin |
fn | contextMenu.ts | Right-click context menu plugin |
fileHandler |
fn | fileHandler.ts | Image drag-and-drop and paste plugin |
Internal Structure
The module is organized in two layers within src/lib/components/editor/:
editor/
├── TextEditor.svelte # Main Svelte component (toolbar, lifecycle, effects)
├── EditorContextMenu.svelte # Context menu component (positioned popup)
└── proseMirror/
├── schema.ts # Document schema definition
├── ProseMirrorEditor.ts # Editor wrapper class
├── commands.ts # 40+ commands + CommandChain
├── pmUtils.ts # ResolvedPos/NodeRange/Slice utilities
├── wordSelection.ts # Word boundary detection
├── index.ts # Barrel exports
└── plugins/
├── searchHighlight.ts # Search decoration plugin
├── textAnnotation.ts # Spellcheck decoration plugin
├── glossaryMark.ts # Glossary tooltip/click plugin
├── contextMenu.ts # Context menu plugin
└── fileHandler.ts # Image file handling plugin
The
searchHighlight.ts and glossaryMark.ts plugins are physically located in the editor module but are documented in their respective feature modules (search-frontend and glossary-frontend) because they are conceptually owned by those features. Cross-links are provided here.Dependencies
| Dependency | Internal/External | Purpose |
|---|---|---|
prosemirror-model |
external | Schema, Node, Mark, DOMParser, DOMSerializer |
prosemirror-state |
external | EditorState, Transaction, Plugin, PluginKey, TextSelection, NodeSelection |
prosemirror-view |
external | EditorView, Decoration, DecorationSet |
prosemirror-commands |
external | toggleMark, setBlockType, wrapIn, lift, baseKeymap |
prosemirror-keymap |
external | keymap() plugin factory |
prosemirror-history |
external | history(), undo, redo |
prosemirror-schema-basic |
external | Basic node and mark specs |
prosemirror-schema-list |
external | List node specs and commands |
prosemirror-tables |
external | Table node specs, editing, column resize, and 8 table commands |
prosemirror-transform |
external | findWrapping for structural transforms |
prosemirror-inputrules |
external | Input rule support (available but not currently used) |
prosemirror-dropcursor |
external | Visual drop cursor |
prosemirror-gapcursor |
external | Gap cursor for block boundaries |
orderedmap |
external | OrderedMap for schema node composition |
search-frontend |
internal | searchStore for reactive search query subscription |
glossary-frontend |
internal | glossaryApi for term data fetch; glossary-store for event subscriptions |
$lib/services/loggerService |
internal | createLogger() for structured logging |
$lib/services/wordCountService |
internal | countAll() for word/character count |
$lib/services/textAnalysis |
internal | createSpellcheckProvider() and TextAnalysisProvider type |
$lib/stores/preferences |
internal | userPreferences for spellcheck toggle |
$lib/stores/dictionary |
internal | dictionaryStore for custom word management |
$lib/services/moduleEventBus |
internal | dispatch/on for glossary events |
lucide-svelte |
external | Toolbar and context menu icons |
Dataflow Diagrams
- Editor Initialization: Mount to Ready
- Content Editing: Change to Persist
- Context Menu: Right-Click to Action