@extend-ai/react-docx 0.7.0-alpha.4 → 0.7.0-alpha.5

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.
package/dist/index.d.cts CHANGED
@@ -401,6 +401,17 @@ interface DocumentNoteDefinition {
401
401
  text: string;
402
402
  nodes?: DocNode[];
403
403
  }
404
+ interface DocumentCommentDefinition {
405
+ id: number;
406
+ author?: string;
407
+ initials?: string;
408
+ date?: string;
409
+ text: string;
410
+ /** Comment id this comment replies to (from commentsExtended threading). */
411
+ parentId?: number;
412
+ /** True when the comment thread is marked done in commentsExtended. */
413
+ resolved?: boolean;
414
+ }
404
415
  interface DocumentCompatibilitySettings {
405
416
  suppressSpacingBeforeAfterPageBreak?: boolean;
406
417
  usePrinterMetrics?: boolean;
@@ -427,6 +438,7 @@ interface DocModel {
427
438
  compatibility?: DocumentCompatibilitySettings;
428
439
  footnotes?: DocumentNoteDefinition[];
429
440
  endnotes?: DocumentNoteDefinition[];
441
+ comments?: DocumentCommentDefinition[];
430
442
  };
431
443
  }
432
444
 
@@ -618,6 +630,32 @@ interface DocxTrackedChange {
618
630
  nodeIndex: number;
619
631
  location: DocxTextRangeLocation;
620
632
  }
633
+ /**
634
+ * A document comment anchored to a text range.
635
+ *
636
+ * Comment definitions come from `word/comments.xml` (threading and resolution
637
+ * state from `word/commentsExtended.xml`); the anchor location is resolved
638
+ * from the paragraph that carries the `commentReference` run.
639
+ */
640
+ interface DocxComment {
641
+ /** Stable identifier (unique per rendered anchor). */
642
+ id: string;
643
+ /** Comment id from `word/comments.xml` (`w:id`). */
644
+ commentId: number;
645
+ author?: string;
646
+ initials?: string;
647
+ date?: string;
648
+ /** Plain-text comment body. */
649
+ text: string;
650
+ /** Comment id this comment replies to, when part of a thread. */
651
+ parentId?: number;
652
+ /** True when the comment thread is marked done. */
653
+ resolved?: boolean;
654
+ /** Plain-text excerpt of the commented document range. */
655
+ anchorText?: string;
656
+ nodeIndex: number;
657
+ location: DocxTextRangeLocation;
658
+ }
621
659
  type DocxLineSpacingRule = "auto" | "exact" | "atLeast";
622
660
  type DocxSelectionSessionKind = "idle" | "pointer" | "keyboard" | "composition" | "command" | "history-restore";
623
661
  interface DocxLineSpacingInfo {
@@ -665,6 +703,12 @@ interface UseDocxEditorOptions {
665
703
  * @defaultValue `false`
666
704
  */
667
705
  initialShowTrackedChanges?: boolean;
706
+ /**
707
+ * Whether document comments are visible when the editor first mounts.
708
+ *
709
+ * @defaultValue `false`
710
+ */
711
+ initialShowComments?: boolean;
668
712
  }
669
713
  /**
670
714
  * Controller returned by `useDocxEditor`.
@@ -713,6 +757,8 @@ interface DocxEditorController {
713
757
  availableParagraphStyles: ParagraphStyleDefinition[];
714
758
  trackedChanges: DocxTrackedChange[];
715
759
  showTrackedChanges: boolean;
760
+ comments: DocxComment[];
761
+ showComments: boolean;
716
762
  currentPage: number;
717
763
  totalPages: number;
718
764
  hasUnorderedList: boolean;
@@ -723,8 +769,10 @@ interface DocxEditorController {
723
769
  setStatus: React.Dispatch<React.SetStateAction<string>>;
724
770
  setDocumentTheme: (theme: DocxDocumentTheme) => void;
725
771
  setShowTrackedChanges: (showTrackedChanges: boolean) => void;
772
+ setShowComments: (showComments: boolean) => void;
726
773
  syncPaginationInfo: (pagination: DocxPaginationInfo) => void;
727
774
  toggleShowTrackedChanges: () => void;
775
+ toggleShowComments: () => void;
728
776
  importDocxFile: (file: File) => Promise<void>;
729
777
  newDocument: () => void;
730
778
  exportDocx: () => void;
@@ -1048,6 +1096,17 @@ interface DocxEditorViewerProps {
1048
1096
  * Custom renderer for tracked-change cards in the page gutter.
1049
1097
  */
1050
1098
  renderTrackedChangeCard?: (props: DocxTrackedChangeCardRenderProps) => React.ReactNode;
1099
+ /**
1100
+ * Overrides whether document comments are shown.
1101
+ *
1102
+ * If omitted, the value from `useDocxComments(editor)` or
1103
+ * `editor.showComments` is used.
1104
+ */
1105
+ showComments?: boolean;
1106
+ /**
1107
+ * Custom renderer for comment cards in the page gutter.
1108
+ */
1109
+ renderCommentCard?: (props: DocxCommentCardRenderProps) => React.ReactNode;
1051
1110
  /**
1052
1111
  * Custom renderer for table context menus.
1053
1112
  *
@@ -1085,6 +1144,22 @@ interface DocxTrackedChangeCardRenderProps {
1085
1144
  /** Positioning style computed by the viewer. Apply this to the card root. */
1086
1145
  style: React.CSSProperties;
1087
1146
  }
