New

docx-editor 1.x has shipped. Vue support, i18n, agents. Read the migration guide →

API Referencev1.3.3

@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)

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;

Create selection tracker plugin

declare function createSelectionTrackerPlugin(onSelectionChange?: SelectionChangeCallback): Plugin;

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] });
```

Extract selection context from editor state

declare function extractSelectionContext(state: EditorState): SelectionContext;

Read the document's StyleResolver, or null when the plugin isn't installed.

declare function getDocumentStyleResolver(state: EditorState): StyleResolver | null;

Get current selection context from editor state

declare function getSelectionContext(state: EditorState): SelectionContext | null;

Check if suggestion mode is currently active.

declare function isSuggestionModeActive(state: EditorState): boolean;

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;

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);
```

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)

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
MemberTypeSummary
authorstring
datestring | null
revisionIdnumber

Selection context for toolbar state

interface SelectionContext
MemberTypeSummary
activeCommentIdsnumber[]Active comment IDs at cursor position
endParagraphIndexnumberEnd paragraph index
hasSelectionbooleanWhether there's a non-collapsed selection
inDeletionbooleanWhether cursor is inside a tracked deletion
inInsertionbooleanWhether cursor is inside a tracked insertion
inListbooleanWhether cursor is in a list
isMultiParagraphbooleanWhether selection spans multiple paragraphs
listLevel?numberList level (0-8)
listType?'bullet' | 'numbered'List type if in list
paragraphFormattingParagraphFormattingCurrent paragraph formatting
startParagraphIndexnumberStart paragraph index
textFormattingTextFormattingCurrent text formatting at cursor/selection

Type aliases(1)

Callback type for selection changes

type SelectionChangeCallback = (context: SelectionContext) => void;

Variables(3)

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>

Plugin key for accessing selection tracker state

selectionTrackerKey: PluginKey<SelectionContext>
suggestionModeKey: PluginKey<SuggestionModeState>