@heyirisai/docx-editor-react 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +139 -0
  3. package/dist/FindReplaceDialog-HM63BMXE.js +1 -0
  4. package/dist/FindReplaceDialog-KU5TEIBJ.mjs +1 -0
  5. package/dist/FootnotePropertiesDialog-TV2BGQDC.js +1 -0
  6. package/dist/FootnotePropertiesDialog-W3YHM4BV.mjs +1 -0
  7. package/dist/HyperlinkDialog-7MEQJIYP.js +1 -0
  8. package/dist/HyperlinkDialog-ZYH7ZHRF.mjs +1 -0
  9. package/dist/ImagePositionDialog-HEWYR6Q3.mjs +1 -0
  10. package/dist/ImagePositionDialog-LSCCQORZ.js +1 -0
  11. package/dist/ImagePropertiesDialog-RAB47C6M.mjs +1 -0
  12. package/dist/ImagePropertiesDialog-Z4M6XKFG.js +1 -0
  13. package/dist/KeyboardShortcutsDialog-B-h3NAat.d.mts +415 -0
  14. package/dist/KeyboardShortcutsDialog-B-h3NAat.d.ts +415 -0
  15. package/dist/PageSetupDialog-AIGIXO3E.mjs +1 -0
  16. package/dist/PageSetupDialog-LWYOYKEU.js +1 -0
  17. package/dist/SplitCellDialog-45W7SDPY.js +1 -0
  18. package/dist/SplitCellDialog-IFBKYCD6.mjs +1 -0
  19. package/dist/TablePropertiesDialog-TMLKGOOW.mjs +1 -0
  20. package/dist/TablePropertiesDialog-VCDCPM3R.js +1 -0
  21. package/dist/WatermarkDialog-KRL7WMIS.mjs +1 -0
  22. package/dist/WatermarkDialog-XGLAH3TK.js +1 -0
  23. package/dist/chunk-4Y4JFAPY.mjs +2 -0
  24. package/dist/chunk-72OSVJPF.mjs +2 -0
  25. package/dist/chunk-74OM4KEH.js +2 -0
  26. package/dist/chunk-BJ5RZW6Y.js +1 -0
  27. package/dist/chunk-BMBP5UFA.mjs +1 -0
  28. package/dist/chunk-BWGNQQOL.mjs +1 -0
  29. package/dist/chunk-BZO4G5M6.js +1 -0
  30. package/dist/chunk-FIXL5PLO.js +2 -0
  31. package/dist/chunk-GM2S2WMT.mjs +1 -0
  32. package/dist/chunk-GNIO6SOS.js +1 -0
  33. package/dist/chunk-GWXEFL3H.js +1 -0
  34. package/dist/chunk-IVFYCMAM.mjs +1 -0
  35. package/dist/chunk-J72K2BOS.mjs +2 -0
  36. package/dist/chunk-L4MDZW2J.js +1 -0
  37. package/dist/chunk-LMMQD3OQ.js +2 -0
  38. package/dist/chunk-NIBCC7WQ.js +1 -0
  39. package/dist/chunk-O6M2HAIZ.mjs +1 -0
  40. package/dist/chunk-OCA7BO3G.mjs +1 -0
  41. package/dist/chunk-OHNO4NRQ.mjs +1 -0
  42. package/dist/chunk-P5ZOUQIK.mjs +1 -0
  43. package/dist/chunk-PSBO3UDN.js +1 -0
  44. package/dist/chunk-QD7BVJV3.js +2 -0
  45. package/dist/chunk-SSLYGYTD.js +1 -0
  46. package/dist/chunk-YY52FSUR.js +1 -0
  47. package/dist/chunk-Z3X4KBNE.mjs +2 -0
  48. package/dist/chunk-ZFZJRL2R.mjs +1 -0
  49. package/dist/dialogs.d.mts +40 -0
  50. package/dist/dialogs.d.ts +40 -0
  51. package/dist/dialogs.js +1 -0
  52. package/dist/dialogs.mjs +1 -0
  53. package/dist/hooks.d.mts +513 -0
  54. package/dist/hooks.d.ts +513 -0
  55. package/dist/hooks.js +1 -0
  56. package/dist/hooks.mjs +1 -0
  57. package/dist/index.d.mts +680 -0
  58. package/dist/index.d.ts +680 -0
  59. package/dist/index.js +31 -0
  60. package/dist/index.mjs +31 -0
  61. package/dist/plugin-api.d.mts +90 -0
  62. package/dist/plugin-api.d.ts +90 -0
  63. package/dist/plugin-api.js +246 -0
  64. package/dist/plugin-api.mjs +246 -0
  65. package/dist/styles.css +1 -0
  66. package/dist/styles.d.mts +13 -0
  67. package/dist/styles.d.ts +13 -0
  68. package/dist/styles.js +1 -0
  69. package/dist/styles.mjs +1 -0
  70. package/dist/types-D35gNE-_.d.mts +106 -0
  71. package/dist/types-D35gNE-_.d.ts +106 -0
  72. package/dist/ui.d.mts +1692 -0
  73. package/dist/ui.d.ts +1692 -0
  74. package/dist/ui.js +90 -0
  75. package/dist/ui.mjs +90 -0
  76. package/dist/useFindReplace-Bc2ubEeV.d.mts +219 -0
  77. package/dist/useFindReplace-Bc2ubEeV.d.ts +219 -0
  78. package/package.json +137 -0