1147
+ interface DocxCommentCardRenderProps {
1148
+ /** Comment data represented by the card. */
1149
+ comment: DocxComment;
1150
+ /** Plain-text comment body (already normalized for display). */
1151
+ snippet: string;
1152
+ /** Formatted comment date, if the source document provided one. */
1153
+ formattedDate?: string;
1154
+ /** Accent color chosen for comments. */
1155
+ accentColor: string;
1156
+ /** Current document theme. */
1157
+ documentTheme: DocxDocumentTheme;
1158
+ /** Zero-based page index that owns the card. */
1159
+ pageIndex: number;
1160
+ /** Positioning style computed by the viewer. Apply this to the card root. */
1161
+ style: React.CSSProperties;
1162
+ }
1088
1163
  /**
1089
1164
  * Viewer interaction mode.
1090
1165
  *
@@ -1129,6 +1204,14 @@ interface UseDocxTrackChangesResult {
1129
1204
  changesByLocation: Map<string, DocxTrackedChange[]>;
1130
1205
  getChangesForLocation: (location: DocxTextRangeLocation) => DocxTrackedChange[];
1131
1206
  }
1207
+ interface UseDocxCommentsResult {
1208
+ comments: DocxComment[];
1209
+ showComments: boolean;
1210
+ setShowComments: (showComments: boolean) => void;
1211
+ toggleShowComments: () => void;
1212
+ commentsByLocation: Map<string, DocxComment[]>;
1213
+ getCommentsForLocation: (location: DocxTextRangeLocation) => DocxComment[];
1214
+ }
1132
1215
  interface DocxSectionColumnLayout {
1133
1216
  count: number;
1134
1217
  gapPx: number;
@@ -1307,9 +1390,15 @@ declare function useDocxLineSpacing(editor: Pick<DocxEditorController, "selected
1307
1390
  declare function useDocxBorders(editor: Pick<DocxEditorController, "selectedBorderContext" | "activeBorderPresets" | "applyBorderPreset">): UseDocxBordersResult;
1308
1391
  declare function useDocxFormFields(editor: Pick<DocxEditorController, "model" | "selectedFormField" | "selectFormField" | "setFormFieldValue" | "toggleFormCheckbox" | "updateFormFieldWidget">): UseDocxFormFieldsResult;
1309
1392
  declare function useDocxTrackChanges(editor: Pick<DocxEditorController, "trackedChanges" | "showTrackedChanges" | "setShowTrackedChanges" | "toggleShowTrackedChanges">): UseDocxTrackChangesResult;
1393
+ /**
1394
+ * Exposes document comments and the show/hide state, mirroring
1395
+ * `useDocxTrackChanges`. Pair with `DocxEditorViewer`'s `renderCommentCard`
1396
+ * to fully customize how comments render.
1397
+ */
1398
+ declare function useDocxComments(editor: Pick<DocxEditorController, "comments" | "showComments" | "setShowComments" | "toggleShowComments">): UseDocxCommentsResult;
1310
1399
  declare function useDocxPageLayout(editor: Pick<DocxEditorController, "model">): UseDocxPageLayoutResult;
1311
1400
  declare function useDocxPagination(editor: Pick<DocxEditorController, "currentPage" | "totalPages">): UseDocxPaginationResult;
1312
- declare function DocxEditorViewer({ editor, className, style, pageBackgroundColor, pageGapBackgroundColor, deferInitialPaginationPaint, loadingState, pageVirtualization, visiblePageRange, onPageCountChange, onRequestPageReveal, headingStyles, showTrackedChanges, renderTrackedChangeCard, renderTableContextMenu, renderContextMenu, onFormFieldDoubleClick, mode, }: DocxEditorViewerProps): React.JSX.Element;
1401
+ declare function DocxEditorViewer({ editor, className, style, pageBackgroundColor, pageGapBackgroundColor, deferInitialPaginationPaint, loadingState, pageVirtualization, visiblePageRange, onPageCountChange, onRequestPageReveal, headingStyles, showTrackedChanges, renderTrackedChangeCard, showComments, renderCommentCard, renderTableContextMenu, renderContextMenu, onFormFieldDoubleClick, mode, }: DocxEditorViewerProps): React.JSX.Element;
1313
1402
 
