New

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

API Referencev1.0.2

@eigenpal/docx-editor-core/prosemirror/commands

ProseMirror Commands

Commands for formatting text and paragraphs.

Functions(77)

Accept all tracked changes in the document.

declare function acceptAllChanges(): Command;

Accept a tracked change at the given range. - Insertion: remove mark, keep text - Deletion: remove mark AND text

declare function acceptChange(from: number, to: number): Command;
declare function addColumnLeft(state: EditorState, dispatch?: (tr: Transaction) => void): boolean;
declare function addColumnRight(state: EditorState, dispatch?: (tr: Transaction) => void): boolean;

Add a comment mark to the current selection.

declare function addCommentMark(commentId: number): Command;
declare function addRowAbove(state: EditorState, dispatch?: (tr: Transaction) => void): boolean;
declare function addRowBelow(state: EditorState, dispatch?: (tr: Transaction) => void): boolean;
declare function addTabStop(position: number, alignment?: TabStopAlignment, leader?: TabLeader): Command;
declare function applyStyle(styleId: string, resolvedAttrs?: ResolvedStyleAttrs): Command;
declare function applyTableStyle(styleData: {
    styleId: string;
    tableBorders?: Record<string, unknown>;
    conditionals?: Record<string, unknown>;
    look?: Record<string, boolean>;
}): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;
declare function autoFitContents(): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;

Create a command that removes a mark from the selection

declare function createRemoveMarkCommand(markType: MarkType): Command;

Create a command that sets a mark on the selection

declare function createSetMarkCommand(markType: MarkType, attrs?: Record<string, unknown>): Command;
declare function decreaseIndent(amount?: number): Command;
declare function deleteColumn(state: EditorState, dispatch?: (tr: Transaction) => void): boolean;
declare function deleteRow(state: EditorState, dispatch?: (tr: Transaction) => void): boolean;
declare function deleteTable(state: EditorState, dispatch?: (tr: Transaction) => void): boolean;
declare function distributeColumns(): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;

Resolve the hyperlink mark + contiguous range that surrounds the current cursor. Used by edit/remove popup actions in both adapters.

Resolution order for the mark itself: 1. `$from.marks()` — the normal active-marks lookup 2. `$from.nodeAfter`/`nodeBefore` marks — boundary positions don't report active marks via `marks()` 3. (optional) text-node search by `fallbackHref` — last resort when the popup knows the href but the cursor sits at a gap

The returned range walks the parent block grouping consecutive text nodes that share the same href, and returns whichever range contains the cursor.

declare function findHyperlinkRangeAt(state: EditorState, fallbackHref?: string): {
    mark: Mark;
    start: number;
    end: number;
} | null;

Find the next tracked change after the given position.

declare function findNextChange(state: EditorState, startPos: number): ChangeRange | null;

Find the previous tracked change before the given position.

declare function findPreviousChange(state: EditorState, startPos: number): ChangeRange | null;
declare function getHyperlinkAttrs(state: EditorState): {
    href: string;
    tooltip?: string;
} | null;
declare function getListInfo(state: EditorState): {
    numId: number;
    ilvl: number;
} | null;

Get the current value of a mark attribute

declare function getMarkAttr(state: EditorState, markType: MarkType, attr: string): unknown | null;
declare function getParagraphAlignment(state: EditorState): ParagraphAlignment | null;
declare function getParagraphBidi(state: EditorState): boolean;
declare function getSelectedText(state: EditorState): string;
declare function getSplitCellDialogConfig(state: EditorState): SplitCellDialogConfig | null;
declare function getStyleId(state: EditorState): string | null;
declare function getTableContext(state: EditorState): TableContextInfo;
declare function increaseIndent(amount?: number): Command;
declare function insertTable(rows: number, cols: number): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;
declare function isHyperlinkActive(state: EditorState): boolean;
declare function isInList(state: EditorState): boolean;
declare function isInTableCell(state: EditorState): boolean;

Check if a mark is active in the current selection

declare function isMarkActive(state: EditorState, markType: MarkType, attrs?: Record<string, unknown>): boolean;
declare function mergeCells(state: EditorState, dispatch?: (tr: Transaction) => void): boolean;

