New

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

API Referencev1.0.2

@eigenpal/docx-editor-react

Curated root entry for the documented React editor API. Advanced surfaces stay public through explicit subpaths: - `@eigenpal/docx-editor-react/ui` - `@eigenpal/docx-editor-react/dialogs` - `@eigenpal/docx-editor-react/hooks` - `@eigenpal/docx-editor-react/plugin-api`

Framework-agnostic document utilities live in `@eigenpal/docx-editor-core`. Agent/MCP surfaces live in `@eigenpal/docx-editor-agents`.

Functions(3)

declare function LocaleProvider(input: LocaleProviderProps): react_jsx_runtime.JSX.Element;

Render a DOCX editor into a container element.

declare function renderAsync(input: DocxInput, container: HTMLElement, options?: RenderAsyncOptions): Promise<DocxEditorHandle>;
declare function useTranslation(): {
    t: TFunction;
};

Interfaces(4)

React-specific handle that extends the framework-agnostic EditorHandle with zoom control.

interface DocxEditorHandle extends EditorHandle
MemberTypeSummary
scrollToParaId(paraId: string) => booleanScroll to a body paragraph by Word `w14:paraId`.
scrollToPosition(pmPos: number) => voidScroll to a raw ProseMirror document position.
setZoom(zoom: number) => voidSet zoom level (1.0 = 100%).

DocxEditor props

interface DocxEditorProps
MemberTypeSummary
agentPanel?AgentPanelOptionsMount a controllable agent panel on the right side of the editor. The panel is the chrome (header, close button, drag-resize); the consumer supplies whatever content goes inside via `render` — typically a chat UI from `@ai-sdk/react`'s `useChat`, `assistant-ui`, or any other framework. We do not ship message bubbles, a composer, or a chat engine.
author?stringAuthor name used for comments and track changes
className?stringAdditional CSS class name
comments?Comment[]Controlled comments array. When provided, the editor reads comment thread metadata (text, author, replies, resolved status) from this prop instead of internal state, and emits every change through `onCommentsChange`.
disableFindReplaceShortcuts?booleanWhen true, the editor does not intercept Cmd/Ctrl+F or Cmd/Ctrl+H. This lets the browser or host app handle native find/history shortcuts.
document?Document | nullPre-parsed document (alternative to documentBuffer)
documentBuffer?DocxInput | nullDocument data — ArrayBuffer, Uint8Array, Blob, or File
documentName?stringDocument name shown in the title bar
documentNameEditable?booleanWhether the document name is editable (default: true)
externalContent?booleanWhen true, the editor treats the `document` prop as a schema seed only and does not load it into ProseMirror on mount. Content is expected to come from external sources — typically `externalPlugins` such as `ySyncPlugin` from `y-prosemirror`, but also any code that dispatches transactions directly.
externalPlugins?prosemirror_state.Plugin[]External ProseMirror plugins (from PluginHost)
fontFamilies?ReadonlyArray<string | FontOption>Custom list of fonts shown in the toolbar's font-family dropdown. Strings render in the "Other" group; pass `FontOption[]` for category grouping and CSS fallback chains. Omit to use the built-in 12-font default. An empty array renders an empty (but enabled) dropdown.
i18n?TranslationsTranslation overrides. Import a locale JSON file and pass it directly.
initialZoom?numberInitial zoom level (default: 1.0)
loadingIndicator?ReactNodeLoading indicator
marginGuideColor?stringColor for margin guides (default: '#c0c0c0')
mode?EditorModeEditor mode: 'editing' (direct edits), 'suggesting' (track changes), or 'viewing' (read-only). Default: 'editing'
onChange?(document: Document) => voidCallback when document changes
onCommentAdd?(comment: Comment) => voidCallback when a comment is added via the UI
onCommentDelete?(comment: Comment) => voidCallback when a comment is deleted via the UI
onCommentReply?(reply: Comment, parent: Comment) => voidCallback when a reply is added to a comment via the UI
onCommentResolve?(comment: Comment) => voidCallback when a comment is resolved via the UI
onCommentsChange?(comments: Comment[]) => voidFires whenever the comments array changes (controlled mode).
onCopy?() => voidCallback when content is copied
onCut?() => voidCallback when content is cut
onDocumentNameChange?(name: string) => voidCallback when document name changes
onEditorViewReady?(view: prosemirror_view.EditorView) => voidCallback when editor view is ready (for PluginHost)
onError?(error: Error) => voidCallback on error
onFontsLoaded?() => voidCallback when fonts are loaded
onModeChange?(mode: EditorMode) => voidCallback when the editing mode changes
onPaste?() => voidCallback when content is pasted
onPrint?() => voidCallback when print is triggered. Pass it to enable the `File > Print` menu entry; omit to hide. The imperative `ref.current.print()` also invokes this callback.
onRenderedDomContextReady?(context: RenderedDomContext) => voidCallback when rendered DOM context is ready (for plugin overlays). Used by PluginHost to get access to the rendered page DOM for positioning.
onSave?(buffer: ArrayBuffer) => voidCallback when document is saved
onSelectionChange?(state: SelectionState | null) => voidCallback when selection changes
placeholder?ReactNodePlaceholder when no document
pluginOverlays?ReactNodePlugin overlays to render inside the editor viewport. Passed from PluginHost to render plugin-specific overlays.
pluginRenderedDomContext?RenderedDomContext | nullRendered DOM context from PluginHost (for sidebar position resolution).
pluginSidebarItems?ReactSidebarItem[]Sidebar items from plugins (passed from PluginHost).
printOptions?PrintOptionsPrint options for print preview
readOnly?booleanWhether the editor is read-only. When true, hides toolbar and rulers
renderTitleBarRight?() => ReactNodeCustom right-side actions for the title bar
rulerUnit?'inch' | 'cm'Unit for ruler display (default: 'inch')
showMarginGuides?booleanWhether to show page margin guides/boundaries (default: false)
showOutline?booleanWhether to show the document outline sidebar (default: false)
showOutlineButton?booleanWhether to show the floating outline toggle button (default: true)
showRuler?booleanWhether to show horizontal ruler (default: false)
showToolbar?booleanWhether to show toolbar (default: true)
showZoomControl?booleanWhether to show zoom control (default: true)
style?CSSPropertiesAdditional inline styles
theme?Theme | nullTheme for styling
toolbarExtra?ReactNodeCustom toolbar actions

