@eigenpal/docx-editor-core/prosemirror/plugins
ProseMirror Plugins
Selection tracker plugin for the DOCX editor. Keymap plugins are now provided by the extension system.
Functions (13)
createDocumentContextPluginfunctionSource ↗
Create the plugin holding [DocumentContext](DocumentContext) for the lifetime of the EditorState. Separate from the resolver plugin so the resolver's public documentStylesKey shape stays stable. The table-insert command reads the theme + default-table styleId from here to bake an inserted table the same way convertTable does on import.
declare function createDocumentContextPlugin(options?: Partial<DocumentContext>): Plugin;createDocumentStylesPluginfunctionSource ↗
Create the plugin holding a StyleResolver for the document's styles for the lifetime of the EditorState. The resolver is fixed per document load; loading a new document recreates the state (and thus this plugin) with a fresh resolver. Accepts a pre-built resolver too, for callers that already have one.
declare function createDocumentStylesPlugin(styles: StyleDefinitions | StyleResolver | null | undefined): Plugin;createSelectionTrackerPluginfunctionSource ↗
Create selection tracker plugin
declare function createSelectionTrackerPlugin(onSelectionChange?: SelectionChangeCallback): Plugin;createSuggestionModePluginfunctionSource ↗
Create the suggestion-mode ProseMirror plugin. **Must be mounted on the editor view for setSuggestionMode and toggleSuggestionMode to do anything** — both adapters (@eigenpal/docx-editor-react, @eigenpal/docx-editor-vue) auto-mount this inside the DocxEditor component, so consumers using the bundled components don't need to register it themselves.
When active, typed text gets the insertion mark, deleted text gets the deletion mark (text stays in the doc; the painter strikes it through), Enter sets pPrIns on the originating paragraph, and Backspace at paragraph start sets pPrDel on the previous paragraph. Author + adjacent same-author marks coalesce into one tracked change.
declare function createSuggestionModePlugin(initialActive?: boolean, author?: string): Plugin;```ts
import { createSuggestionModePlugin } from '@eigenpal/docx-editor-core/prosemirror/plugins';
const plugin = createSuggestionModePlugin(false, 'Jane');
EditorState.create({ doc, plugins: [plugin, ...other] });
```extractSelectionContextfunctionSource ↗
Extract selection context from editor state
declare function extractSelectionContext(state: EditorState): SelectionContext;getDefaultTableStyleIdfunctionSource ↗
Read w:defaultTableStyle (styleId for new tables), or null.
declare function getDefaultTableStyleId(state: EditorState): string | null;getDocumentStyleResolverfunctionSource ↗
Read the document's StyleResolver, or null when the plugin isn't installed.
declare function getDocumentStyleResolver(state: EditorState): StyleResolver | null;getDocumentThemefunctionSource ↗
Read the document theme, or null when the context plugin isn't installed.
declare function getDocumentTheme(state: EditorState): Theme | null;getSelectionContextfunctionSource ↗
Get current selection context from editor state
declare function getSelectionContext(state: EditorState): SelectionContext | null;isSuggestionModeActivefunctionSource ↗
Check if suggestion mode is currently active.
declare function isSuggestionModeActive(state: EditorState): boolean;makeRevisionInfofunctionSource ↗
Build a fresh RevisionInfo triple from the active suggesting-mode state. Returns null when suggesting mode is OFF — callers use this to decide whether to track an edit or apply it directly.
Shared by suggestionMode.ts's text/paragraph handlers and by the suggesting-aware table commands (addRowBelow, deleteRow, ...). One source of truth for both the mint and the author/date fields.
declare function makeRevisionInfo(state: EditorState): RevisionInfo | null;setSuggestionModefunctionSource ↗
Set suggesting mode active state and (optionally) author. Author tracks across every revision minted while the mode is on. The mounted createSuggestionModePlugin is required.
declare function setSuggestionMode(active: boolean, state: EditorState, dispatch?: (tr: Transaction) => void, author?: string): boolean;```ts
import { setSuggestionMode } from '@eigenpal/docx-editor-core/prosemirror/plugins';
setSuggestionMode(true, view.state, view.dispatch, 'Jane');
// ... typed text now wraps in <w:ins> with author="Jane"
setSuggestionMode(false, view.state, view.dispatch);
```toggleSuggestionModefunctionSource ↗
Toggle suggesting mode on/off. The mounted createSuggestionModePlugin is required for the dispatch to have any effect — without it the meta is silently dropped. Returns false (no-op) if the plugin is missing.
declare function toggleSuggestionMode(state: EditorState, dispatch?: (tr: Transaction) => void): boolean;```ts
import { toggleSuggestionMode } from '@eigenpal/docx-editor-core/prosemirror/plugins';
toggleSuggestionMode(view.state, view.dispatch);
```Interfaces (3)
DocumentContextinterfaceSource ↗
Extra document-level context parked alongside the StyleResolver.
interface DocumentContext| Member | Type | Summary |
|---|---|---|
| defaultTableStyleId | string | null | `w:defaultTableStyle` (settings.xml) — styleId for newly created tables. |
| theme | Theme | null | The document theme, for resolving themed colors in commands. |
RevisionInfointerfaceSource ↗
Tracked-change attribute triple as it appears on PM node attrs (paragraph.pPrIns, tableRow.trIns, etc). Mirrors TrackedChangeInfo but with a null date (PM attr defaults) and a revisionId name that matches OOXML's w:id more idiomatically on the editor side.
Round-trip pairs with TrackedChangeInfo via { id, author, date? } ↔ { revisionId, author, date | null }.
interface RevisionInfo| Member | Type | Summary |
|---|---|---|
| author | string | |
| date | string | null | |
| revisionId | number |
SelectionContextinterfaceSource ↗
Selection context for toolbar state
interface SelectionContext| Member | Type | Summary |
|---|---|---|
| activeCommentIds | number[] | Active comment IDs at cursor position |
| endParagraphIndex | number | End paragraph index |
| hasSelection | boolean | Whether there's a non-collapsed selection |
| inDeletion | boolean | Whether cursor is inside a tracked deletion |
| inInsertion | boolean | Whether cursor is inside a tracked insertion |
| inList | boolean | Whether cursor is in a list |
| isMultiParagraph | boolean | Whether selection spans multiple paragraphs |
| listLevel? | number | List level (0-8) |
| listType? | 'bullet' | 'numbered' | List type if in list |
| paragraphFormatting | ParagraphFormatting | Current paragraph formatting |
| startParagraphIndex | number | Start paragraph index |
| textFormatting | TextFormatting | Current text formatting at cursor/selection |
Type aliases (1)
SelectionChangeCallbacktypeSource ↗
Callback type for selection changes
type SelectionChangeCallback = (context: SelectionContext) => void;Variables (4)
documentContextKeyconstSource ↗
documentContextKey: PluginKey<DocumentContext>documentStylesKeyconstSource ↗
documentStyles plugin — makes the document's StyleResolver reachable from ProseMirror commands.
Styles otherwise flow one way (Document → PM) at load time: toProseDoc bakes resolved formatting into nodes and discards the resolver. Some commands need the live style table though — the Enter handler looks up a paragraph style's w:next to switch to body text after a heading. This plugin parks the resolver in plugin state so those commands can read it via getDocumentStyleResolver(state).
A sibling documentContext plugin (below) carries the extra document-level context the table-insert command needs — the theme and the settings w:defaultTableStyle — without changing this resolver plugin's shape.
The host (React HiddenProseMirror / HiddenHeaderFooterPMs, Vue useDocxEditor) passes the same styles it hands to toProseDoc and adds these plugins when creating the EditorState. When absent, style-aware commands fall back to their style-agnostic behavior.
documentStylesKey: PluginKey<StyleResolver | null>selectionTrackerKeyconstSource ↗
Plugin key for accessing selection tracker state
selectionTrackerKey: PluginKey<SelectionContext>suggestionModeKeyconstSource ↗
suggestionModeKey: PluginKey<SuggestionModeState>