@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(10)
createDocumentStylesPlugin
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;createSelectionTrackerPlugin
Create selection tracker plugin
declare function createSelectionTrackerPlugin(onSelectionChange?: SelectionChangeCallback): Plugin;createSuggestionModePlugin
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] });
```extractSelectionContext
Extract selection context from editor state
declare function extractSelectionContext(state: EditorState): SelectionContext;getDocumentStyleResolver
Read the document's StyleResolver, or null when the plugin isn't installed.
declare function getDocumentStyleResolver(state: EditorState): StyleResolver | null;getSelectionContext
Get current selection context from editor state
declare function getSelectionContext(state: EditorState): SelectionContext | null;isSuggestionModeActive
Check if suggestion mode is currently active.
declare function isSuggestionModeActive(state: EditorState): boolean;makeRevisionInfo
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;setSuggestionMode
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);
```toggleSuggestionMode
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(2)
RevisionInfo
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 |
SelectionContext
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)
SelectionChangeCallback
Callback type for selection changes
type SelectionChangeCallback = (context: SelectionContext) => void;Variables(3)
documentStylesKey
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)`.
The host (React `HiddenProseMirror` / `HiddenHeaderFooterPMs`, Vue `useDocxEditor`) passes the same styles it hands to `toProseDoc` and adds this plugin when creating the EditorState. When absent, style-aware commands fall back to their style-agnostic behavior.
documentStylesKey: PluginKey<StyleResolver | null>selectionTrackerKey
Plugin key for accessing selection tracker state
selectionTrackerKey: PluginKey<SelectionContext>suggestionModeKey
suggestionModeKey: PluginKey<SuggestionModeState>