DocxEditor ref interface

interface DocxEditorRef
MemberTypeSummary
addComment(options: { paraId: string; text: string; author: string; search?: string; }) => number | nullAdd a comment programmatically. Anchored by Word `w14:paraId` so it survives unrelated edits. Returns the comment ID, or null if the paraId is unknown or the search text isn't found / is ambiguous.
applyFormatting(options: { paraId: string; search?: string; marks: { bold?: boolean; italic?: boolean; underline?: boolean | { style?: string; }; strike?: boolean; color?: { rgb?: string; themeColor?: string; }; highlight?: string; fontSize?: number; fontFamily?: { ascii?: string; hAnsi?: string; }; }; }) => booleanApply character formatting (bold / italic / color / size / font / etc.) to a paragraph or to a unique phrase within it. This is a direct edit, not a tracked change. Returns false on missing paraId or ambiguous search.
findInDocument(query: string, options?: { caseSensitive?: boolean; limit?: number; }) => Array<{ paraId: string; match: string; before: string; after: string; }>Locate every paragraph containing `query` (case-insensitive substring). Returns a stable handle (paraId + the matched phrase) the agent can pass back to `addComment` / `proposeChange`.
focus() => voidFocus the editor
getAgent() => DocumentAgent | nullGet the DocumentAgent for programmatic access
getComments() => Comment[]Get all comments.
getCurrentPage() => numberGet current page number
getDocument() => Document | nullGet the current document
getEditorRef() => PagedEditorRef | nullGet the editor ref
getPageContent(pageNumber: number) => { pageNumber: number; text: string; paragraphs: Array<{ paraId: string; text: string; styleId?: string; }>; } | nullRead the contents of a single page. 1-indexed; returns null if the page does not exist. Each paragraph is returned with its stable paraId so the agent can comment on or modify it without an extra round-trip.
getSelectionInfo() => { paraId: string | null; selectedText: string; paragraphText: string; before: string; after: string; } | nullRead the user's current cursor / selection — what's highlighted right now.
getTotalPages() => numberGet total page count
getZoom() => numberGet current zoom level
loadDocument(doc: Document) => voidLoad a pre-parsed document programmatically
loadDocumentBuffer(buffer: DocxInput) => Promise<void>Load a DOCX buffer programmatically (ArrayBuffer, Uint8Array, Blob, or File)
onContentChange(listener: (document: Document) => void) => () => voidSubscribe to document changes. Fires after every committed edit. Returns unsubscribe.
onSelectionChange(listener: (selection: SelectionState | null) => void) => () => voidSubscribe to selection changes (cursor moves / selection changes). Returns unsubscribe.
openPrintPreview() => voidOpen print preview
print() => voidPrint the document directly
proposeChange(options: { paraId: string; search: string; replaceWith: string; author: string; }) => booleanSuggest a tracked change. Pass `replaceWith: ''` to delete the matched text; pass `search: ''` to insert at paragraph end. Returns false on missing paraId, missing/ambiguous search, or attempt to layer on an existing tracked change.
replyToComment(commentId: number, text: string, author: string) => number | nullReply to an existing comment. Returns the reply comment ID.
resolveComment(commentId: number) => voidResolve (mark as done) a comment.
save(options?: { selective?: boolean; }) => Promise<ArrayBuffer | null>Save the document to buffer. Pass selective: false to force full repack.
scrollToPage(pageNumber: number) => voidScroll the paginated view so the given page is in view. Page numbers are 1-indexed (matches `getCurrentPage` / `getTotalPages`). No-op for out-of-range or non-integer values.
scrollToParaId(paraId: string) => booleanScroll the paginated view to the paragraph with the given Word `w14:paraId`.
scrollToPosition(pmPos: number) => voidScroll the paginated view to a specific ProseMirror document position. Use this when you have a raw PM offset; for Word `w14:paraId` use `scrollToParaId` instead.
setParagraphStyle(options: { paraId: string; styleId: string; }) => booleanApply a paragraph style by styleId (e.g. `'Heading1'`, `'Quote'`). Direct edit, not a tracked change. Returns false if paraId is unknown.
setZoom(zoom: number) => voidSet zoom level
interface LocaleProviderProps
MemberTypeSummary
childrenReactNode
i18n?Translations

Type aliases(2)

EditorMode union + the catalog the editing-mode dropdown renders. Lives next to DocxEditor.tsx so the dropdown component and the parent forwardRef body share one source of truth.

type EditorMode = 'editing' | 'suggesting' | 'viewing';

Options for [renderAsync](renderAsync). A subset of DocxEditorProps minus `documentBuffer` / `document` (passed as the first argument instead).

type RenderAsyncOptions = Omit<DocxEditorProps, 'documentBuffer' | 'document'>;

Variables(2)

DocxEditor - Complete DOCX editor component

DocxEditor: React.ForwardRefExoticComponent<DocxEditorProps & React.RefAttributes<DocxEditorRef>>

eigenpal/docx-editor-react

Curated root entry for the documented React editor API. Advanced surfaces stay public through explicit subpaths: - `@eigenpal/docx-editor-react/ui` - `@eigenpal/docx-editor-react/dialogs` - `@eigenpal/docx-editor-react/hooks` - `@eigenpal/docx-editor-react/plugin-api`

Framework-agnostic document utilities live in `@eigenpal/docx-editor-core`. Agent/MCP surfaces live in `@eigenpal/docx-editor-agents`.

VERSION = "0.0.2"