Reject all tracked changes in the document.

declare function rejectAllChanges(): Command;

Reject a tracked change at the given range. - Insertion: remove mark AND text - Deletion: remove mark, keep text

declare function rejectChange(from: number, to: number): Command;

Remove a comment mark by ID from the entire document.

declare function removeCommentMark(commentId: number): Command;
declare function removeTableBorders(state: EditorState, dispatch?: (tr: Transaction) => void): boolean;
declare function removeTabStop(position: number): Command;
declare function selectColumn(state: EditorState, dispatch?: (tr: Transaction) => void): boolean;
declare function selectRow(state: EditorState, dispatch?: (tr: Transaction) => void): boolean;
declare function selectTable(state: EditorState, dispatch?: (tr: Transaction) => void): boolean;

Paragraph Formatting Commands — thin re-exports from extension system

Alignment, line spacing, indentation, lists, paragraph styles. All implementations live in extensions/; this file re-exports for backward compatibility.

declare function setAlignment(alignment: ParagraphAlignment): Command;
declare function setAllTableBorders(state: EditorState, dispatch?: (tr: Transaction) => void, borderSpec?: {
    style: string;
    size: number;
    color: {
        rgb: string;
    };
}): boolean;
declare function setCellBorder(side: 'top' | 'bottom' | 'left' | 'right' | 'all', spec: {
    style: string;
    size?: number;
    color?: {
        rgb: string;
    };
} | null, clearOthers?: boolean): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;
declare function setCellFillColor(color: string | null): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;
declare function setCellMargins(margins: {
    top?: number;
    bottom?: number;
    left?: number;
    right?: number;
}): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;
declare function setCellTextDirection(direction: string | null): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;
declare function setCellVerticalAlign(align: 'top' | 'center' | 'bottom'): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;
declare function setFontFamily(fontName: string): Command;
declare function setFontSize(size: number): Command;
declare function setHighlight(color: string): Command;

Change a floating image's wrap layout. `pos` is the PM document position of the image node; `target` is either an OOXML wrap type (square / tight / topAndBottom / behind / inFront / inline) or a directional convenience choice (`squareLeft` / `squareRight`).

`opts.initialPositionEmu` is used when promoting an inline image to an anchor — the caller measures the image's current rendered offset relative to the column origin in EMUs and passes it through, so the new float lands exactly where the inline glyph used to sit (matches Word's behavior).

declare function setImageWrapType(pos: number, target: ImageLayoutTarget, opts?: SetImageWrapTypeOptions): Command;
declare function setIndentFirstLine(twips: number, hanging?: boolean): Command;
declare function setIndentLeft(twips: number): Command;
declare function setIndentRight(twips: number): Command;
declare function setInsideTableBorders(state: EditorState, dispatch?: (tr: Transaction) => void, borderSpec?: {
    style: string;
    size: number;
    color: {
        rgb: string;
    };
}): boolean;
declare function setLineSpacing(value: number, rule?: LineSpacingRule): Command;
declare function setOutsideTableBorders(state: EditorState, dispatch?: (tr: Transaction) => void, borderSpec?: {
    style: string;
    size: number;
    color: {
        rgb: string;
    };
}): boolean;
declare function setRowHeight(height: number | null, rule?: 'auto' | 'atLeast' | 'exact'): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;
declare function setSpaceAfter(twips: number): Command;
declare function setSpaceBefore(twips: number): Command;
declare function setTableBorderColor(color: string): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;
declare function setTableBorders(preset: BorderPreset, borderSpec?: {
    style: string;
    size: number;
    color: {
        rgb: string;
    };
}): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;
declare function setTableBorderWidth(size: number): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;
declare function setTableProperties(props: {
    width?: number | null;
    widthType?: string | null;
    justification?: 'left' | 'center' | 'right' | null;
}): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;
declare function setTextColor(attrs: TextColorAttrs): Command;
declare function setUnderlineStyle(style: string, color?: TextColorAttrs): Command;
declare function splitActiveTableCell(state: EditorState, dispatch: ((tr: Transaction) => void) | undefined, rows: number, cols: number, 
targetRow?: number, targetCol?: number): boolean;
declare function splitCell(state: EditorState, dispatch?: (tr: Transaction) => void): boolean;
declare function toggleHeaderRow(): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;
declare function toggleNoWrap(): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;

