@eigenpal/docx-editor-react

v1.8.3 · 6 published subpaths with full TypeScript signatures and JSDoc.

Subpaths

Package root

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

Functions (3)

LocaleProviderfunctionSource ↗

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

renderAsyncfunctionSource ↗

Render a DOCX editor into a container element.

declare function renderAsync(input: DocxInput, container: HTMLElement, options?: RenderAsyncOptions): Promise<DocxEditorHandle>;

useTranslationfunctionSource ↗

declare function useTranslation(): {
    t: TFunction;
};

Interfaces (4)

DocxEditorHandleinterfaceSource ↗

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

interface DocxEditorHandle extends EditorHandle
MemberTypeSummary
scrollToParaId(paraId: string, options?: ScrollToParaIdOptions) => 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%).

DocxEditorPropsinterfaceSource ↗

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
colorMode?'light' | 'dark' | 'system'Color theme mode for UI styling. `'system'` follows the OS preference.
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`.
commentsSidebarOpen?booleanControlled comments-sidebar visibility; source of truth when set. Pair with `onCommentsSidebarOpenChange`; omit for the default self-managed behavior.
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.
fonts?ReadonlyArray<FontDefinition>Custom font faces to register with the browser before the editor measures text. Each entry injects an `@font-face` rule. Pass a URL (woff2/woff/ ttf/otf), an ArrayBuffer, or omit `src` to load by name from Google Fonts. Multiple entries can share `family` to register different weights/styles.
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).
onCommentsSidebarOpenChange?(open: boolean) => voidFires with the next open state whenever the editor wants to show or hide the comments sidebar. Fires in both controlled and uncontrolled modes.
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
onOpen?(file: File) => void | Promise<void>Callback when a DOCX file is selected through `File > Open` or Cmd/Ctrl+O. Pass it to route the picked file through your own import pipeline. Omit it to keep the built-in local document load behavior.
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')
showFileOpen?booleanWhether to show `File > Open` and enable Cmd/Ctrl+O (default: true). Set false when you provide your own open action elsewhere.
showHelpMenu?booleanWhether to show the Help menu in the menu bar (default: true)
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 | nullDocument theme schema object
toolbarExtra?ReactNodeCustom toolbar actions
watermarkPresets?readonly string[]Text-watermark presets shown in the watermark dialog's preset dropdown. Omit to use the built-in MS Word phrases (`DEFAULT_WATERMARK_PRESETS`: CONFIDENTIAL, DRAFT, DO NOT COPY, SAMPLE, URGENT, ASAP). Pass an empty array to hide the preset dropdown and require custom text.

DocxEditorRefinterfaceSource ↗

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.
getContentControls(filter?: ContentControlFilter) => PMContentControl[]List block-level content controls (SDTs) in the live document, optionally filtered by `tag`/`alias`/`id`/`type`. Each result includes the control's text and PM position. Anchors for templates and document automation.
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
highlightRange(from: number, to: number) => voidSelect the ProseMirror position range `[from, to]` so the selection overlay highlights it, and scroll its start into view. The selection persists until it next changes (there is no auto-clearing flash). No-op for a malformed range or a `from` past the document end; `to` is clamped to the document size.
insertBreak(options: { paraId: string; type: 'page' | 'sectionNextPage' | 'sectionContinuous'; }) => booleanInsert a page or section break after the paragraph identified by `paraId`. `'page'` adds a page break; `'sectionNextPage'` / `'sectionContinuous'` start a new section on a new page / the same page. Direct edit, not a tracked change. Returns false if paraId is unknown.
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.
removeContentControl(filter: ContentControlFilter, options?: { force?: boolean; keepContent?: boolean; }) => booleanRemove the first control matching `filter`. With `{ keepContent: true }` the inner blocks are unwrapped in place. Returns false if no match. Throws if the control is deletion-locked unless `{ force: true }`.
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.
scrollToChangeId(revisionId: number) => booleanScroll the paginated view to the tracked change with the given Word revision `w:id` and select its range so the selection overlay highlights it. Resolves the id against the live tracked-change marks at call time (matching coalesced revisions the way the changes sidebar does).
scrollToCommentId(commentId: number) => booleanScroll the paginated view to the comment with the given id and select its anchored range so the selection overlay highlights it. Resolves the id against the live comment marks at call time.
scrollToContentControl(filter: ContentControlFilter) => booleanScroll the first content control matching `filter` into view. Returns false if none.
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, options?: ScrollToParaIdOptions) => booleanScroll the paginated view to the paragraph with the given Word `w14:paraId`. Pass `options.highlight` to briefly flash it in a custom color.
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.
setContentControlContent(filter: ContentControlFilter, text: string, options?: { force?: boolean; }) => booleanReplace the content of the first control matching `filter` with `text` (newlines become paragraphs). Returns false if no match. Throws if the control is content-locked unless `{ force: true }`.
setContentControlValue(filter: ContentControlFilter, value: ContentControlValue, options?: { force?: boolean; }) => booleanSet a typed value on the first control matching `filter`: a dropdown selection (`{ kind: 'dropdown', value }`), checkbox (`{ kind: 'checkbox', checked }`), or date (`{ kind: 'date', date }`). Updates the visible content and structured state. Returns false if no match; throws if content-locked (unless `force`) or the value doesn't fit the control type.
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

LocaleProviderPropsinterfaceSource ↗

interface LocaleProviderProps
MemberTypeSummary
childrenReactNode
i18n?Translations

Type aliases (2)

EditorModetypeSource ↗

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';

RenderAsyncOptionstypeSource ↗

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)

DocxEditorconstSource ↗

DocxEditor - Complete DOCX editor component

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

VERSIONconstSource ↗

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"

On this page