1314
1403
  interface InsertParagraphOptions {
1315
1404
  paragraphStyle?: ParagraphStyle;
@@ -1623,4 +1712,4 @@ interface UseDocxModelState {
1623
1712
  declare function useDocxModel(file?: ArrayBuffer): UseDocxModelState;
1624
1713
  declare function ReactDocxViewer({ file, model, className, layoutOptions, emptyState }: ReactDocxViewerProps): React.JSX.Element;
1625
1714
 
1626
- export { DEFAULT_MIN_PARAGRAPH_LINE_HEIGHT_PX, DEFAULT_PAGE_OVERFLOW_TOLERANCE_PX, type DocModel, type DocNode, type DocumentCompatibilitySettings, type DocumentNoteDefinition, type DocumentPageNodeSegment, type DocumentPageRange, type DocumentPageSegmentationOptions, type DocumentSection, type DocxBorderContext, type DocxBorderPreset, type DocxBorderPresetState, type DocxContextMenuAction, type DocxContextMenuActionId, type DocxContextMenuContext, type DocxContextMenuRenderProps, type DocxDocumentTheme, type DocxEditorController, type DocxEditorSelection, DocxEditorViewer, type DocxEditorViewerMode, type DocxEditorViewerProps, type DocxFormFieldLocation, type DocxHeadingStyleMap, type DocxImageDropTarget, type DocxImageLocation, type DocxImageWrapMenuOption, type DocxImageWrapMode, type DocxImageWrapState, type DocxLineSpacingInfo, type DocxListType, type DocxPageLayoutInfo, type DocxPageThumbnailBounds, type DocxPageThumbnailItem, type DocxPageThumbnailResolution, type DocxPageThumbnailResolutionOptions, type DocxPageThumbnailStatus, type DocxPageVirtualizationOptions, type DocxPaginationInfo, type DocxSectionColumnLayout, type DocxSelectedFormField, type DocxTableContextMenuAction, type DocxTableContextMenuActionId, type DocxTableContextMenuContext, type DocxTableContextMenuRenderProps, type DocxTextRange, type DocxTextRangeLocation, type DocxTrackedChange, type DocxTrackedChangeCardRenderProps, type DocxTrackedChangeKind, type DocxViewerThumbnails, type DocxVisiblePageRange, type FooterSection, type FormFieldCheckboxWidgetSettings, type FormFieldDropdownWidgetSettings, type FormFieldOption, type FormFieldRunNode, type FormFieldSourceKind, type FormFieldTextWidgetSettings, type FormFieldType, type FormFieldWidgetSettings, type HeaderSection, type HeadingLevel, type ImageRunNode, type InsertParagraphOptions, type LayoutBlock, type LayoutFragmentSource, type LayoutImageRun, type LayoutOptions, type LayoutPage, type LayoutParagraphBlock, type LayoutRun, type LayoutSnapshot, type LayoutSnapshotBlockFragment, type LayoutSnapshotImageRun, type LayoutSnapshotMargins, type LayoutSnapshotOptions, type LayoutSnapshotPage, type LayoutSnapshotPageSize, type LayoutSnapshotParagraphFragment, type LayoutSnapshotRect, type LayoutSnapshotRun, type LayoutSnapshotTableCellFragment, type LayoutSnapshotTableFragment, type LayoutSnapshotTableRowFragment, type LayoutSnapshotTextRun, type LayoutTableBlock, type LayoutTableCell, type LayoutTableRow, type LayoutTextRun, type LegacyWasmOoxmlPackage, type LetterheadColumnSegmentGroup, type NumberingAbstractDefinition, type NumberingDefinitionSet, type NumberingInstanceDefinition, type NumberingLevelDefinition, type NumberingPictureBulletDefinition, type OoxmlPackage, type OoxmlPart, type OverflowBreakCollectionOptions, type PageSegmentationCallbacks, type PaginationSectionMetrics, type ParagraphAlignment, type ParagraphBorderSet, type ParagraphBorderStyle, type ParagraphChildNode, type ParagraphIndent, type ParagraphLineRange, type ParagraphNode, type ParagraphNumbering, type ParagraphSpacing, type ParagraphSplitControlOptions, type ParagraphStyle, type ParagraphStyleDefinition, type ParagraphTabStop, ReactDocxViewer, type ReactDocxViewerProps, type ResolvedDocument, type ResolvedDocumentSection, type ResolvedLayoutMetrics, type ResolvedModelSection, type TableBorderSet, type TableBorderStyle, type TableBoxSpacing, type TableCellContentNode, type TableCellNode, type TableCellStyle, type TableExplicitPageBreakInfo, type TableNode, type TableRowNode, type TableRowRange, type TableRowStyle, type TableStyle, type TextRunBorderStyle, type TextRunNode, type TextStyle, type UpdateTextOptions, type UseDocxBordersResult, type UseDocxDocumentThemeResult, type UseDocxEditorOptions, type UseDocxFormFieldsResult, type UseDocxImageWrapMenuResult, type UseDocxLineSpacingResult, type UseDocxModelState, type UseDocxPageLayoutResult, type UseDocxPageThumbnailsOptions, type UseDocxPageThumbnailsResult, type UseDocxPaginationResult, type UseDocxParagraphStylesResult, type UseDocxTrackChangesResult, type UseDocxViewerThumbnailsOptions, type WasmOoxmlPackage, type WasmSource, applyRunStyle, buildDocModel, buildDocModelFromBytes, buildDocumentPageNodeSegments, buildDocumentPageRanges, buildLayoutSnapshot, cloneDocModel, collectDocxEstimatedOverflowBreakStartNodeIndexes, collectDocxHardPageBreakStartNodeIndexes, collectDocxLastRenderedPageBreakStartNodeIndexes, collectTableExplicitPageBreakInfo, collectTopLevelExplicitPageBreakStartNodeIndexes, copyParagraphs, createMinimalDocxPackage, defaultStarterModel, duplicateParagraph, getPart, initWasm, insertParagraph, layoutDocument, modelToDocumentXml, normalizeDocModel, packageToArrayBuffer, paragraphAfterSpacingPx, paragraphBeforeSpacingPx, paragraphHasExplicitPageBreak, paragraphHasLastRenderedPageBreak, paragraphHasPageBreakBefore, paragraphLetterheadColumnGroupAtSegmentOffset, paragraphLetterheadFloatSideAtNodeIndex, paragraphStartsWithLastRenderedPageBreak, parseDocx, parseParagraphsFromClipboard, parseSectionLayout, pasteParagraphs, removeParagraph, replaceText, resolveDocumentForLayout, resolveDocumentLayout, resolveDocumentPageSegmentStartNodeIndex, resolveDocumentSectionsFromMetadata, resolveDocxPageThumbnailResolution, resolvePaginationSectionMetricsIndexForNodeIndex, resolveParagraphBeforeSpacingPx, resolveSectionIndexForNodeIndex, resolveSectionPropertiesXmlForNodeIndex, scalePaginationSectionMetricsHeights, scorePaginationAgainstStoredPageBreaks, sectionBreakAfterParagraphStartsNewPage, sectionBreakPropertiesStartNewPage, sectionTitlePageEnabled, selectSectionVariantForPage, serializeDocModel, serializeDocx, serializeParagraphsForClipboard, setParagraphAlignment, setParagraphHeading, setRunColor, setRunHighlight, setWasmSource, splitParagraphChildrenAtTextOffsets, toggleRunStyleFlag, updateParagraphText, updateTableCellParagraphText, updateTableCellParagraphTextRecursive, updateTableCellText, useDocxBorders, useDocxDocumentTheme, useDocxEditor, useDocxFormFields, useDocxImageWrapMenu, useDocxLineSpacing, useDocxModel, useDocxPageLayout, useDocxPageThumbnails, useDocxPagination, useDocxParagraphStyles, useDocxTrackChanges, useDocxViewerThumbnails, withPart };
1715
+ export { DEFAULT_MIN_PARAGRAPH_LINE_HEIGHT_PX, DEFAULT_PAGE_OVERFLOW_TOLERANCE_PX, type DocModel, type DocNode, type DocumentCommentDefinition, type DocumentCompatibilitySettings, type DocumentNoteDefinition, type DocumentPageNodeSegment, type DocumentPageRange, type DocumentPageSegmentationOptions, type DocumentSection, type DocxBorderContext, type DocxBorderPreset, type DocxBorderPresetState, type DocxComment, type DocxCommentCardRenderProps, type DocxContextMenuAction, type DocxContextMenuActionId, type DocxContextMenuContext, type DocxContextMenuRenderProps, type DocxDocumentTheme, type DocxEditorController, type DocxEditorSelection, DocxEditorViewer, type DocxEditorViewerMode, type DocxEditorViewerProps, type DocxFormFieldLocation, type DocxHeadingStyleMap, type DocxImageDropTarget, type DocxImageLocation, type DocxImageWrapMenuOption, type DocxImageWrapMode, type DocxImageWrapState, type DocxLineSpacingInfo, type DocxListType, type DocxPageLayoutInfo, type DocxPageThumbnailBounds, type DocxPageThumbnailItem, type DocxPageThumbnailResolution, type DocxPageThumbnailResolutionOptions, type DocxPageThumbnailStatus, type DocxPageVirtualizationOptions, type DocxPaginationInfo, type DocxSectionColumnLayout, type DocxSelectedFormField, type DocxTableContextMenuAction, type DocxTableContextMenuActionId, type DocxTableContextMenuContext, type DocxTableContextMenuRenderProps, type DocxTextRange, type DocxTextRangeLocation, type DocxTrackedChange, type DocxTrackedChangeCardRenderProps, type DocxTrackedChangeKind, type DocxViewerThumbnails, type DocxVisiblePageRange, type FooterSection, type FormFieldCheckboxWidgetSettings, type FormFieldDropdownWidgetSettings, type FormFieldOption, type FormFieldRunNode, type FormFieldSourceKind, type FormFieldTextWidgetSettings, type FormFieldType, type FormFieldWidgetSettings, type HeaderSection, type HeadingLevel, type ImageRunNode, type InsertParagraphOptions, type LayoutBlock, type LayoutFragmentSource, type LayoutImageRun, type LayoutOptions, type LayoutPage, type LayoutParagraphBlock, type LayoutRun, type LayoutSnapshot, type LayoutSnapshotBlockFragment, type LayoutSnapshotImageRun, type LayoutSnapshotMargins, type LayoutSnapshotOptions, type LayoutSnapshotPage, type LayoutSnapshotPageSize, type LayoutSnapshotParagraphFragment, type LayoutSnapshotRect, type LayoutSnapshotRun, type LayoutSnapshotTableCellFragment, type LayoutSnapshotTableFragment, type LayoutSnapshotTableRowFragment, type LayoutSnapshotTextRun, type LayoutTableBlock, type LayoutTableCell, type LayoutTableRow, type LayoutTextRun, type LegacyWasmOoxmlPackage, type LetterheadColumnSegmentGroup, type NumberingAbstractDefinition, type NumberingDefinitionSet, type NumberingInstanceDefinition, type NumberingLevelDefinition, type NumberingPictureBulletDefinition, type OoxmlPackage, type OoxmlPart, type OverflowBreakCollectionOptions, type PageSegmentationCallbacks, type PaginationSectionMetrics, type ParagraphAlignment, type ParagraphBorderSet, type ParagraphBorderStyle, type ParagraphChildNode, type ParagraphIndent, type ParagraphLineRange, type ParagraphNode, type ParagraphNumbering, type ParagraphSpacing, type ParagraphSplitControlOptions, type ParagraphStyle, type ParagraphStyleDefinition, type ParagraphTabStop, ReactDocxViewer, type ReactDocxViewerProps, type ResolvedDocument, type ResolvedDocumentSection, type ResolvedLayoutMetrics, type ResolvedModelSection, type TableBorderSet, type TableBorderStyle, type TableBoxSpacing, type TableCellContentNode, type TableCellNode, type TableCellStyle, type TableExplicitPageBreakInfo, type TableNode, type TableRowNode, type TableRowRange, type TableRowStyle, type TableStyle, type TextRunBorderStyle, type TextRunNode, type TextStyle, type UpdateTextOptions, type UseDocxBordersResult, type UseDocxCommentsResult, type UseDocxDocumentThemeResult, type UseDocxEditorOptions, type UseDocxFormFieldsResult, type UseDocxImageWrapMenuResult, type UseDocxLineSpacingResult, type UseDocxModelState, type UseDocxPageLayoutResult, type UseDocxPageThumbnailsOptions, type UseDocxPageThumbnailsResult, type UseDocxPaginationResult, type UseDocxParagraphStylesResult, type UseDocxTrackChangesResult, type UseDocxViewerThumbnailsOptions, type WasmOoxmlPackage, type WasmSource, applyRunStyle, buildDocModel, buildDocModelFromBytes, buildDocumentPageNodeSegments, buildDocumentPageRanges, buildLayoutSnapshot, cloneDocModel, collectDocxEstimatedOverflowBreakStartNodeIndexes, collectDocxHardPageBreakStartNodeIndexes, collectDocxLastRenderedPageBreakStartNodeIndexes, collectTableExplicitPageBreakInfo, collectTopLevelExplicitPageBreakStartNodeIndexes, copyParagraphs, createMinimalDocxPackage, defaultStarterModel, duplicateParagraph, getPart, initWasm, insertParagraph, layoutDocument, modelToDocumentXml, normalizeDocModel, packageToArrayBuffer, paragraphAfterSpacingPx, paragraphBeforeSpacingPx, paragraphHasExplicitPageBreak, paragraphHasLastRenderedPageBreak, paragraphHasPageBreakBefore, paragraphLetterheadColumnGroupAtSegmentOffset, paragraphLetterheadFloatSideAtNodeIndex, paragraphStartsWithLastRenderedPageBreak, parseDocx, parseParagraphsFromClipboard, parseSectionLayout, pasteParagraphs, removeParagraph, replaceText, resolveDocumentForLayout, resolveDocumentLayout, resolveDocumentPageSegmentStartNodeIndex, resolveDocumentSectionsFromMetadata, resolveDocxPageThumbnailResolution, resolvePaginationSectionMetricsIndexForNodeIndex, resolveParagraphBeforeSpacingPx, resolveSectionIndexForNodeIndex, resolveSectionPropertiesXmlForNodeIndex, scalePaginationSectionMetricsHeights, scorePaginationAgainstStoredPageBreaks, sectionBreakAfterParagraphStartsNewPage, sectionBreakPropertiesStartNewPage, sectionTitlePageEnabled, selectSectionVariantForPage, serializeDocModel, serializeDocx, serializeParagraphsForClipboard, setParagraphAlignment, setParagraphHeading, setRunColor, setRunHighlight, setWasmSource, splitParagraphChildrenAtTextOffsets, toggleRunStyleFlag, updateParagraphText, updateTableCellParagraphText, updateTableCellParagraphTextRecursive, updateTableCellText, useDocxBorders, useDocxComments, useDocxDocumentTheme, useDocxEditor, useDocxFormFields, useDocxImageWrapMenu, useDocxLineSpacing, useDocxModel, useDocxPageLayout, useDocxPageThumbnails, useDocxPagination, useDocxParagraphStyles, useDocxTrackChanges, useDocxViewerThumbnails, withPart };
package/dist/index.d.ts CHANGED
@@ -401,6 +401,17 @@ interface DocumentNoteDefinition {
401
401
  text: string;
402
402
  nodes?: DocNode[];
403
403
  }
404
+ interface DocumentCommentDefinition {
405
+ id: number;
406
+ author?: string;
407
+ initials?: string;
408
+ date?: string;
409
+ text: string;
410
+ /** Comment id this comment replies to (from commentsExtended threading). */
411
+ parentId?: number;
412
+ /** True when the comment thread is marked done in commentsExtended. */
413
+ resolved?: boolean;
414
+ }
404
415
  interface DocumentCompatibilitySettings {
405
416
  suppressSpacingBeforeAfterPageBreak?: boolean;
406
417
  usePrinterMetrics?: boolean;
@@ -427,6 +438,7 @@ interface DocModel {
427
438
  compatibility?: DocumentCompatibilitySettings;
428
439
  footnotes?: DocumentNoteDefinition[];
429
440
  endnotes?: DocumentNoteDefinition[];
441
+ comments?: DocumentCommentDefinition[];
430
442
  };
431
443
  }
432
444
 
@@ -618,6 +630,32 @@ interface DocxTrackedChange {
618
630
  nodeIndex: number;
619
631
  location: DocxTextRangeLocation;
620
632
  }
633
+ /**
634
+ * A document comment anchored to a text range.
635
+ *
636
+ * Comment definitions come from `word/comments.xml` (threading and resolution
637
+ * state from `word/commentsExtended.xml`); the anchor location is resolved
638
+ * from the paragraph that carries the `commentReference` run.
639
+ */
640
+ interface DocxComment {
641
+ /** Stable identifier (unique per rendered anchor). */
642
+ id: string;
643
+ /** Comment id from `word/comments.xml` (`w:id`). */
644
+ commentId: number;
645
+ author?: string;
646
+ initials?: string;
647
+ date?: string;
648
+ /** Plain-text comment body. */
649
+ text: string;
650
+ /** Comment id this comment replies to, when part of a thread. */
651
+ parentId?: number;
652
+ /** True when the comment thread is marked done. */
653
+ resolved?: boolean;
654
+ /** Plain-text excerpt of the commented document range. */
655
+ anchorText?: string;
656
+ nodeIndex: number;
657
+ location: DocxTextRangeLocation;
658
+ }
621
659
  type DocxLineSpacingRule = "auto" | "exact" | "atLeast";
622
660
  type DocxSelectionSessionKind = "idle" | "pointer" | "keyboard" | "composition" | "command" | "history-restore";
623
661
  interface DocxLineSpacingInfo {
@@ -665,6 +703,12 @@ interface UseDocxEditorOptions {
665
703
  * @defaultValue `false`
666
704
  */
667
705
  initialShowTrackedChanges?: boolean;
706
+ /**
707
+ * Whether document comments are visible when the editor first mounts.
708
+ *
709
+ * @defaultValue `false`
710
+ */
711
+ initialShowComments?: boolean;
668
712
  }
669
713
  /**
670
714
  * Controller returned by `useDocxEditor`.
@@ -713,6 +757,8 @@ interface DocxEditorController {
713
757
  availableParagraphStyles: ParagraphStyleDefinition[];
714
758
  trackedChanges: DocxTrackedChange[];
715
759
  showTrackedChanges: boolean;
760
+ comments: DocxComment[];
761
+ showComments: boolean;
716
762
  currentPage: number;
717
763
  totalPages: number;
718
764
  hasUnorderedList: boolean;
@@ -723,8 +769,10 @@ interface DocxEditorController {
723
769
  setStatus: React.Dispatch<React.SetStateAction<string>>;
724
770
  setDocumentTheme: (theme: DocxDocumentTheme) => void;
725
771
  setShowTrackedChanges: (showTrackedChanges: boolean) => void;
772
+ setShowComments: (showComments: boolean) => void;
726
773
  syncPaginationInfo: (pagination: DocxPaginationInfo) => void;
727
774
  toggleShowTrackedChanges: () => void;
775
+ toggleShowComments: () => void;
728
776
  importDocxFile: (file: File) => Promise<void>;
729
777
  newDocument: () => void;
730
778
  exportDocx: () => void;
@@ -1048,6 +1096,17 @@ interface DocxEditorViewerProps {
1048
1096
  * Custom renderer for tracked-change cards in the page gutter.
1049
1097
  */
1050
1098
  renderTrackedChangeCard?: (props: DocxTrackedChangeCardRenderProps) => React.ReactNode;
1099
+ /**
1100
+ * Overrides whether document comments are shown.
1101
+ *
1102
+ * If omitted, the value from `useDocxComments(editor)` or
1103
+ * `editor.showComments` is used.
1104
+ */
1105
+ showComments?: boolean;
1106
+ /**
1107
+ * Custom renderer for comment cards in the page gutter.
1108
+ */
1109
+ renderCommentCard?: (props: DocxCommentCardRenderProps) => React.ReactNode;
1051
1110
  /**
1052
1111
  * Custom renderer for table context menus.
1053
1112
  *
@@ -1085,6 +1144,22 @@ interface DocxTrackedChangeCardRenderProps {
1085
1144
  /** Positioning style computed by the viewer. Apply this to the card root. */
1086
1145
  style: React.CSSProperties;
1087
1146
  }
1147
+ interface DocxCommentCardRenderProps {
1148
+ /** Comment data represented by the card. */
1149
+ comment: DocxComment;
1150
+ /** Plain-text comment body (already normalized for display). */
1151
+ snippet: string;
1152
+ /** Formatted comment date, if the source document provided one. */
1153
+ formattedDate?: string;
1154
+ /** Accent color chosen for comments. */
1155
+ accentColor: string;
1156
+ /** Current document theme. */
1157
+ documentTheme: DocxDocumentTheme;
1158
+ /** Zero-based page index that owns the card. */
1159
+ pageIndex: number;
1160
+ /** Positioning style computed by the viewer. Apply this to the card root. */
1161
+ style: React.CSSProperties;
1162
+ }
1088
1163
  /**
1089
1164
  * Viewer interaction mode.
1090
1165
  *
@@ -1129,6 +1204,14 @@ interface UseDocxTrackChangesResult {
1129
1204
  changesByLocation: Map<string, DocxTrackedChange[]>;
1130
1205
  getChangesForLocation: (location: DocxTextRangeLocation) => DocxTrackedChange[];
1131
1206
  }
1207
+ interface UseDocxCommentsResult {
1208
+ comments: DocxComment[];
1209
+ showComments: boolean;
1210
+ setShowComments: (showComments: boolean) => void;
1211
+ toggleShowComments: () => void;
1212
+ commentsByLocation: Map<string, DocxComment[]>;
1213
+ getCommentsForLocation: (location: DocxTextRangeLocation) => DocxComment[];
1214
+ }
1132
1215
  interface DocxSectionColumnLayout {
1133
1216
  count: number;
1134
1217
  gapPx: number;
@@ -1307,9 +1390,15 @@ declare function useDocxLineSpacing(editor: Pick<DocxEditorController, "selected
1307
1390
  declare function useDocxBorders(editor: Pick<DocxEditorController, "selectedBorderContext" | "activeBorderPresets" | "applyBorderPreset">): UseDocxBordersResult;
1308
1391
  declare function useDocxFormFields(editor: Pick<DocxEditorController, "model" | "selectedFormField" | "selectFormField" | "setFormFieldValue" | "toggleFormCheckbox" | "updateFormFieldWidget">): UseDocxFormFieldsResult;
1309
1392
  declare function useDocxTrackChanges(editor: Pick<DocxEditorController, "trackedChanges" | "showTrackedChanges" | "setShowTrackedChanges" | "toggleShowTrackedChanges">): UseDocxTrackChangesResult;
1393
+ /**
1394
+ * Exposes document comments and the show/hide state, mirroring
1395
+ * `useDocxTrackChanges`. Pair with `DocxEditorViewer`'s `renderCommentCard`
1396
+ * to fully customize how comments render.
1397
+ */
1398
+ declare function useDocxComments(editor: Pick<DocxEditorController, "comments" | "showComments" | "setShowComments" | "toggleShowComments">): UseDocxCommentsResult;
1310
1399
  declare function useDocxPageLayout(editor: Pick<DocxEditorController, "model">): UseDocxPageLayoutResult;
1311
1400
  declare function useDocxPagination(editor: Pick<DocxEditorController, "currentPage" | "totalPages">): UseDocxPaginationResult;
1312
- declare function DocxEditorViewer({ editor, className, style, pageBackgroundColor, pageGapBackgroundColor, deferInitialPaginationPaint, loadingState, pageVirtualization, visiblePageRange, onPageCountChange, onRequestPageReveal, headingStyles, showTrackedChanges, renderTrackedChangeCard, renderTableContextMenu, renderContextMenu, onFormFieldDoubleClick, mode, }: DocxEditorViewerProps): React.JSX.Element;
1401
+ declare function DocxEditorViewer({ editor, className, style, pageBackgroundColor, pageGapBackgroundColor, deferInitialPaginationPaint, loadingState, pageVirtualization, visiblePageRange, onPageCountChange, onRequestPageReveal, headingStyles, showTrackedChanges, renderTrackedChangeCard, showComments, renderCommentCard, renderTableContextMenu, renderContextMenu, onFormFieldDoubleClick, mode, }: DocxEditorViewerProps): React.JSX.Element;
1313
1402
 
1314
1403
  interface InsertParagraphOptions {
1315
1404
  paragraphStyle?: ParagraphStyle;
@@ -1623,4 +1712,4 @@ interface UseDocxModelState {
1623
1712
  declare function useDocxModel(file?: ArrayBuffer): UseDocxModelState;
1624
1713
  declare function ReactDocxViewer({ file, model, className, layoutOptions, emptyState }: ReactDocxViewerProps): React.JSX.Element;
1625
1714
 
1626
- export { DEFAULT_MIN_PARAGRAPH_LINE_HEIGHT_PX, DEFAULT_PAGE_OVERFLOW_TOLERANCE_PX, type DocModel, type DocNode, type DocumentCompatibilitySettings, type DocumentNoteDefinition, type DocumentPageNodeSegment, type DocumentPageRange, type DocumentPageSegmentationOptions, type DocumentSection, type DocxBorderContext, type DocxBorderPreset, type DocxBorderPresetState, type DocxContextMenuAction, type DocxContextMenuActionId, type DocxContextMenuContext, type DocxContextMenuRenderProps, type DocxDocumentTheme, type DocxEditorController, type DocxEditorSelection, DocxEditorViewer, type DocxEditorViewerMode, type DocxEditorViewerProps, type DocxFormFieldLocation, type DocxHeadingStyleMap, type DocxImageDropTarget, type DocxImageLocation, type DocxImageWrapMenuOption, type DocxImageWrapMode, type DocxImageWrapState, type DocxLineSpacingInfo, type DocxListType, type DocxPageLayoutInfo, type DocxPageThumbnailBounds, type DocxPageThumbnailItem, type DocxPageThumbnailResolution, type DocxPageThumbnailResolutionOptions, type DocxPageThumbnailStatus, type DocxPageVirtualizationOptions, type DocxPaginationInfo, type DocxSectionColumnLayout, type DocxSelectedFormField, type DocxTableContextMenuAction, type DocxTableContextMenuActionId, type DocxTableContextMenuContext, type DocxTableContextMenuRenderProps, type DocxTextRange, type DocxTextRangeLocation, type DocxTrackedChange, type DocxTrackedChangeCardRenderProps, type DocxTrackedChangeKind, type DocxViewerThumbnails, type DocxVisiblePageRange, type FooterSection, type FormFieldCheckboxWidgetSettings, type FormFieldDropdownWidgetSettings, type FormFieldOption, type FormFieldRunNode, type FormFieldSourceKind, type FormFieldTextWidgetSettings, type FormFieldType, type FormFieldWidgetSettings, type HeaderSection, type HeadingLevel, type ImageRunNode, type InsertParagraphOptions, type LayoutBlock, type LayoutFragmentSource, type LayoutImageRun, type LayoutOptions, type LayoutPage, type LayoutParagraphBlock, type LayoutRun, type LayoutSnapshot, type LayoutSnapshotBlockFragment, type LayoutSnapshotImageRun, type LayoutSnapshotMargins, type LayoutSnapshotOptions, type LayoutSnapshotPage, type LayoutSnapshotPageSize, type LayoutSnapshotParagraphFragment, type LayoutSnapshotRect, type LayoutSnapshotRun, type LayoutSnapshotTableCellFragment, type LayoutSnapshotTableFragment, type LayoutSnapshotTableRowFragment, type LayoutSnapshotTextRun, type LayoutTableBlock, type LayoutTableCell, type LayoutTableRow, type LayoutTextRun, type LegacyWasmOoxmlPackage, type LetterheadColumnSegmentGroup, type NumberingAbstractDefinition, type NumberingDefinitionSet, type NumberingInstanceDefinition, type NumberingLevelDefinition, type NumberingPictureBulletDefinition, type OoxmlPackage, type OoxmlPart, type OverflowBreakCollectionOptions, type PageSegmentationCallbacks, type PaginationSectionMetrics, type ParagraphAlignment, type ParagraphBorderSet, type ParagraphBorderStyle, type ParagraphChildNode, type ParagraphIndent, type ParagraphLineRange, type ParagraphNode, type ParagraphNumbering, type ParagraphSpacing, type ParagraphSplitControlOptions, type ParagraphStyle, type ParagraphStyleDefinition, type ParagraphTabStop, ReactDocxViewer, type ReactDocxViewerProps, type ResolvedDocument, type ResolvedDocumentSection, type ResolvedLayoutMetrics, type ResolvedModelSection, type TableBorderSet, type TableBorderStyle, type TableBoxSpacing, type TableCellContentNode, type TableCellNode, type TableCellStyle, type TableExplicitPageBreakInfo, type TableNode, type TableRowNode, type TableRowRange, type TableRowStyle, type TableStyle, type TextRunBorderStyle, type TextRunNode, type TextStyle, type UpdateTextOptions, type UseDocxBordersResult, type UseDocxDocumentThemeResult, type UseDocxEditorOptions, type UseDocxFormFieldsResult, type UseDocxImageWrapMenuResult, type UseDocxLineSpacingResult, type UseDocxModelState, type UseDocxPageLayoutResult, type UseDocxPageThumbnailsOptions, type UseDocxPageThumbnailsResult, type UseDocxPaginationResult, type UseDocxParagraphStylesResult, type UseDocxTrackChangesResult, type UseDocxViewerThumbnailsOptions, type WasmOoxmlPackage, type WasmSource, applyRunStyle, buildDocModel, buildDocModelFromBytes, buildDocumentPageNodeSegments, buildDocumentPageRanges, buildLayoutSnapshot, cloneDocModel, collectDocxEstimatedOverflowBreakStartNodeIndexes, collectDocxHardPageBreakStartNodeIndexes, collectDocxLastRenderedPageBreakStartNodeIndexes, collectTableExplicitPageBreakInfo, collectTopLevelExplicitPageBreakStartNodeIndexes, copyParagraphs, createMinimalDocxPackage, defaultStarterModel, duplicateParagraph, getPart, initWasm, insertParagraph, layoutDocument, modelToDocumentXml, normalizeDocModel, packageToArrayBuffer, paragraphAfterSpacingPx, paragraphBeforeSpacingPx, paragraphHasExplicitPageBreak, paragraphHasLastRenderedPageBreak, paragraphHasPageBreakBefore, paragraphLetterheadColumnGroupAtSegmentOffset, paragraphLetterheadFloatSideAtNodeIndex, paragraphStartsWithLastRenderedPageBreak, parseDocx, parseParagraphsFromClipboard, parseSectionLayout, pasteParagraphs, removeParagraph, replaceText, resolveDocumentForLayout, resolveDocumentLayout, resolveDocumentPageSegmentStartNodeIndex, resolveDocumentSectionsFromMetadata, resolveDocxPageThumbnailResolution, resolvePaginationSectionMetricsIndexForNodeIndex, resolveParagraphBeforeSpacingPx, resolveSectionIndexForNodeIndex, resolveSectionPropertiesXmlForNodeIndex, scalePaginationSectionMetricsHeights, scorePaginationAgainstStoredPageBreaks, sectionBreakAfterParagraphStartsNewPage, sectionBreakPropertiesStartNewPage, sectionTitlePageEnabled, selectSectionVariantForPage, serializeDocModel, serializeDocx, serializeParagraphsForClipboard, setParagraphAlignment, setParagraphHeading, setRunColor, setRunHighlight, setWasmSource, splitParagraphChildrenAtTextOffsets, toggleRunStyleFlag, updateParagraphText, updateTableCellParagraphText, updateTableCellParagraphTextRecursive, updateTableCellText, useDocxBorders, useDocxDocumentTheme, useDocxEditor, useDocxFormFields, useDocxImageWrapMenu, useDocxLineSpacing, useDocxModel, useDocxPageLayout, useDocxPageThumbnails, useDocxPagination, useDocxParagraphStyles, useDocxTrackChanges, useDocxViewerThumbnails, withPart };
1715
+ export { DEFAULT_MIN_PARAGRAPH_LINE_HEIGHT_PX, DEFAULT_PAGE_OVERFLOW_TOLERANCE_PX, type DocModel, type DocNode, type DocumentCommentDefinition, type DocumentCompatibilitySettings, type DocumentNoteDefinition, type DocumentPageNodeSegment, type DocumentPageRange, type DocumentPageSegmentationOptions, type DocumentSection, type DocxBorderContext, type DocxBorderPreset, type DocxBorderPresetState, type DocxComment, type DocxCommentCardRenderProps, type DocxContextMenuAction, type DocxContextMenuActionId, type DocxContextMenuContext, type DocxContextMenuRenderProps, type DocxDocumentTheme, type DocxEditorController, type DocxEditorSelection, DocxEditorViewer, type DocxEditorViewerMode, type DocxEditorViewerProps, type DocxFormFieldLocation, type DocxHeadingStyleMap, type DocxImageDropTarget, type DocxImageLocation, type DocxImageWrapMenuOption, type DocxImageWrapMode, type DocxImageWrapState, type DocxLineSpacingInfo, type DocxListType, type DocxPageLayoutInfo, type DocxPageThumbnailBounds, type DocxPageThumbnailItem, type DocxPageThumbnailResolution, type DocxPageThumbnailResolutionOptions, type DocxPageThumbnailStatus, type DocxPageVirtualizationOptions, type DocxPaginationInfo, type DocxSectionColumnLayout, type DocxSelectedFormField, type DocxTableContextMenuAction, type DocxTableContextMenuActionId, type DocxTableContextMenuContext, type DocxTableContextMenuRenderProps, type DocxTextRange, type DocxTextRangeLocation, type DocxTrackedChange, type DocxTrackedChangeCardRenderProps, type DocxTrackedChangeKind, type DocxViewerThumbnails, type DocxVisiblePageRange, type FooterSection, type FormFieldCheckboxWidgetSettings, type FormFieldDropdownWidgetSettings, type FormFieldOption, type FormFieldRunNode, type FormFieldSourceKind, type FormFieldTextWidgetSettings, type FormFieldType, type FormFieldWidgetSettings, type HeaderSection, type HeadingLevel, type ImageRunNode, type InsertParagraphOptions, type LayoutBlock, type LayoutFragmentSource, type LayoutImageRun, type LayoutOptions, type LayoutPage, type LayoutParagraphBlock, type LayoutRun, type LayoutSnapshot, type LayoutSnapshotBlockFragment, type LayoutSnapshotImageRun, type LayoutSnapshotMargins, type LayoutSnapshotOptions, type LayoutSnapshotPage, type LayoutSnapshotPageSize, type LayoutSnapshotParagraphFragment, type LayoutSnapshotRect, type LayoutSnapshotRun, type LayoutSnapshotTableCellFragment, type LayoutSnapshotTableFragment, type LayoutSnapshotTableRowFragment, type LayoutSnapshotTextRun, type LayoutTableBlock, type LayoutTableCell, type LayoutTableRow, type LayoutTextRun, type LegacyWasmOoxmlPackage, type LetterheadColumnSegmentGroup, type NumberingAbstractDefinition, type NumberingDefinitionSet, type NumberingInstanceDefinition, type NumberingLevelDefinition, type NumberingPictureBulletDefinition, type OoxmlPackage, type OoxmlPart, type OverflowBreakCollectionOptions, type PageSegmentationCallbacks, type PaginationSectionMetrics, type ParagraphAlignment, type ParagraphBorderSet, type ParagraphBorderStyle, type ParagraphChildNode, type ParagraphIndent, type ParagraphLineRange, type ParagraphNode, type ParagraphNumbering, type ParagraphSpacing, type ParagraphSplitControlOptions, type ParagraphStyle, type ParagraphStyleDefinition, type ParagraphTabStop, ReactDocxViewer, type ReactDocxViewerProps, type ResolvedDocument, type ResolvedDocumentSection, type ResolvedLayoutMetrics, type ResolvedModelSection, type TableBorderSet, type TableBorderStyle, type TableBoxSpacing, type TableCellContentNode, type TableCellNode, type TableCellStyle, type TableExplicitPageBreakInfo, type TableNode, type TableRowNode, type TableRowRange, type TableRowStyle, type TableStyle, type TextRunBorderStyle, type TextRunNode, type TextStyle, type UpdateTextOptions, type UseDocxBordersResult, type UseDocxCommentsResult, type UseDocxDocumentThemeResult, type UseDocxEditorOptions, type UseDocxFormFieldsResult, type UseDocxImageWrapMenuResult, type UseDocxLineSpacingResult, type UseDocxModelState, type UseDocxPageLayoutResult, type UseDocxPageThumbnailsOptions, type UseDocxPageThumbnailsResult, type UseDocxPaginationResult, type UseDocxParagraphStylesResult, type UseDocxTrackChangesResult, type UseDocxViewerThumbnailsOptions, type WasmOoxmlPackage, type WasmSource, applyRunStyle, buildDocModel, buildDocModelFromBytes, buildDocumentPageNodeSegments, buildDocumentPageRanges, buildLayoutSnapshot, cloneDocModel, collectDocxEstimatedOverflowBreakStartNodeIndexes, collectDocxHardPageBreakStartNodeIndexes, collectDocxLastRenderedPageBreakStartNodeIndexes, collectTableExplicitPageBreakInfo, collectTopLevelExplicitPageBreakStartNodeIndexes, copyParagraphs, createMinimalDocxPackage, defaultStarterModel, duplicateParagraph, getPart, initWasm, insertParagraph, layoutDocument, modelToDocumentXml, normalizeDocModel, packageToArrayBuffer, paragraphAfterSpacingPx, paragraphBeforeSpacingPx, paragraphHasExplicitPageBreak, paragraphHasLastRenderedPageBreak, paragraphHasPageBreakBefore, paragraphLetterheadColumnGroupAtSegmentOffset, paragraphLetterheadFloatSideAtNodeIndex, paragraphStartsWithLastRenderedPageBreak, parseDocx, parseParagraphsFromClipboard, parseSectionLayout, pasteParagraphs, removeParagraph, replaceText, resolveDocumentForLayout, resolveDocumentLayout, resolveDocumentPageSegmentStartNodeIndex, resolveDocumentSectionsFromMetadata, resolveDocxPageThumbnailResolution, resolvePaginationSectionMetricsIndexForNodeIndex, resolveParagraphBeforeSpacingPx, resolveSectionIndexForNodeIndex, resolveSectionPropertiesXmlForNodeIndex, scalePaginationSectionMetricsHeights, scorePaginationAgainstStoredPageBreaks, sectionBreakAfterParagraphStartsNewPage, sectionBreakPropertiesStartNewPage, sectionTitlePageEnabled, selectSectionVariantForPage, serializeDocModel, serializeDocx, serializeParagraphsForClipboard, setParagraphAlignment, setParagraphHeading, setRunColor, setRunHighlight, setWasmSource, splitParagraphChildrenAtTextOffsets, toggleRunStyleFlag, updateParagraphText, updateTableCellParagraphText, updateTableCellParagraphTextRecursive, updateTableCellText, useDocxBorders, useDocxComments, useDocxDocumentTheme, useDocxEditor, useDocxFormFields, useDocxImageWrapMenu, useDocxLineSpacing, useDocxModel, useDocxPageLayout, useDocxPageThumbnails, useDocxPagination, useDocxParagraphStyles, useDocxTrackChanges, useDocxViewerThumbnails, withPart };