Interfaces(4)

interface ResolvedStyleAttrs
MemberTypeSummary
paragraphFormatting?ParagraphFormatting
runFormatting?TextFormatting

Optional context for `setImageWrapType` transitions:

- `initialPositionEmu`: when promoting an inline image to an anchor, the caller passes the inline image's current rendered position relative to the column origin in EMUs. The command stores this as the anchor's `wp:positionH` / `wp:positionV` so Word renders the new float exactly where the inline image used to sit (Word's own behavior).

interface SetImageWrapTypeOptions
MemberTypeSummary
initialPositionEmu?{ horizontalEmu: number; verticalEmu: number; }

ProseMirror table cell splitting — dialog-backed split with explicit row/column input.

Uses the shared split algorithm from utils/tableSplitAlgorithm.ts for the core layout computation, then maps the result back into ProseMirror transactions.

interface SplitCellDialogConfig
MemberTypeSummary
capturedCellColnumberCaptured column index of the target cell at dialog-open time
capturedCellRownumberCaptured row index of the target cell at dialog-open time
initialColsnumber
initialRowsnumber
minColsnumber
minRowsnumber

Table selection context + navigation helpers.

`getTableContext` walks the selection up from `$from` and reports which table / row / cell the cursor is in, plus the table's row/column counts, whether a multi-cell selection is active, and the current cell's border + fill colors (so the toolbar's color pickers can show the live values).

`goToNextCell` / `goToPrevCell` are tab-stop-style cell navigation commands registered by the plugin extension.

interface TableContextInfo
MemberTypeSummary
canSplitCell?boolean
cellBackgroundColor?stringCurrent cell's background/fill color (RGB hex without #), if any
cellBorderColor?ColorValueCurrent cell's dominant border color, if any
columnCount?number
columnIndex?number
hasMultiCellSelection?boolean
isInTableboolean
rowCount?number
rowIndex?number
table?Node
tablePos?number

Type aliases(3)

Anchored wrap-type targets — the OOXML wrap types except `inline`.

type AnchorWrapType = Exclude<WrapType, 'inline'>;

Cell-border commands. Each command applies a preset / individual side / color / width to the cells targeted by the current selection (single cursor cell or active `CellSelection`).

All four commands use the shared `buildTableGrid` lookup to find each cell's neighbours in the grid, then sync the matching edge on the adjacent cell — Google-Docs style edge-symmetric border editing.

Schema-free: only attribute updates via `tr.setNodeMarkup`.

type BorderPreset = 'all' | 'outside' | 'inside' | 'none';

User-facing layout choices that mirror Word's Wrap Text menu. These are directional shortcuts that fold (`wrapType`, `cssFloat`) into a single picker option:

- `squareLeft` — image floats left, text wraps on the right - `squareRight` — image floats right, text wraps on the left - `inline` — image flows in the line as a glyph - the other targets are 1:1 with their OOXML wrap types

`setImageWrapType` accepts both raw OOXML targets (square / tight / through / topAndBottom / behind / inFront / inline) and the directional convenience targets.

type ImageLayoutTarget = AnchorWrapType | 'squareLeft' | 'squareRight' | 'inline';

Variables(29)

alignCenter: Command
alignJustify: Command
alignLeft: Command
alignRight: Command
clearFontFamily: Command
clearFontSize: Command

Clear all text formatting (remove all marks)

clearFormatting: Command
clearHighlight: Command
clearStyle: Command
clearTextColor: Command
decreaseListLevel: Command
doubleSpacing: Command
generateTOC: Command
increaseListLevel: Command

Insert a page break at the current cursor position. Always ensures a paragraph follows the page break and places the cursor there.

insertPageBreak: Command
oneAndHalfSpacing: Command
removeList: Command
setLtr: Command
setRtl: Command
singleSpacing: Command
toggleBold: Command
toggleBulletList: Command
toggleItalic: Command
toggleNumberedList: Command
toggleStrike: Command
toggleSubscript: Command
toggleSuperscript: Command
toggleUnderline: Command