@@ -0,0 +1,680 @@
1
+ /**
2
+ * @heyirisai/docx-editor-react
3
+ *
4
+ * Curated root entry for the documented React editor API. Advanced surfaces
5
+ * stay public through explicit subpaths:
6
+ * - `@heyirisai/docx-editor-react/ui`
7
+ * - `@heyirisai/docx-editor-react/dialogs`
8
+ * - `@heyirisai/docx-editor-react/hooks`
9
+ * - `@heyirisai/docx-editor-react/plugin-api`
10
+ *
11
+ * Framework-agnostic document utilities live in `@heyirisai/docx-editor-core`.
12
+ * Agent/MCP surfaces live in `@heyirisai/docx-editor-agents`.
13
+ *
14
+ * @packageDocumentation
15
+ * @public
16
+ */
17
+ import * as React from 'react';
18
+ import { ReactNode, CSSProperties } from 'react';
19
+ import * as prosemirror_view from 'prosemirror-view';
20
+ import { EditorView } from 'prosemirror-view';
21
+ import * as prosemirror_state from 'prosemirror-state';
22
+ import { EditorState, Transaction } from 'prosemirror-state';
23
+ import { Document, HeaderFooter, Theme } from '@heyirisai/docx-editor-core/types/document';
24
+ import { FontOption } from '@heyirisai/docx-editor-core/utils/fontOptions';
25
+ import { R as ReactSidebarItem } from './types-D35gNE-_.js';
26
+ import { Comment } from '@heyirisai/docx-editor-core/types/content';
27
+ import { Translations, TFunction } from '@heyirisai/docx-editor-i18n';
28
+ import { PrintOptions, EditorHandle } from '@heyirisai/docx-editor-core';
29
+ export { CreateEmptyDocumentOptions, createDocumentWithText, createEmptyDocument } from '@heyirisai/docx-editor-core';
30
+ import { DocumentAgent, ContentControlFilter, ContentControlValue } from '@heyirisai/docx-editor-core/agent';
31
+ import { ScrollToParaIdOptions, DocxInput, FontDefinition } from '@heyirisai/docx-editor-core/utils';
32
+ import { SelectionState, PMContentControl } from '@heyirisai/docx-editor-core/prosemirror';
33
+ import { Layout } from '@heyirisai/docx-editor-core/layout-engine';
34
+ import { RenderedDomContext } from '@heyirisai/docx-editor-core/plugin-api';
35
+
36
+ /**
37
+ * Options for the agent panel mount on the right side of the editor.
38
+ *
39
+ * Three control patterns:
40
+ * - **Uncontrolled**: `agentPanel={{ render }}` — toolbar button + panel
41
+ * close button toggle the panel. Width persists to localStorage.
42
+ * - **Controlled**: `agentPanel={{ render, open, onOpenChange }}` — the
43
+ * consumer owns open state (e.g. tied to a global menu).
44
+ * - **Headless**: omit `agentPanel`, use the toolkit directly via
45
+ * `useDocxAgentTools` — render the panel anywhere you want.
46
+ */
47
+ interface AgentPanelOptions {
48
+ /** Render-prop returning the panel content. Called only when open. */
49
+ render: (ctx: {
50
+ close: () => void;
51
+ }) => ReactNode;
52
+ /** Controlled open state. Omit for uncontrolled. */
53
+ open?: boolean;
54
+ /** Fires when toolbar button or panel close button is clicked. */
55
+ onOpenChange?: (open: boolean) => void;
56
+ /** Show the toolbar toggle button. Default: true. */
57
+ showToolbarButton?: boolean;
58
+ /** Optional badge / dot on the toolbar button. */
59
+ toolbarBadge?: ReactNode;
60
+ /** Optional panel title. Default: t('agentPanel.defaultTitle'). */
61
+ title?: string;
62
+ /** Optional panel header icon. Default: sparkle. */
63
+ icon?: ReactNode;
64
+ /** Initial panel width in px (uncontrolled). Default: 360. */
65
+ defaultWidth?: number;
66
+ /** Min drag width. Default: 280. */
67
+ minWidth?: number;
68
+ /** Max drag width. Default: 600. */
69
+ maxWidth?: number;
70
+ }
71
+
72
+ interface PagedEditorRef {
73
+ /** Get the current document. */
74
+ getDocument(): Document | null;
75
+ /** Get the ProseMirror EditorState. */
76
+ getState(): EditorState | null;
77
+ /** Get the ProseMirror EditorView. */
78
+ getView(): EditorView | null;
79
+ /** Focus the editor. */
80
+ focus(): void;
81
+ /** Blur the editor. */
82
+ blur(): void;
83
+ /** Check if focused. */
84
+ isFocused(): boolean;
85
+ /** Dispatch a transaction. */
86
+ dispatch(tr: Transaction): void;
87
+ /** Undo. */
88
+ undo(): boolean;
89
+ /** Redo. */
90
+ redo(): boolean;
91
+ /** Set selection by PM position. */
92
+ setSelection(anchor: number, head?: number): void;
93
+ /** Get current layout. */
94
+ getLayout(): Layout | null;
95
+ /** Force re-layout. */
96
+ relayout(): void;
97
+ /** Scroll the visible pages to bring a PM position into view. */
98
+ scrollToPosition(pmPos: number): void;
99
+ /**
100
+ * Scroll to the paragraph identified by Word `w14:paraId` / PM `paraId`.
101
+ * Pass `options.highlight` to briefly flash rendered paragraph fragments.
102
+ * @returns whether a matching paragraph was found
103
+ */
104
+ scrollToParaId(paraId: string, options?: ScrollToParaIdOptions): boolean;
105
+ /**
106
+ * Scroll the paginated view so `pageNumber` (1-indexed) is in view.
107
+ * No-op if the layout isn't ready yet or pageNumber is out of range.
108
+ */
109
+ scrollToPage(pageNumber: number): void;
110
+ /**
111
+ * Scroll to the comment identified by `commentId` and select its range so
112
+ * the selection overlay highlights it. Resolves the id → PM range via the
113
+ * live comment marks; returns `false` (not a throw, not a silent no-op)
114
+ * when the id no longer resolves so the caller can surface a "location no
115
+ * longer exists" affordance.
116
+ */
117
+ scrollToCommentId(commentId: number): boolean;
118
+ /**
119
+ * Scroll to the tracked change identified by `revisionId` and select its
120
+ * range so the selection overlay highlights it. Resolves the id → PM range
121
+ * via the live tracked-change marks; returns `false` when the id no longer
122
+ * resolves (the change was accepted/rejected/deleted).
123
+ */
124
+ scrollToChangeId(revisionId: number): boolean;
125
+ /**
126
+ * Select the PM position range `[from, to]` so the selection overlay
127
+ * highlights it, and scroll its start into view. No-op for a malformed
128
+ * range or a `from` past the document end; `to` is clamped to the document
129
+ * size (raw caller positions, so out-of-range must not throw).
130
+ */
131
+ highlightRange(from: number, to: number): void;
132
+ /**
133
+ * Look up the persistent hidden HF PM EditorView for a given HeaderFooter
134
+ * instance. Returns null when none is mounted (no document, or `hf` is not
135
+ * present in `Document.package.headers/footers`). Phase 2 of the HF
136
+ * unification: the inline overlay uses this to replicate edits into the
137
+ * persistent PM so the painter — which reads from the persistent PM per
138
+ * phase 1 — re-renders live during typing. Phase 5 deletes the inline
139
+ * overlay's PM and this method's only remaining caller is the click /
140
+ * focus router (phase 3).
141
+ */
142
+ getHfPmView(hf: HeaderFooter): EditorView | null;
143
+ /** Get all active header/footer EditorViews mapped by rId. */
144
+ getHfPmViews(): Map<string, EditorView>;
145
+ }
146
+
147
+ /**
148
+ * EditorMode union + the catalog the editing-mode dropdown renders.
149
+ * Lives next to DocxEditor.tsx so the dropdown component and the parent
150
+ * forwardRef body share one source of truth.
151
+ */
152
+
153
+ type EditorMode = 'editing' | 'suggesting' | 'viewing';
154
+
155
+ /**
156
+ * DocxEditor props
157
+ */
158
+ interface DocxEditorProps {
159
+ /** Document data — ArrayBuffer, Uint8Array, Blob, or File */
160
+ documentBuffer?: DocxInput | null;
161
+ /** Pre-parsed document (alternative to documentBuffer) */
162
+ document?: Document | null;
163
+ /** Callback when document is saved */
164
+ onSave?: (buffer: ArrayBuffer) => void;
165
+ /**
166
+ * Callback when a DOCX file is selected through `File > Open` or Cmd/Ctrl+O.
167
+ * Pass it to route the picked file through your own import pipeline. Omit it
168
+ * to keep the built-in local document load behavior.
169
+ */
170
+ onOpen?: (file: File) => void | Promise<void>;
171
+ /** Author name used for comments and track changes */
172
+ author?: string;
173
+ /** Callback when document changes */
174
+ onChange?: (document: Document) => void;
175
+ /** Callback when selection changes */
176
+ onSelectionChange?: (state: SelectionState | null) => void;
177
+ /** Callback on error */
178
+ onError?: (error: Error) => void;
179
+ /** Callback when fonts are loaded */
180
+ onFontsLoaded?: () => void;
181
+ /** External ProseMirror plugins (from PluginHost) */
182
+ externalPlugins?: prosemirror_state.Plugin[];
183
+ /**
184
+ * When true, the editor treats the `document` prop as a schema seed only and
185
+ * does not load it into ProseMirror on mount. Content is expected to come from
186
+ * external sources — typically `externalPlugins` such as `ySyncPlugin` from
187
+ * `y-prosemirror`, but also any code that dispatches transactions directly.
188
+ *
189
+ * You must still pass a `document` prop (e.g., `createEmptyDocument()`) so the
190
+ * editor can build its schema and render the shell.
191
+ */
192
+ externalContent?: boolean;
193
+ /** Callback when editor view is ready (for PluginHost) */
194
+ onEditorViewReady?: (view: prosemirror_view.EditorView) => void;
195
+ /** Color theme mode for UI styling. `'system'` follows the OS preference. */
196
+ colorMode?: 'light' | 'dark' | 'system';
197
+ /** Document theme schema object */
198
+ theme?: Theme | null;
199
+ /** Whether to show toolbar (default: true) */
200
+ showToolbar?: boolean;
201
+ /**
202
+ * Whether to show `File > Open` and enable Cmd/Ctrl+O (default: true).
203
+ * Set false when you provide your own open action elsewhere.
204
+ */
205
+ showFileOpen?: boolean;
206
+ /** Whether to show the Help menu in the menu bar (default: true) */
207
+ showHelpMenu?: boolean;
208
+ /** Whether to show zoom control (default: true) */
209
+ showZoomControl?: boolean;
210
+ /** Whether to show page margin guides/boundaries (default: false) */
211
+ showMarginGuides?: boolean;
212
+ /** Color for margin guides (default: '#c0c0c0') */
213
+ marginGuideColor?: string;
214
+ /** Whether to show horizontal ruler (default: false) */
215
+ showRuler?: boolean;
216
+ /** Unit for ruler display (default: 'inch') */
217
+ rulerUnit?: 'inch' | 'cm';
218
+ /** Initial zoom level (default: 1.0) */
219
+ initialZoom?: number;
220
+ /** Whether the editor is read-only. When true, hides toolbar and rulers */
221
+ readOnly?: boolean;
222
+ /**
223
+ * When true, the editor does not intercept Cmd/Ctrl+F or Cmd/Ctrl+H.
224
+ * This lets the browser or host app handle native find/history shortcuts.
225
+ */
226
+ disableFindReplaceShortcuts?: boolean;
227
+ /** Custom toolbar actions */
228
+ toolbarExtra?: ReactNode;
229
+ /** Additional CSS class name */
230
+ className?: string;
231
+ /** Additional inline styles */
232
+ style?: CSSProperties;
233
+ /** Placeholder when no document */
234
+ placeholder?: ReactNode;
235
+ /** Loading indicator */
236
+ loadingIndicator?: ReactNode;
237
+ /** Whether to show the document outline sidebar (default: false) */
238
+ showOutline?: boolean;
239
+ /** Whether to show the floating outline toggle button (default: true) */
240
+ showOutlineButton?: boolean;
241
+ /**
242
+ * Custom list of fonts shown in the toolbar's font-family dropdown.
243
+ * Strings render in the "Other" group; pass `FontOption[]` for category
244
+ * grouping and CSS fallback chains. Omit to use the built-in 12-font
245
+ * default. An empty array renders an empty (but enabled) dropdown.
246
+ *
247
+ * Pass a stable reference (memoized or module-level) — inline arrays
248
+ * create a new identity per render and invalidate the picker's memo.
249
+ *
250
+ * @example fontFamilies={['Arial', 'Roboto']}
251
+ * @example fontFamilies={[{ name: 'Roboto', fontFamily: 'Roboto, sans-serif', category: 'sans-serif' }]}
252
+ */
253
+ fontFamilies?: ReadonlyArray<string | FontOption>;
254
+ /**
255
+ * Custom font faces to register with the browser before the editor measures
256
+ * text. Each entry injects an `@font-face` rule. Pass a URL (woff2/woff/
257
+ * ttf/otf), an ArrayBuffer, or omit `src` to load by name from Google Fonts.
258
+ * Multiple entries can share `family` to register different weights/styles.
259
+ *
260
+ * Pass a stable reference — inline arrays re-register faces on each render
261
+ * (the loader dedupes by `family|weight|style`, so it's harmless but wastes
262
+ * work).
263
+ *
264
+ * @example
265
+ * fonts={[
266
+ * { family: 'Custom Sans', src: '/fonts/CustomSans-Regular.woff2' },
267
+ * { family: 'Custom Sans', src: '/fonts/CustomSans-Bold.woff2', weight: 700 },
268
+ * ]}
269
+ */
270
+ fonts?: ReadonlyArray<FontDefinition>;
271
+ /**
272
+ * Text-watermark presets shown in the watermark dialog's preset dropdown.
273
+ * Omit to use the built-in MS Word phrases (`DEFAULT_WATERMARK_PRESETS`:
274
+ * CONFIDENTIAL, DRAFT, DO NOT COPY, SAMPLE, URGENT, ASAP). Pass an empty
275
+ * array to hide the preset dropdown and require custom text.
276
+ *
277
+ * @example watermarkPresets={['INTERNAL', 'PROPRIETARY', 'COPY']}
278
+ */
279
+ watermarkPresets?: readonly string[];
280
+ /** Print options for print preview */
281
+ printOptions?: PrintOptions;
282
+ /**
283
+ * Callback when print is triggered. Pass it to enable the `File > Print`
284
+ * menu entry; omit to hide. The imperative `ref.current.print()` also
285
+ * invokes this callback.
286
+ */
287
+ onPrint?: () => void;
288
+ /** Callback when content is copied */
289
+ onCopy?: () => void;
290
+ /** Callback when content is cut */
291
+ onCut?: () => void;
292
+ /** Callback when content is pasted */
293
+ onPaste?: () => void;
294
+ /** Editor mode: 'editing' (direct edits), 'suggesting' (track changes), or 'viewing' (read-only). Default: 'editing' */
295
+ mode?: EditorMode;
296
+ /** Callback when the editing mode changes */
297
+ onModeChange?: (mode: EditorMode) => void;
298
+ /** Callback when a comment is added via the UI */
299
+ onCommentAdd?: (comment: Comment) => void;
300
+ /** Callback when a comment is resolved via the UI */
301
+ onCommentResolve?: (comment: Comment) => void;
302
+ /** Callback when a comment is deleted via the UI */
303
+ onCommentDelete?: (comment: Comment) => void;
304
+ /** Callback when a reply is added to a comment via the UI */
305
+ onCommentReply?: (reply: Comment, parent: Comment) => void;
306
+ /**
307
+ * Controlled comments array. When provided, the editor reads comment thread
308
+ * metadata (text, author, replies, resolved status) from this prop instead
309
+ * of internal state, and emits every change through `onCommentsChange`.
310
+ *
311
+ * Use this with collaboration backends (Yjs, Liveblocks, Automerge, …) so
312
+ * comment threads sync across peers — the PM document only carries the
313
+ * range markers; thread metadata lives outside the doc and needs its own
314
+ * sync channel.
315
+ *
316
+ * If omitted, the editor falls back to internal state (current behavior).
317
+ * The granular `onCommentAdd`/`onCommentResolve`/`onCommentDelete`/
318
+ * `onCommentReply` callbacks fire in both modes.
319
+ */
320
+ comments?: Comment[];
321
+ /** Fires whenever the comments array changes (controlled mode). */
322
+ onCommentsChange?: (comments: Comment[]) => void;
323
+ /** Controlled comments-sidebar visibility; source of truth when set. Pair with `onCommentsSidebarOpenChange`; omit for the default self-managed behavior. */
324
+ commentsSidebarOpen?: boolean;
325
+ /** Fires with the next open state whenever the editor wants to show or hide the comments sidebar. Fires in both controlled and uncontrolled modes. */
326
+ onCommentsSidebarOpenChange?: (open: boolean) => void;
327
+ /**
328
+ * Callback when rendered DOM context is ready (for plugin overlays).
329
+ * Used by PluginHost to get access to the rendered page DOM for positioning.
330
+ */
331
+ onRenderedDomContextReady?: (context: RenderedDomContext) => void;
332
+ /**
333
+ * Plugin overlays to render inside the editor viewport.
334
+ * Passed from PluginHost to render plugin-specific overlays.
335
+ */
336
+ pluginOverlays?: ReactNode;
337
+ /** Sidebar items from plugins (passed from PluginHost). */
338
+ pluginSidebarItems?: ReactSidebarItem[];
339
+ /** Rendered DOM context from PluginHost (for sidebar position resolution). */
340
+ pluginRenderedDomContext?: RenderedDomContext | null;
341
+ /** Custom logo/icon for the title bar */
342
+ renderLogo?: () => ReactNode;
343
+ /** Document name shown in the title bar */
344
+ documentName?: string;
345
+ /** Callback when document name changes */
346
+ onDocumentNameChange?: (name: string) => void;
347
+ /** Whether the document name is editable (default: true) */
348
+ documentNameEditable?: boolean;
349
+ /** Custom right-side actions for the title bar */
350
+ renderTitleBarRight?: () => ReactNode;
351
+ /** Translation overrides. Import a locale JSON file and pass it directly. */
352
+ i18n?: Translations;
353
+ /**
354
+ * Mount a controllable agent panel on the right side of the editor. The
355
+ * panel is the chrome (header, close button, drag-resize); the consumer
356
+ * supplies whatever content goes inside via `render` — typically a chat
357
+ * UI from `@ai-sdk/react`'s `useChat`, `assistant-ui`, or any other
358
+ * framework. We do not ship message bubbles, a composer, or a chat engine.
359
+ *
360
+ * Three control patterns:
361
+ * - **Uncontrolled**: `agentPanel={{ render }}` — toolbar button + panel
362
+ * close button toggle the panel. Width persists to localStorage.
363
+ * - **Controlled**: `agentPanel={{ render, open, onOpenChange }}` — the
364
+ * consumer owns open state (e.g. tied to a global menu).
365
+ * - **Headless**: omit `agentPanel`, use the toolkit directly via
366
+ * `useDocxAgentTools` — render the panel anywhere you want.
367
+ */
368
+ agentPanel?: AgentPanelOptions;
369
+ }
370
+ /**
371
+ * DocxEditor ref interface
372
+ */
373
+ interface DocxEditorRef {
374
+ /** Get the DocumentAgent for programmatic access */
375
+ getAgent: () => DocumentAgent | null;
376
+ /** Get the current document */
377
+ getDocument: () => Document | null;
378
+ /** Get the editor ref */
379
+ getEditorRef: () => PagedEditorRef | null;
380
+ /** Save the document to buffer. Pass { selective: false } to force full repack. */
381
+ save: (options?: {
382
+ selective?: boolean;
383
+ }) => Promise<ArrayBuffer | null>;
384
+ /** Set zoom level */
385
+ setZoom: (zoom: number) => void;
386
+ /** Get current zoom level */
387
+ getZoom: () => number;
388
+ /** Focus the editor */
389
+ focus: () => void;
390
+ /** Get current page number */
391
+ getCurrentPage: () => number;
392
+ /** Get total page count */
393
+ getTotalPages: () => number;
394
+ /**
395
+ * Scroll the paginated view so the given page is in view.
396
+ * Page numbers are 1-indexed (matches `getCurrentPage` / `getTotalPages`).
397
+ * No-op for out-of-range or non-integer values.
398
+ * @example ref.current?.scrollToPage(2)
399
+ */
400
+ scrollToPage: (pageNumber: number) => void;
401
+ /**
402
+ * Scroll the paginated view to the paragraph with the given Word `w14:paraId`.
403
+ * Pass `options.highlight` to briefly flash it in a custom color.
404
+ * @returns whether a matching paragraph exists in the ProseMirror document
405
+ * @example ref.current?.scrollToParaId('1A2B3C4D', { highlight: { color: 'rgba(255, 235, 59, 0.55)' } })
406
+ */
407
+ scrollToParaId: (paraId: string, options?: ScrollToParaIdOptions) => boolean;
408
+ /**
409
+ * Scroll the paginated view to a specific ProseMirror document position.
410
+ * Use this when you have a raw PM offset; for Word `w14:paraId` use
411
+ * `scrollToParaId` instead.
412
+ * @example ref.current?.scrollToPosition(42)
413
+ */
414
+ scrollToPosition: (pmPos: number) => void;
415
+ /**
416
+ * Scroll the paginated view to the comment with the given id and select its
417
+ * anchored range so the selection overlay highlights it. Resolves the id
418
+ * against the live comment marks at call time.
419
+ * @returns `false` when the id no longer resolves (the comment was deleted
420
+ * or its anchored text removed between render and click), so the caller
421
+ * can surface a "location no longer exists" affordance rather than
422
+ * silently no-op'ing.
423
+ * @example ref.current?.scrollToCommentId(3)
424
+ */
425
+ scrollToCommentId: (commentId: number) => boolean;
426
+ /**
427
+ * Scroll the paginated view to the tracked change with the given Word
428
+ * revision `w:id` and select its range so the selection overlay highlights
429
+ * it. Resolves the id against the live tracked-change marks at call time
430
+ * (matching coalesced revisions the way the changes sidebar does).
431
+ * @returns `false` when the id no longer resolves (the change was
432
+ * accepted, rejected, or deleted between render and click).
433
+ * @example ref.current?.scrollToChangeId(42)
434
+ */
435
+ scrollToChangeId: (revisionId: number) => boolean;
436
+ /**
437
+ * Select the ProseMirror position range `[from, to]` so the selection
438
+ * overlay highlights it, and scroll its start into view. The selection
439
+ * persists until it next changes (there is no auto-clearing flash). No-op
440
+ * for a malformed range or a `from` past the document end; `to` is clamped
441
+ * to the document size.
442
+ * @example ref.current?.highlightRange(10, 24)
443
+ */
444
+ highlightRange: (from: number, to: number) => void;
445
+ /** Open print preview */
446
+ openPrintPreview: () => void;
447
+ /** Print the document directly */
448
+ print: () => void;
449
+ /** Load a pre-parsed document programmatically */
450
+ loadDocument: (doc: Document) => void;
451
+ /** Load a DOCX buffer programmatically (ArrayBuffer, Uint8Array, Blob, or File) */
452
+ loadDocumentBuffer: (buffer: DocxInput) => Promise<void>;
453
+ /** Add a comment programmatically. Anchored by Word `w14:paraId` so
454
+ * it survives unrelated edits. Returns the comment ID, or null if
455
+ * the paraId is unknown or the search text isn't found / is ambiguous. */
456
+ addComment: (options: {
457
+ paraId: string;
458
+ text: string;
459
+ author: string;
460
+ /** Optional: anchor to a specific phrase within the paragraph (must be unique). */
461
+ search?: string;
462
+ }) => number | null;
463
+ /** Reply to an existing comment. Returns the reply comment ID. */
464
+ replyToComment: (commentId: number, text: string, author: string) => number | null;
465
+ /** Resolve (mark as done) a comment. */
466
+ resolveComment: (commentId: number) => void;
467
+ /** Suggest a tracked change. Pass `replaceWith: ''` to delete the matched text;
468
+ * pass `search: ''` to insert at paragraph end. Returns false on missing paraId,
469
+ * missing/ambiguous search, or attempt to layer on an existing tracked change. */
470
+ proposeChange: (options: {
471
+ paraId: string;
472
+ search: string;
473
+ replaceWith: string;
474
+ author: string;
475
+ }) => boolean;
476
+ /** Locate every paragraph containing `query` (case-insensitive substring).
477
+ * Returns a stable handle (paraId + the matched phrase) the agent can pass
478
+ * back to `addComment` / `proposeChange`. */
479
+ findInDocument: (query: string, options?: {
480
+ caseSensitive?: boolean;
481
+ limit?: number;
482
+ }) => Array<{
483
+ paraId: string;
484
+ match: string;
485
+ before: string;
486
+ after: string;
487
+ }>;
488
+ /**
489
+ * Apply character formatting (bold / italic / color / size / font / etc.)
490
+ * to a paragraph or to a unique phrase within it. This is a direct edit,
491
+ * not a tracked change. Returns false on missing paraId or ambiguous search.
492
+ */
493
+ applyFormatting: (options: {
494
+ paraId: string;
495
+ search?: string;
496
+ marks: {
497
+ bold?: boolean;
498
+ italic?: boolean;
499
+ underline?: boolean | {
500
+ style?: string;
501
+ };
502
+ strike?: boolean;
503
+ color?: {
504
+ rgb?: string;
505
+ themeColor?: string;
506
+ };
507
+ highlight?: string;
508
+ fontSize?: number;
509
+ fontFamily?: {
510
+ ascii?: string;
511
+ hAnsi?: string;
512
+ };
513
+ };
514
+ }) => boolean;
515
+ /**
516
+ * Apply a paragraph style by styleId (e.g. `'Heading1'`, `'Quote'`).
517
+ * Direct edit, not a tracked change. Returns false if paraId is unknown.
518
+ */
519
+ setParagraphStyle: (options: {
520
+ paraId: string;
521
+ styleId: string;
522
+ }) => boolean;
523
+ /**
524
+ * Insert a page or section break after the paragraph identified by `paraId`.
525
+ * `'page'` adds a page break; `'sectionNextPage'` / `'sectionContinuous'`
526
+ * start a new section on a new page / the same page. Direct edit, not a
527
+ * tracked change. Returns false if paraId is unknown.
528
+ */
529
+ insertBreak: (options: {
530
+ paraId: string;
531
+ type: 'page' | 'sectionNextPage' | 'sectionContinuous';
532
+ }) => boolean;
533
+ /**
534
+ * Read the contents of a single page. 1-indexed; returns null if the page
535
+ * does not exist. Each paragraph is returned with its stable paraId so the
536
+ * agent can comment on or modify it without an extra round-trip.
537
+ */
538
+ getPageContent: (pageNumber: number) => {
539
+ pageNumber: number;
540
+ text: string;
541
+ paragraphs: Array<{
542
+ paraId: string;
543
+ text: string;
544
+ styleId?: string;
545
+ }>;
546
+ } | null;
547
+ /** Read the user's current cursor / selection — what's highlighted right now. */
548
+ getSelectionInfo: () => {
549
+ paraId: string | null;
550
+ selectedText: string;
551
+ paragraphText: string;
552
+ before: string;
553
+ after: string;
554
+ } | null;
555
+ /** Get all comments. */
556
+ getComments: () => Comment[];
557
+ /**
558
+ * List block-level content controls (SDTs) in the live document, optionally
559
+ * filtered by `tag`/`alias`/`id`/`type`. Each result includes the control's
560
+ * text and PM position. Anchors for templates and document automation.
561
+ */
562
+ getContentControls: (filter?: ContentControlFilter) => PMContentControl[];
563
+ /** Scroll the first content control matching `filter` into view. Returns false if none. */
564
+ scrollToContentControl: (filter: ContentControlFilter) => boolean;
565
+ /**
566
+ * Replace the content of the first control matching `filter` with `text`
567
+ * (newlines become paragraphs). Returns false if no match. Throws if the
568
+ * control is content-locked unless `{ force: true }`.
569
+ */
570
+ setContentControlContent: (filter: ContentControlFilter, text: string, options?: {
571
+ force?: boolean;
572
+ }) => boolean;
573
+ /**
574
+ * Remove the first control matching `filter`. With `{ keepContent: true }`
575
+ * the inner blocks are unwrapped in place. Returns false if no match. Throws
576
+ * if the control is deletion-locked unless `{ force: true }`.
577
+ */
578
+ removeContentControl: (filter: ContentControlFilter, options?: {
579
+ force?: boolean;
580
+ keepContent?: boolean;
581
+ }) => boolean;
582
+ /**
583
+ * Set a typed value on the first control matching `filter`: a dropdown
584
+ * selection (`{ kind: 'dropdown', value }`), checkbox (`{ kind: 'checkbox',
585
+ * checked }`), or date (`{ kind: 'date', date }`). Updates the visible
586
+ * content and structured state. Returns false if no match; throws if
587
+ * content-locked (unless `force`) or the value doesn't fit the control type.
588
+ */
589
+ setContentControlValue: (filter: ContentControlFilter, value: ContentControlValue, options?: {
590
+ force?: boolean;
591
+ }) => boolean;
592
+ /** Subscribe to document changes. Fires after every committed edit. Returns unsubscribe. */
593
+ onContentChange: (listener: (document: Document) => void) => () => void;
594
+ /** Subscribe to selection changes (cursor moves / selection changes). Returns unsubscribe. */
595
+ onSelectionChange: (listener: (selection: SelectionState | null) => void) => () => void;
596
+ }
597
+
598
+ /**
599
+ * DocxEditor - Complete DOCX editor component
600
+ */
601
+ declare const DocxEditor: React.ForwardRefExoticComponent<DocxEditorProps & React.RefAttributes<DocxEditorRef>>;
602
+
603
+ /**
604
+ * Simple imperative API for rendering a DOCX editor into a DOM element.
605
+ *
606
+ * Returns an `EditorHandle` (from @heyirisai/docx-editor-core) that works with
607
+ * any framework implementation.
608
+ *
609
+ * Usage:
610
+ * ```ts
611
+ * import { renderAsync } from '@heyirisai/docx-editor-react';
612
+ *
613
+ * const editor = await renderAsync(docxBlob, document.getElementById('container'), {
614
+ * readOnly: false,
615
+ * showToolbar: true,
616
+ * });
617
+ *
618
+ * // Save the edited document
619
+ * const blob = await editor.save();
620
+ *
621
+ * // Clean up
622
+ * editor.destroy();
623
+ * ```
624
+ */
625
+
626
+ /**
627
+ * Options for {@link renderAsync}. A subset of DocxEditorProps minus
628
+ * `documentBuffer` / `document` (passed as the first argument instead).
629
+ */
630
+ type RenderAsyncOptions = Omit<DocxEditorProps, 'documentBuffer' | 'document'>;
631
+ /**
632
+ * React-specific handle that extends the framework-agnostic EditorHandle
633
+ * with zoom control.
634
+ */
635
+ interface DocxEditorHandle extends EditorHandle {
636
+ /** Set zoom level (1.0 = 100%). */
637
+ setZoom: (zoom: number) => void;
638
+ /** Scroll to a body paragraph by Word `w14:paraId`. */
639
+ scrollToParaId: (paraId: string, options?: ScrollToParaIdOptions) => boolean;
640
+ /** Scroll to a raw ProseMirror document position. */
641
+ scrollToPosition: (pmPos: number) => void;
642
+ }
643
+ /**
644
+ * Render a DOCX editor into a container element.
645
+ *
646
+ * @param input - DOCX data as ArrayBuffer, Uint8Array, Blob, or File
647
+ * @param container - DOM element to render into
648
+ * @param options - Editor configuration (toolbar, readOnly, callbacks, etc.)
649
+ * @returns A handle with save / destroy / getDocument methods
650
+ */
651
+ declare function renderAsync(input: DocxInput, container: HTMLElement, options?: RenderAsyncOptions): Promise<DocxEditorHandle>;
652
+
653
+ interface LocaleProviderProps {
654
+ i18n?: Translations;
655
+ children: ReactNode;
656
+ }
657
+ declare function LocaleProvider({ i18n, children }: LocaleProviderProps): React.JSX.Element;
658
+ declare function useTranslation(): {
659
+ t: TFunction;
660
+ };
661
+
662
+ /**
663
+ * @heyirisai/docx-editor-react
664
+ *
665
+ * Curated root entry for the documented React editor API. Advanced surfaces
666
+ * stay public through explicit subpaths:
667
+ * - `@heyirisai/docx-editor-react/ui`
668
+ * - `@heyirisai/docx-editor-react/dialogs`
669
+ * - `@heyirisai/docx-editor-react/hooks`
670
+ * - `@heyirisai/docx-editor-react/plugin-api`
671
+ *
672
+ * Framework-agnostic document utilities live in `@heyirisai/docx-editor-core`.
673
+ * Agent/MCP surfaces live in `@heyirisai/docx-editor-agents`.
674
+ *
675
+ * @packageDocumentation
676
+ * @public
677
+ */
678
+ declare const VERSION = "0.0.2";
679
+
680
+ export { DocxEditor, type DocxEditorHandle, type DocxEditorProps, type DocxEditorRef, type EditorMode, LocaleProvider, type LocaleProviderProps, type RenderAsyncOptions, VERSION, renderAsync, useTranslation };