@eigenpal/docx-editor-core/prosemirror/commands
ProseMirror Commands
Commands for formatting text and paragraphs.
Functions(77)
acceptAllChanges
Accept all tracked changes in the document.
declare function acceptAllChanges(): Command;acceptChange
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;addColumnLeft
declare function addColumnLeft(state: EditorState, dispatch?: (tr: Transaction) => void): boolean;addColumnRight
declare function addColumnRight(state: EditorState, dispatch?: (tr: Transaction) => void): boolean;addCommentMark
Add a comment mark to the current selection.
declare function addCommentMark(commentId: number): Command;addRowAbove
declare function addRowAbove(state: EditorState, dispatch?: (tr: Transaction) => void): boolean;addRowBelow
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;applyTableStyle
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;autoFitContents
declare function autoFitContents(): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;createRemoveMarkCommand
Create a command that removes a mark from the selection
declare function createRemoveMarkCommand(markType: MarkType): Command;createSetMarkCommand
Create a command that sets a mark on the selection
declare function createSetMarkCommand(markType: MarkType, attrs?: Record<string, unknown>): Command;decreaseIndent
declare function decreaseIndent(amount?: number): Command;deleteColumn
declare function deleteColumn(state: EditorState, dispatch?: (tr: Transaction) => void): boolean;declare function deleteRow(state: EditorState, dispatch?: (tr: Transaction) => void): boolean;deleteTable
declare function deleteTable(state: EditorState, dispatch?: (tr: Transaction) => void): boolean;distributeColumns
declare function distributeColumns(): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;findHyperlinkRangeAt
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;findNextChange
Find the next tracked change after the given position.
declare function findNextChange(state: EditorState, startPos: number): ChangeRange | null;findPreviousChange
Find the previous tracked change before the given position.
declare function findPreviousChange(state: EditorState, startPos: number): ChangeRange | null;getHyperlinkAttrs
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;getParagraphAlignment
declare function getParagraphAlignment(state: EditorState): ParagraphAlignment | null;getParagraphBidi
declare function getParagraphBidi(state: EditorState): boolean;declare function getSelectedText(state: EditorState): string;getSplitCellDialogConfig
declare function getSplitCellDialogConfig(state: EditorState): SplitCellDialogConfig | null;declare function getStyleId(state: EditorState): string | null;getTableContext
declare function getTableContext(state: EditorState): TableContextInfo;increaseIndent
declare function increaseIndent(amount?: number): Command;insertHyperlink
declare function insertHyperlink(text: string, href: string, tooltip?: string): Command;insertTable
declare function insertTable(rows: number, cols: number): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;isHyperlinkActive
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;rejectAllChanges
Reject all tracked changes in the document.
declare function rejectAllChanges(): Command;rejectChange
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;removeCommentMark
Remove a comment mark by ID from the entire document.
declare function removeCommentMark(commentId: number): Command;removeTableBorders
declare function removeTableBorders(state: EditorState, dispatch?: (tr: Transaction) => void): boolean;removeTabStop
declare function removeTabStop(position: number): Command;selectColumn
declare function selectColumn(state: EditorState, dispatch?: (tr: Transaction) => void): boolean;declare function selectRow(state: EditorState, dispatch?: (tr: Transaction) => void): boolean;selectTable
declare function selectTable(state: EditorState, dispatch?: (tr: Transaction) => void): boolean;setAlignment
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;setAllTableBorders
declare function setAllTableBorders(state: EditorState, dispatch?: (tr: Transaction) => void, borderSpec?: {
style: string;
size: number;
color: {
rgb: string;
};
}): boolean;setCellBorder
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;setCellFillColor
declare function setCellFillColor(color: string | null): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;setCellMargins
declare function setCellMargins(margins: {
top?: number;
bottom?: number;
left?: number;
right?: number;
}): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;setCellTextDirection
declare function setCellTextDirection(direction: string | null): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;setCellVerticalAlign
declare function setCellVerticalAlign(align: 'top' | 'center' | 'bottom'): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;setFontFamily
declare function setFontFamily(fontName: string): Command;declare function setFontSize(size: number): Command;setHighlight
declare function setHighlight(color: string): Command;setHyperlink
declare function setHyperlink(href: string, tooltip?: string): Command;setImageWrapType
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;setIndentFirstLine
declare function setIndentFirstLine(twips: number, hanging?: boolean): Command;setIndentLeft
declare function setIndentLeft(twips: number): Command;setIndentRight
declare function setIndentRight(twips: number): Command;setInsideTableBorders
declare function setInsideTableBorders(state: EditorState, dispatch?: (tr: Transaction) => void, borderSpec?: {
style: string;
size: number;
color: {
rgb: string;
};
}): boolean;setLineSpacing
declare function setLineSpacing(value: number, rule?: LineSpacingRule): Command;setOutsideTableBorders
declare function setOutsideTableBorders(state: EditorState, dispatch?: (tr: Transaction) => void, borderSpec?: {
style: string;
size: number;
color: {
rgb: string;
};
}): boolean;setRowHeight
declare function setRowHeight(height: number | null, rule?: 'auto' | 'atLeast' | 'exact'): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;setSpaceAfter
declare function setSpaceAfter(twips: number): Command;setSpaceBefore
declare function setSpaceBefore(twips: number): Command;setTableBorderColor
declare function setTableBorderColor(color: string): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;setTableBorders
declare function setTableBorders(preset: BorderPreset, borderSpec?: {
style: string;
size: number;
color: {
rgb: string;
};
}): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;setTableBorderWidth
declare function setTableBorderWidth(size: number): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;setTableProperties
declare function setTableProperties(props: {
width?: number | null;
widthType?: string | null;
justification?: 'left' | 'center' | 'right' | null;
}): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;setTextColor
declare function setTextColor(attrs: TextColorAttrs): Command;setUnderlineStyle
declare function setUnderlineStyle(style: string, color?: TextColorAttrs): Command;splitActiveTableCell
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;toggleHeaderRow
declare function toggleHeaderRow(): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;toggleNoWrap
declare function toggleNoWrap(): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;Interfaces(4)
ResolvedStyleAttrs
interface ResolvedStyleAttrs| Member | Type | Summary |
|---|---|---|
| paragraphFormatting? | ParagraphFormatting | |
| runFormatting? | TextFormatting |
SetImageWrapTypeOptions
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| Member | Type | Summary |
|---|---|---|
| initialPositionEmu? | {
horizontalEmu: number;
verticalEmu: number;
} |
SplitCellDialogConfig
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| Member | Type | Summary |
|---|---|---|
| capturedCellCol | number | Captured column index of the target cell at dialog-open time |
| capturedCellRow | number | Captured row index of the target cell at dialog-open time |
| initialCols | number | |
| initialRows | number | |
| minCols | number | |
| minRows | number |
TableContextInfo
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| Member | Type | Summary |
|---|---|---|
| canSplitCell? | boolean | |
| cellBackgroundColor? | string | Current cell's background/fill color (RGB hex without #), if any |
| cellBorderColor? | ColorValue | Current cell's dominant border color, if any |
| columnCount? | number | |
| columnIndex? | number | |
| hasMultiCellSelection? | boolean | |
| isInTable | boolean | |
| rowCount? | number | |
| rowIndex? | number | |
| table? | Node | |
| tablePos? | number |
Type aliases(3)
AnchorWrapType
Anchored wrap-type targets — the OOXML wrap types except `inline`.
type AnchorWrapType = Exclude<WrapType, 'inline'>;BorderPreset
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';ImageLayoutTarget
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
alignCenter: CommandalignJustify
alignJustify: CommandalignLeft
alignLeft: CommandalignRight
alignRight: CommandclearFontFamily
clearFontFamily: CommandclearFontSize
clearFontSize: CommandclearFormatting
Clear all text formatting (remove all marks)
clearFormatting: CommandclearHighlight
clearHighlight: CommandclearStyle
clearStyle: CommandclearTextColor
clearTextColor: CommanddecreaseListLevel
decreaseListLevel: CommanddoubleSpacing
doubleSpacing: CommandgenerateTOC
generateTOC: CommandincreaseListLevel
increaseListLevel: CommandinsertPageBreak
Insert a page break at the current cursor position. Always ensures a paragraph follows the page break and places the cursor there.
insertPageBreak: CommandoneAndHalfSpacing
oneAndHalfSpacing: CommandremoveHyperlink
removeHyperlink: CommandremoveList
removeList: CommandsetLtr: CommandsetRtl: CommandsingleSpacing
singleSpacing: CommandtoggleBold
toggleBold: CommandtoggleBulletList
toggleBulletList: CommandtoggleItalic
toggleItalic: CommandtoggleNumberedList
toggleNumberedList: CommandtoggleStrike
toggleStrike: CommandtoggleSubscript
toggleSubscript: CommandtoggleSuperscript
toggleSuperscript: CommandtoggleUnderline
toggleUnderline: Command