@docx-editor.dev/editor-api 2.35.0-canary.20261104032723.sha-43c2012 → 2.35.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.
@@ -1,4 +1,4 @@
1
- import { AutomationHandle, AutomationSpan, AutomationOperation, AutomationValue, AutomationSpanRef, RevisionBatchResult, RevisionAuthorResult, AutomationStyleRead, DiagnosticCode, HistoryGroup, AutomationHost, AutomationCapabilities, AutomationPaginationOptions, ByteSizeBucket, DocumentOpenDiagnosticCode, DocumentPartKind, DiagnosticErrorName, EditDiagnosticCode, ReviewDiagnosticCode, ReviewOperation } from '@docx-editor.dev/core/automation';
1
+ import { AutomationHandle, AutomationSpan, AutomationOperation, AutomationValue, AutomationSpanRef, RevisionBatchResult, RevisionAuthorResult, AutomationStyleRead, DiagnosticCode, HistoryGroup, AutomationHost, AutomationCapabilities, AutomationPaginationOptions, ByteSizeBucket, DocumentOpenDiagnosticCode, DocumentPartKind, DiagnosticErrorName, EditDiagnosticCode, ReviewDiagnosticCode, ReviewOperation, CompareDocumentsEngine } from '@docx-editor.dev/core/automation';
2
2
  import { CollaborationModuleContribution } from '@docx-editor.dev/core/collaboration';
3
3
 
4
4
  /**
@@ -425,6 +425,43 @@ declare enum RemoveDocInfoType {
425
425
  template = "Template",
426
426
  versions = "Versions"
427
427
  }
428
+ /**
429
+ * Where a document compare puts its result. Only `CompareTargetCurrent` is supported: the
430
+ * revisions go into the document the call is made on.
431
+ *
432
+ * @public
433
+ */
434
+ declare enum CompareTarget {
435
+ compareTargetCurrent = "CompareTargetCurrent",
436
+ compareTargetNew = "CompareTargetNew",
437
+ compareTargetSelected = "CompareTargetSelected"
438
+ }
439
+ /**
440
+ * Options of `Document.compareFromBase64`.
441
+ *
442
+ * Supported: `authorName`, `compareTarget` (`CompareTargetCurrent` only), `detectFormatChanges`,
443
+ * and `removeDateAndTime`. `addToRecentFiles` and `ignoreAllComparisonWarnings` are accepted
444
+ * and have no effect: there is no recent-files list and no warning prompt. `true` for
445
+ * `removePersonalInformation` refuses with `NotSupported`.
446
+ *
447
+ * @public
448
+ */
449
+ interface DocumentCompareOptions {
450
+ /** Accepted; there is no recent-files list. Default `true`. */
451
+ addToRecentFiles?: boolean;
452
+ /** Author of the revisions. Default: the revised document's author, else `Comparison`. */
453
+ authorName?: string;
454
+ /** Where the result goes. Default and only supported value: `CompareTargetCurrent`. */
455
+ compareTarget?: CompareTarget | 'CompareTargetCurrent' | 'CompareTargetNew' | 'CompareTargetSelected';
456
+ /** Record formatting differences as revisions. Default `true`. */
457
+ detectFormatChanges?: boolean;
458
+ /** Accepted; there is no warning prompt. Default `false`. */
459
+ ignoreAllComparisonWarnings?: boolean;
460
+ /** Write the revisions without dates. Default `false`. */
461
+ removeDateAndTime?: boolean;
462
+ /** `true` refuses with `NotSupported`. Default `false`. */
463
+ removePersonalInformation?: boolean;
464
+ }
428
465
 
429
466
  /** What the object is, which is what decides how its characters are named. */
430
467
  type SpanOwner = 'body' | 'paragraph' | 'span';
@@ -2750,6 +2787,26 @@ declare class Document extends ModelObject {
2750
2787
  */
2751
2788
  removeDocumentInformation(removeDocInfoType: RemoveDocInfoType): void;
2752
2789
  removeDocumentInformation(removeDocInfoType: 'Comments' | 'Revisions' | 'Versions' | 'RemovePersonalInformation' | 'EmailHeader' | 'RoutingSlip' | 'SendForReview' | 'DocumentProperties' | 'Template' | 'DocumentWorkspace' | 'InkAnnotations' | 'DocumentServerProperties' | 'DocumentManagementPolicy' | 'ContentType' | 'TaskpaneWebExtensions' | 'AtMentions' | 'DocumentTasks' | 'DocumentIntelligence' | 'CommentReactions' | 'All'): void;
2790
+ /**
2791
+ * Compare this document (the original) with the revised document in `base64File`, and record
2792
+ * the differences as tracked changes in this document.
2793
+ *
2794
+ * Needs the review module (`modules: [reviewModule()]` from `@docx-editor.dev/pro`); without
2795
+ * it the sync fails with `NotSupported`. Only `CompareTargetCurrent` is supported. Must be the
2796
+ * only write in its sync. Refused in a collaboration session.
2797
+ *
2798
+ * @example
2799
+ * ```ts
2800
+ * context.document.compareFromBase64(revisedBase64, { authorName: 'Legal' });
2801
+ * await context.sync();
2802
+ * ```
2803
+ */
2804
+ compareFromBase64(base64File: string, documentCompareOptions?: DocumentCompareOptions): void;
2805
+ /**
2806
+ * Refuses with `NotSupported` at the sync: the document model has no file system. Read the
2807
+ * file yourself and call {@link Document.compareFromBase64}.
2808
+ */
2809
+ compare(filePath: string, documentCompareOptions?: DocumentCompareOptions): void;
2753
2810
  /** Core document metadata. Reads require load; writes commit at sync. */
2754
2811
  get properties(): DocumentProperties;
2755
2812
  /**
@@ -4100,6 +4157,13 @@ type RuntimeDiagnostic = {
4100
4157
  interface EditorModule {
4101
4158
  readonly id: string;
4102
4159
  readonly collaboration?: CollaborationModuleContribution;
4160
+ /**
4161
+ * Review contribution. Its compare engine enables `Document.compareFromBase64`; the rest of
4162
+ * the contribution is ignored here.
4163
+ */
4164
+ readonly review?: {
4165
+ readonly compareDocuments?: CompareDocumentsEngine;
4166
+ };
4103
4167
  /**
4104
4168
  * Told about this runtime's anonymous diagnostics: the open, and each refused batch with a
4105
4169
  * known reason. A telemetry module's listener fits here unchanged.
@@ -4189,5 +4253,5 @@ interface CreateServerOptions {
4189
4253
  /** Options for {@link createCollaborative}. @public */
4190
4254
  type CreateCollaborativeOptions = CreateServerOptions;
4191
4255
 
4192
- export { ListItem as $, Alignment as A, DocumentProperties as F, DocxEditorError as J, Field as P, FieldCollection as Q, FieldType as R, Font as T, InlinePicture as V, InlinePictureCollection as W, InsertLocation as X, List as Y, ListBullet as Z, ListCollection as _, ListNumbering as a0, NoteItem as a3, NoteItemCollection as a4, PageOrientation as a6, PageSetup as a7, Paragraph as a8, ShapeType as aA, Style as aB, StyleCollection as aC, StyleType as aD, Table as aE, TableCell as aF, TableCellCollection as aG, TableCollection as aH, TableRow as aI, TableRowCollection as aJ, TrackedObjects as aK, UnderlineType as aL, VerticalAlignment as aM, getReviewItemRange as aN, getReviewItemRangeOrNullObject as aO, getReviewItemRevisions as aP, isDocxEditorError as aQ, ParagraphCollection as aa, Range as ae, RangeCollection as af, RangeLocation as ah, RemoveDocInfoType as ai, RequestContext as aj, Revision as ak, RevisionCollection as an, Section as au, SectionCollection as av, Shape as ay, ShapeCollection as az, Body as b, Bookmark as e, BookmarkCollection as f, BreakType as g, ChangeTrackingMode as h, ChangeTrackingVersion as i, ClientObject as j, ClientResult as k, Comment as l, CommentCollection as m, CommentReply as n, CommentReplyCollection as o, ContentControl as q, ContentControlCollection as r, ContentControlType as u, Document as w };
4193
- export type { BesideLocation as B, CreateServerOptions as C, DocxEditorServerRuntime as D, DocumentPreviewStatus as E, DocumentXmlLimits as G, DocumentZipLimits as H, DocxEditorDebugInfo as I, DocxEditorErrorCode as K, DocxEditorErrorInit as L, DocxEditorInnerError as M, DocxEditorRuntime as N, EditorModule as O, FieldTypeLiteral as S, HeaderFooterType as U, CreateCollaborativeOptions as a, LoadOption as a1, LoadQueryOptions as a2, NoteItemType as a5, ParagraphAlignment as a9, ParagraphInsertTextLocation as ab, ParagraphReadingOrder as ac, PreviewCallback as ad, RangeInsertTextLocation as ag, RevisionAuthorOptions as al, RevisionAuthorSelection as am, RevisionTextView as ao, RevisionType as ap, RunCallback as aq, RunOptions as ar, RuntimeDiagnostic as as, SearchOptions as at, SelectionMode as aw, ServerPaginationOptions as ax, BodyInsertParagraphLocation as c, BodyInsertTextLocation as d, CommitPreviewOptions as p, ContentControlLockState as s, ContentControlSubtype as t, ContentControlValue as v, DocumentCapabilities as x, DocumentLimits as y, DocumentPreview as z };
4256
+ export { ListBullet as $, Alignment as A, DocumentProperties as H, DocxEditorError as L, Field as R, FieldCollection as S, FieldType as T, Font as V, InlinePicture as X, InlinePictureCollection as Y, InsertLocation as Z, List as _, ListCollection as a0, ListItem as a1, ListNumbering as a2, NoteItem as a5, NoteItemCollection as a6, PageOrientation as a8, PageSetup as a9, Shape as aA, ShapeCollection as aB, ShapeType as aC, Style as aD, StyleCollection as aE, StyleType as aF, Table as aG, TableCell as aH, TableCellCollection as aI, TableCollection as aJ, TableRow as aK, TableRowCollection as aL, TrackedObjects as aM, UnderlineType as aN, VerticalAlignment as aO, getReviewItemRange as aP, getReviewItemRangeOrNullObject as aQ, getReviewItemRevisions as aR, isDocxEditorError as aS, Paragraph as aa, ParagraphCollection as ac, Range as ag, RangeCollection as ah, RangeLocation as aj, RemoveDocInfoType as ak, RequestContext as al, Revision as am, RevisionCollection as ap, Section as aw, SectionCollection as ax, Body as b, Bookmark as e, BookmarkCollection as f, BreakType as g, ChangeTrackingMode as h, ChangeTrackingVersion as i, ClientObject as j, ClientResult as k, Comment as l, CommentCollection as m, CommentReply as n, CommentReplyCollection as o, CompareTarget as q, ContentControl as r, ContentControlCollection as s, ContentControlType as v, Document as x };
4257
+ export type { BesideLocation as B, CreateServerOptions as C, DocxEditorServerRuntime as D, DocumentLimits as E, DocumentPreview as F, DocumentPreviewStatus as G, DocumentXmlLimits as I, DocumentZipLimits as J, DocxEditorDebugInfo as K, DocxEditorErrorCode as M, DocxEditorErrorInit as N, DocxEditorInnerError as O, DocxEditorRuntime as P, EditorModule as Q, FieldTypeLiteral as U, HeaderFooterType as W, CreateCollaborativeOptions as a, LoadOption as a3, LoadQueryOptions as a4, NoteItemType as a7, ParagraphAlignment as ab, ParagraphInsertTextLocation as ad, ParagraphReadingOrder as ae, PreviewCallback as af, RangeInsertTextLocation as ai, RevisionAuthorOptions as an, RevisionAuthorSelection as ao, RevisionTextView as aq, RevisionType as ar, RunCallback as as, RunOptions as at, RuntimeDiagnostic as au, SearchOptions as av, SelectionMode as ay, ServerPaginationOptions as az, BodyInsertParagraphLocation as c, BodyInsertTextLocation as d, CommitPreviewOptions as p, ContentControlLockState as t, ContentControlSubtype as u, ContentControlValue as w, DocumentCapabilities as y, DocumentCompareOptions as z };
@@ -1,4 +1,4 @@
1
- import { AutomationHandle, AutomationSpan, AutomationOperation, AutomationValue, AutomationSpanRef, RevisionBatchResult, RevisionAuthorResult, AutomationStyleRead, DiagnosticCode, HistoryGroup, AutomationHost, AutomationCapabilities, AutomationPaginationOptions, ByteSizeBucket, DocumentOpenDiagnosticCode, DocumentPartKind, DiagnosticErrorName, EditDiagnosticCode, ReviewDiagnosticCode, ReviewOperation } from '@docx-editor.dev/core/automation';
1
+ import { AutomationHandle, AutomationSpan, AutomationOperation, AutomationValue, AutomationSpanRef, RevisionBatchResult, RevisionAuthorResult, AutomationStyleRead, DiagnosticCode, HistoryGroup, AutomationHost, AutomationCapabilities, AutomationPaginationOptions, ByteSizeBucket, DocumentOpenDiagnosticCode, DocumentPartKind, DiagnosticErrorName, EditDiagnosticCode, ReviewDiagnosticCode, ReviewOperation, CompareDocumentsEngine } from '@docx-editor.dev/core/automation';
2
2
  import { CollaborationModuleContribution } from '@docx-editor.dev/core/collaboration';
3
3
 
4
4
  /**
@@ -425,6 +425,43 @@ declare enum RemoveDocInfoType {
425
425
  template = "Template",
426
426
  versions = "Versions"
427
427
  }
428
+ /**
429
+ * Where a document compare puts its result. Only `CompareTargetCurrent` is supported: the
430
+ * revisions go into the document the call is made on.
431
+ *
432
+ * @public
433
+ */
434
+ declare enum CompareTarget {
435
+ compareTargetCurrent = "CompareTargetCurrent",
436
+ compareTargetNew = "CompareTargetNew",
437
+ compareTargetSelected = "CompareTargetSelected"
438
+ }
439
+ /**
440
+ * Options of `Document.compareFromBase64`.
441
+ *
442
+ * Supported: `authorName`, `compareTarget` (`CompareTargetCurrent` only), `detectFormatChanges`,
443
+ * and `removeDateAndTime`. `addToRecentFiles` and `ignoreAllComparisonWarnings` are accepted
444
+ * and have no effect: there is no recent-files list and no warning prompt. `true` for
445
+ * `removePersonalInformation` refuses with `NotSupported`.
446
+ *
447
+ * @public
448
+ */
449
+ interface DocumentCompareOptions {
450
+ /** Accepted; there is no recent-files list. Default `true`. */
451
+ addToRecentFiles?: boolean;
452
+ /** Author of the revisions. Default: the revised document's author, else `Comparison`. */
453
+ authorName?: string;
454
+ /** Where the result goes. Default and only supported value: `CompareTargetCurrent`. */
455
+ compareTarget?: CompareTarget | 'CompareTargetCurrent' | 'CompareTargetNew' | 'CompareTargetSelected';
456
+ /** Record formatting differences as revisions. Default `true`. */
457
+ detectFormatChanges?: boolean;
458
+ /** Accepted; there is no warning prompt. Default `false`. */
459
+ ignoreAllComparisonWarnings?: boolean;
460
+ /** Write the revisions without dates. Default `false`. */
461
+ removeDateAndTime?: boolean;
462
+ /** `true` refuses with `NotSupported`. Default `false`. */
463
+ removePersonalInformation?: boolean;
464
+ }
428
465
 
429
466
  /** What the object is, which is what decides how its characters are named. */
430
467
  type SpanOwner = 'body' | 'paragraph' | 'span';
@@ -2750,6 +2787,26 @@ declare class Document extends ModelObject {
2750
2787
  */
2751
2788
  removeDocumentInformation(removeDocInfoType: RemoveDocInfoType): void;
2752
2789
  removeDocumentInformation(removeDocInfoType: 'Comments' | 'Revisions' | 'Versions' | 'RemovePersonalInformation' | 'EmailHeader' | 'RoutingSlip' | 'SendForReview' | 'DocumentProperties' | 'Template' | 'DocumentWorkspace' | 'InkAnnotations' | 'DocumentServerProperties' | 'DocumentManagementPolicy' | 'ContentType' | 'TaskpaneWebExtensions' | 'AtMentions' | 'DocumentTasks' | 'DocumentIntelligence' | 'CommentReactions' | 'All'): void;
2790
+ /**
2791
+ * Compare this document (the original) with the revised document in `base64File`, and record
2792
+ * the differences as tracked changes in this document.
2793
+ *
2794
+ * Needs the review module (`modules: [reviewModule()]` from `@docx-editor.dev/pro`); without
2795
+ * it the sync fails with `NotSupported`. Only `CompareTargetCurrent` is supported. Must be the
2796
+ * only write in its sync. Refused in a collaboration session.
2797
+ *
2798
+ * @example
2799
+ * ```ts
2800
+ * context.document.compareFromBase64(revisedBase64, { authorName: 'Legal' });
2801
+ * await context.sync();
2802
+ * ```
2803
+ */
2804
+ compareFromBase64(base64File: string, documentCompareOptions?: DocumentCompareOptions): void;
2805
+ /**
2806
+ * Refuses with `NotSupported` at the sync: the document model has no file system. Read the
2807
+ * file yourself and call {@link Document.compareFromBase64}.
2808
+ */
2809
+ compare(filePath: string, documentCompareOptions?: DocumentCompareOptions): void;
2753
2810
  /** Core document metadata. Reads require load; writes commit at sync. */
2754
2811
  get properties(): DocumentProperties;
2755
2812
  /**
@@ -4100,6 +4157,13 @@ type RuntimeDiagnostic = {
4100
4157
  interface EditorModule {
4101
4158
  readonly id: string;
4102
4159
  readonly collaboration?: CollaborationModuleContribution;
4160
+ /**
4161
+ * Review contribution. Its compare engine enables `Document.compareFromBase64`; the rest of
4162
+ * the contribution is ignored here.
4163
+ */
4164
+ readonly review?: {
4165
+ readonly compareDocuments?: CompareDocumentsEngine;
4166
+ };
4103
4167
  /**
4104
4168
  * Told about this runtime's anonymous diagnostics: the open, and each refused batch with a
4105
4169
  * known reason. A telemetry module's listener fits here unchanged.
@@ -4189,5 +4253,5 @@ interface CreateServerOptions {
4189
4253
  /** Options for {@link createCollaborative}. @public */
4190
4254
  type CreateCollaborativeOptions = CreateServerOptions;
4191
4255
 
4192
- export { ListItem as $, Alignment as A, DocumentProperties as F, DocxEditorError as J, Field as P, FieldCollection as Q, FieldType as R, Font as T, InlinePicture as V, InlinePictureCollection as W, InsertLocation as X, List as Y, ListBullet as Z, ListCollection as _, ListNumbering as a0, NoteItem as a3, NoteItemCollection as a4, PageOrientation as a6, PageSetup as a7, Paragraph as a8, ShapeType as aA, Style as aB, StyleCollection as aC, StyleType as aD, Table as aE, TableCell as aF, TableCellCollection as aG, TableCollection as aH, TableRow as aI, TableRowCollection as aJ, TrackedObjects as aK, UnderlineType as aL, VerticalAlignment as aM, getReviewItemRange as aN, getReviewItemRangeOrNullObject as aO, getReviewItemRevisions as aP, isDocxEditorError as aQ, ParagraphCollection as aa, Range as ae, RangeCollection as af, RangeLocation as ah, RemoveDocInfoType as ai, RequestContext as aj, Revision as ak, RevisionCollection as an, Section as au, SectionCollection as av, Shape as ay, ShapeCollection as az, Body as b, Bookmark as e, BookmarkCollection as f, BreakType as g, ChangeTrackingMode as h, ChangeTrackingVersion as i, ClientObject as j, ClientResult as k, Comment as l, CommentCollection as m, CommentReply as n, CommentReplyCollection as o, ContentControl as q, ContentControlCollection as r, ContentControlType as u, Document as w };
4193
- export type { BesideLocation as B, CreateServerOptions as C, DocxEditorServerRuntime as D, DocumentPreviewStatus as E, DocumentXmlLimits as G, DocumentZipLimits as H, DocxEditorDebugInfo as I, DocxEditorErrorCode as K, DocxEditorErrorInit as L, DocxEditorInnerError as M, DocxEditorRuntime as N, EditorModule as O, FieldTypeLiteral as S, HeaderFooterType as U, CreateCollaborativeOptions as a, LoadOption as a1, LoadQueryOptions as a2, NoteItemType as a5, ParagraphAlignment as a9, ParagraphInsertTextLocation as ab, ParagraphReadingOrder as ac, PreviewCallback as ad, RangeInsertTextLocation as ag, RevisionAuthorOptions as al, RevisionAuthorSelection as am, RevisionTextView as ao, RevisionType as ap, RunCallback as aq, RunOptions as ar, RuntimeDiagnostic as as, SearchOptions as at, SelectionMode as aw, ServerPaginationOptions as ax, BodyInsertParagraphLocation as c, BodyInsertTextLocation as d, CommitPreviewOptions as p, ContentControlLockState as s, ContentControlSubtype as t, ContentControlValue as v, DocumentCapabilities as x, DocumentLimits as y, DocumentPreview as z };
4256
+ export { ListBullet as $, Alignment as A, DocumentProperties as H, DocxEditorError as L, Field as R, FieldCollection as S, FieldType as T, Font as V, InlinePicture as X, InlinePictureCollection as Y, InsertLocation as Z, List as _, ListCollection as a0, ListItem as a1, ListNumbering as a2, NoteItem as a5, NoteItemCollection as a6, PageOrientation as a8, PageSetup as a9, Shape as aA, ShapeCollection as aB, ShapeType as aC, Style as aD, StyleCollection as aE, StyleType as aF, Table as aG, TableCell as aH, TableCellCollection as aI, TableCollection as aJ, TableRow as aK, TableRowCollection as aL, TrackedObjects as aM, UnderlineType as aN, VerticalAlignment as aO, getReviewItemRange as aP, getReviewItemRangeOrNullObject as aQ, getReviewItemRevisions as aR, isDocxEditorError as aS, Paragraph as aa, ParagraphCollection as ac, Range as ag, RangeCollection as ah, RangeLocation as aj, RemoveDocInfoType as ak, RequestContext as al, Revision as am, RevisionCollection as ap, Section as aw, SectionCollection as ax, Body as b, Bookmark as e, BookmarkCollection as f, BreakType as g, ChangeTrackingMode as h, ChangeTrackingVersion as i, ClientObject as j, ClientResult as k, Comment as l, CommentCollection as m, CommentReply as n, CommentReplyCollection as o, CompareTarget as q, ContentControl as r, ContentControlCollection as s, ContentControlType as v, Document as x };
4257
+ export type { BesideLocation as B, CreateServerOptions as C, DocxEditorServerRuntime as D, DocumentLimits as E, DocumentPreview as F, DocumentPreviewStatus as G, DocumentXmlLimits as I, DocumentZipLimits as J, DocxEditorDebugInfo as K, DocxEditorErrorCode as M, DocxEditorErrorInit as N, DocxEditorInnerError as O, DocxEditorRuntime as P, EditorModule as Q, FieldTypeLiteral as U, HeaderFooterType as W, CreateCollaborativeOptions as a, LoadOption as a3, LoadQueryOptions as a4, NoteItemType as a7, ParagraphAlignment as ab, ParagraphInsertTextLocation as ad, ParagraphReadingOrder as ae, PreviewCallback as af, RangeInsertTextLocation as ai, RevisionAuthorOptions as an, RevisionAuthorSelection as ao, RevisionTextView as aq, RevisionType as ar, RunCallback as as, RunOptions as at, RuntimeDiagnostic as au, SearchOptions as av, SelectionMode as ay, ServerPaginationOptions as az, BodyInsertParagraphLocation as c, BodyInsertTextLocation as d, CommitPreviewOptions as p, ContentControlLockState as t, ContentControlSubtype as u, ContentControlValue as w, DocumentCapabilities as y, DocumentCompareOptions as z };
@@ -2,7 +2,11 @@
2
2
 
3
3
  # Accept or reject without scrolling
4
4
 
5
- When your own list drives the scroll, open an item with `useReview().setActive(key, { reveal: false })`. The caret moves to the item, and the page stays where it is. Then resolve the item with `accept(item)` or `reject(item)`. Review writes such as accept, reject, and comment never scroll the page.
5
+ Resolve a tracked change from your own list with `useReview().accept(item)` or `reject(item)`. Review writes such as accept, reject, and comment never scroll the page, and they need no prior activation.
6
+
7
+ ## Resolve a change without scrolling
8
+
9
+ The following row opens its item without scrolling and resolves it from two buttons:
6
10
 
7
11
  **React**
8
12
 
@@ -10,35 +14,22 @@ When your own list drives the scroll, open an item with `useReview().setActive(k
10
14
  import { useReview, type ReviewItemView } from '@docx-editor.dev/pro/react';
11
15
 
12
16
  export function ChangeRow({ item }: { item: ReviewItemView }) {
13
- const { setActive, accept, reject } = useReview();
17
+ const { setActive, accept, reject, lastRefusal } = useReview();
14
18
  return (
15
- <li onClick={() => setActive(item.key, { reveal: false })}>
16
- {item.text}
17
- <button
18
- disabled={item.readOnly}
19
- onClick={(event) => {
20
- event.stopPropagation();
21
- accept(item);
22
- }}
23
- >
19
+ <li>
20
+ <button onClick={() => setActive(item.key, { reveal: false })}>{item.text}</button>
21
+ <button disabled={item.readOnly} onClick={() => accept(item)}>
24
22
  Accept
25
23
  </button>
26
- <button
27
- disabled={item.readOnly}
28
- onClick={(event) => {
29
- event.stopPropagation();
30
- reject(item);
31
- }}
32
- >
24
+ <button disabled={item.readOnly} onClick={() => reject(item)}>
33
25
  Reject
34
26
  </button>
27
+ {lastRefusal?.key === item.key && <p role="alert">{lastRefusal.code}</p>}
35
28
  </li>
36
29
  );
37
30
  }
38
31
  ```
39
32
 
40
- `accept` and `reject` return `false` when the editor refuses the decision, for example in viewing mode. Read `useReview().lastRefusal` for the diagnostic code.
41
-
42
33
  **Vue**
43
34
 
44
35
  ```vue
@@ -46,23 +37,24 @@ export function ChangeRow({ item }: { item: ReviewItemView }) {
46
37
  import { useReview, type ReviewItemView } from '@docx-editor.dev/pro/vue';
47
38
 
48
39
  defineProps<{ item: ReviewItemView }>();
49
- const { setActive, accept, reject } = useReview();
40
+ const { setActive, accept, reject, lastRefusal } = useReview();
50
41
  </script>
51
42
 
52
43
  <template>
53
- <li @click="setActive(item.key, { reveal: false })">
54
- {{ item.text }}
55
- <button :disabled="item.readOnly" @click.stop="accept(item)">Accept</button>
56
- <button :disabled="item.readOnly" @click.stop="reject(item)">Reject</button>
44
+ <li>
45
+ <button @click="setActive(item.key, { reveal: false })">{{ item.text }}</button>
46
+ <button :disabled="item.readOnly" @click="accept(item)">Accept</button>
47
+ <button :disabled="item.readOnly" @click="reject(item)">Reject</button>
48
+ <p v-if="lastRefusal?.key === item.key" role="alert">{{ lastRefusal.code }}</p>
57
49
  </li>
58
50
  </template>
59
51
  ```
60
52
 
61
- `accept` and `reject` return `false` when the editor refuses the decision, for example in viewing mode. `useReview()` returns `lastRefusal` as a ref, so read `lastRefusal.value?.code` in script, or `lastRefusal?.code` in the template.
53
+ `accept` and `reject` return `false` when the editor refuses the decision, for example in viewing mode. `lastRefusal` holds the item key and the diagnostic code. In Vue it is a ref, so read `lastRefusal.value?.code` in script.
62
54
 
63
- The buttons stop the click from reaching the row, so a decision does not also activate the item.
55
+ ## Activate without scrolling
64
56
 
65
- `reveal` takes `false` or one of four placements:
57
+ `setActive(key, { reveal: false })` moves the caret to the item and keeps the scroll position. `reveal` takes `false` or one of four placements:
66
58
 
67
59
  | Value | Where the item lands |
68
60
  | --- | --- |
@@ -73,23 +65,14 @@ The buttons stop the click from reaching the row, so a decision does not also ac
73
65
 
74
66
  Add `announce: true` to open the packaged balloon or card for the item.
75
67
 
76
- ## Decide in a headless pipeline
77
-
78
- The editing API has no viewport. Load the revisions and call `Revision.accept()` or `Revision.reject()`.
79
-
80
- ```ts
81
- import { DocxEditor } from '@docx-editor.dev/editor-api';
82
-
83
- const runtime = await DocxEditor.createServer(bytes, { author: 'Review bot' });
84
- await runtime.run(async (context) => {
85
- const revisions = context.document.body.revisions;
86
- revisions.load('items/author');
87
- await context.sync();
88
- for (const revision of revisions.items) {
89
- if (revision.author === 'Review bot') revision.accept();
90
- }
91
- await context.sync();
92
- });
93
- const saved = await runtime.save();
94
- runtime.dispose();
95
- ```
68
+ ## Limits
69
+
70
+ - Disable the decision buttons for items where `item.readOnly` is `true`.
71
+ - If the whole row is clickable, stop button clicks from reaching it, so a decision does not also activate the item.
72
+ - Headless pipelines have no viewport. To decide changes on a server, call `Revision.accept()` or `Revision.reject()`. For more information, see [Tracked changes](https://www.docx-editor.dev/docs/2.x/editor-api/revisions).
73
+
74
+ ## See also
75
+
76
+ - [Tracked changes](https://www.docx-editor.dev/docs/2.x/pro/tracked-changes)
77
+ - [Diagnostics](https://www.docx-editor.dev/docs/2.x/guides/diagnostics)
78
+ - [Custom cards in the review rail](./custom-review-cards.md)
@@ -2,71 +2,95 @@
2
2
 
3
3
  # Comment on found text
4
4
 
5
- In a browser host, find the text with `editor.findMatches`, select the first match with `editor.selectMatch`, and then call `useReview().comment`. The comment is written as the editor's `author`, so set `author` on the editor and add `reviewModule()` to its modules. `selectMatch` opens the header, footer, or note that holds the match, so a match in any story works.
5
+ Find text with `editor.findMatches`, select a match with `editor.selectMatch`, and comment with `useReview().comment`. On a server, search with `body.search` and call `Range.insertComment`.
6
+
7
+ ## Comment on a search result
8
+
9
+ The following button comments on the first whole-word match of a term. The editor needs an `author` and `reviewModule()` in its modules.
6
10
 
7
11
  **React**
8
12
 
9
13
  ```tsx
14
+ import { useState } from 'react';
10
15
  import { useDocxEditor } from '@docx-editor.dev/react';
11
16
  import { useReview } from '@docx-editor.dev/pro/react';
12
17
 
13
18
  export function CommentOnTerm({ term }: { term: string }) {
14
19
  const editor = useDocxEditor();
15
- const { comment } = useReview();
20
+ const { comment, lastRefusal } = useReview();
21
+ const [status, setStatus] = useState('');
16
22
  const run = () => {
17
23
  const [match] = editor?.findMatches(term, { wholeWord: true }) ?? [];
18
- if (match && editor?.selectMatch(match).ok) comment(`Define "${term}".`);
24
+ if (!match || !editor?.selectMatch(match).ok) return setStatus('No match');
25
+ setStatus(comment(`Define "${term}".`) ? '' : 'Refused');
19
26
  };
20
- return <button onClick={run}>Comment on {term}</button>;
27
+ return (
28
+ <>
29
+ <button onClick={run}>Comment on {term}</button>
30
+ {/* lastRefusal updates on the next render, so read it here. */}
31
+ <span role="status">{status === 'Refused' ? lastRefusal?.code : status}</span>
32
+ </>
33
+ );
21
34
  }
22
35
  ```
23
36
 
24
- `comment` returns `false` when the editor refuses the write. Read `useReview().lastRefusal` for the diagnostic code.
25
-
26
37
  **Vue**
27
38
 
28
39
  ```vue
29
40
  <script setup lang="ts">
41
+ import { ref } from 'vue';
30
42
  import { useDocxEditor } from '@docx-editor.dev/vue';
31
43
  import { useReview } from '@docx-editor.dev/pro/vue';
32
44
 
33
45
  const props = defineProps<{ term: string }>();
34
46
  const editor = useDocxEditor();
35
- const { comment } = useReview();
47
+ const { comment, lastRefusal } = useReview();
48
+ const status = ref('');
36
49
  function run() {
37
50
  const [match] = editor.value?.findMatches(props.term, { wholeWord: true }) ?? [];
38
- if (match && editor.value?.selectMatch(match).ok) comment(`Define "${props.term}".`);
51
+ if (!match || !editor.value?.selectMatch(match).ok) {
52
+ status.value = 'No match';
53
+ return;
54
+ }
55
+ if (!comment(`Define "${props.term}".`)) status.value = lastRefusal.value?.code ?? 'Refused';
39
56
  }
40
57
  </script>
41
58
 
42
59
  <template>
43
60
  <button @click="run">Comment on {{ term }}</button>
61
+ <span role="status">{{ status }}</span>
44
62
  </template>
45
63
  ```
46
64
 
47
- `comment` returns `false` when the editor refuses the write. `useReview()` returns `lastRefusal` as a ref, so read `lastRefusal.value?.code` in script, or `lastRefusal?.code` in the template.
65
+ Comment only after `selectMatch(match).ok` is `true`. `selectMatch` opens the header, footer, or note that holds the match. `comment` returns `false` when the editor refuses the write, and `lastRefusal` holds the diagnostic code.
48
66
 
49
- ## Comment in a headless pipeline
67
+ ## Comment on a server
50
68
 
51
- On a server or in an agent pipeline, search the body and call `Range.insertComment`. The runtime writes the comment as its `author` option.
69
+ The following example searches the body, not every story, and saves the result:
52
70
 
53
71
  ```ts
54
72
  import { DocxEditor } from '@docx-editor.dev/editor-api';
55
73
 
56
74
  const runtime = await DocxEditor.createServer(bytes, { author: 'Review bot' });
57
- await runtime.run(async (context) => {
58
- const found = context.document.body.search(term, { matchWholeWord: true });
59
- found.load('items');
60
- await context.sync();
61
- found.items[0]?.insertComment(`Define "${term}".`);
62
- await context.sync();
63
- });
64
- const saved = await runtime.save();
65
- runtime.dispose();
75
+ try {
76
+ await runtime.run(async (context) => {
77
+ const found = context.document.body.search(term, { matchWholeWord: true });
78
+ found.load('items');
79
+ await context.sync();
80
+ if (found.items.length === 0) return;
81
+ found.items[0]!.insertComment(`Define "${term}".`);
82
+ await context.sync();
83
+ });
84
+ const saved = await runtime.save();
85
+ } finally {
86
+ runtime.dispose();
87
+ }
66
88
  ```
67
89
 
68
- Both paths save the same comment markup: the same `w:comment` attributes, the same date format, and the same range markers.
90
+ Load the search results before you read them, and end with `await context.sync()` to send the queued comment. The runtime writes the comment as its `author` option.
69
91
 
70
- ## Reply to a thread
92
+ ## See also
71
93
 
72
- To answer an existing comment, call `useReview().reply(item, text)` in a browser host, or `Comment.reply(text)` in the editing API.
94
+ - [Comments](https://www.docx-editor.dev/docs/2.x/pro/comments)
95
+ - [Diagnostics](https://www.docx-editor.dev/docs/2.x/guides/diagnostics)
96
+ - [Replace as a tracked change](./tracked-replacement.md)
@@ -2,9 +2,11 @@
2
2
 
3
3
  # Custom cards in the review rail
4
4
 
5
- To draw your own cards, render `DocxEditorReview` with `preset` set to `false` and put your card component inside it. Your component reads the items from `useReview()`, measures each card, stacks the cards with `useStackedReviewPositions`, and converts positions to pixels with `useReviewRailMetrics()`.
5
+ Render `DocxEditorReview` with `preset` set to `false` and put your card component inside it. The component reads items from `useReview()`, stacks measured cards with `useStackedReviewPositions`, and converts positions to pixels with `useReviewRailMetrics()`.
6
6
 
7
- Measure every card with a `ResizeObserver` and pass the heights in CSS pixels. Without measured heights, each card reserves only `defaultHeight`, and a taller card overlaps the next one.
7
+ ## Render custom cards
8
+
9
+ The following example measures each card with a `ResizeObserver`, stacks the cards, and shows a refused decision:
8
10
 
9
11
  **React**
10
12
 
@@ -19,17 +21,8 @@ import {
19
21
 
20
22
  type OnHeight = (key: string, height: number) => void;
21
23
 
22
- function MeasuredCard({
23
- id,
24
- top,
25
- onHeight,
26
- children,
27
- }: {
28
- id: string;
29
- top: number;
30
- onHeight: OnHeight;
31
- children: ReactNode;
32
- }) {
24
+ function MeasuredCard(props: { id: string; top: number; onHeight: OnHeight; children: ReactNode }) {
25
+ const { id, top, onHeight, children } = props;
33
26
  const ref = useRef<HTMLDivElement>(null);
34
27
  useEffect(() => {
35
28
  const node = ref.current!;
@@ -45,8 +38,9 @@ function MeasuredCard({
45
38
  }
46
39
 
47
40
  function MyCards() {
48
- const { items, selectionAnchorY, accept } = useReview();
41
+ const { items, selectionAnchorY, accept, lastRefusal } = useReview();
49
42
  const metrics = useReviewRailMetrics();
43
+ // A new map only when a height changes, so the stack recomputes only then.
50
44
  const [heights, setHeights] = useState<ReadonlyMap<string, number>>(() => new Map());
51
45
  const onHeight = useCallback<OnHeight>(
52
46
  (key, height) =>
@@ -69,6 +63,7 @@ function MyCards() {
69
63
  >
70
64
  {item.text}
71
65
  {item.kind === 'revision' && <button onClick={() => accept(item)}>Accept</button>}
66
+ {lastRefusal?.key === item.key && <p>{lastRefusal.code}</p>}
72
67
  </MeasuredCard>
73
68
  ))}
74
69
  <DocxEditorReview.Draft top={top(selectionAnchorY ?? 0)} />
@@ -86,8 +81,6 @@ export function MyRail() {
86
81
  }
87
82
  ```
88
83
 
89
- The heights map gets a new reference only when a height changes, so the stack recomputes only then. Keep that rule if you store heights another way.
90
-
91
84
  **Vue**
92
85
 
93
86
  ```vue
@@ -101,7 +94,7 @@ import {
101
94
  useStackedReviewPositions,
102
95
  } from '@docx-editor.dev/pro/vue';
103
96
 
104
- const { items, selectionAnchorY, accept } = useReview();
97
+ const { items, selectionAnchorY, accept, lastRefusal } = useReview();
105
98
  const { metrics } = useReviewRailMetrics();
106
99
  // Reactive, so a new measurement restacks the cards.
107
100
  const heights = shallowReactive(new Map<string, number>());
@@ -111,19 +104,20 @@ const positions = useStackedReviewPositions(items, heights, () => ({
111
104
  }));
112
105
  const top = (y: number) => `${metrics.value.top + y * metrics.value.scale}px`;
113
106
 
114
- const observed = new Map<string, { el: Element; observer: ResizeObserver }>();
107
+ const observed = new Map<string, { el: HTMLElement; observer: ResizeObserver }>();
115
108
  function measure(key: string, el: unknown) {
109
+ const node = el as HTMLElement | null;
116
110
  const current = observed.get(key);
117
- if (current?.el === el) return;
111
+ if (current?.el === node) return;
118
112
  current?.observer.disconnect();
119
113
  observed.delete(key);
120
- if (!(el instanceof HTMLElement)) {
114
+ if (!node) {
121
115
  heights.delete(key);
122
116
  return;
123
117
  }
124
- const observer = new ResizeObserver(() => heights.set(key, el.offsetHeight));
125
- observer.observe(el);
126
- observed.set(key, { el, observer });
118
+ const observer = new ResizeObserver(() => heights.set(key, node.offsetHeight));
119
+ observer.observe(node);
120
+ observed.set(key, { el: node, observer });
127
121
  }
128
122
  onBeforeUnmount(() => observed.forEach(({ observer }) => observer.disconnect()));
129
123
  </script>
@@ -137,6 +131,7 @@ onBeforeUnmount(() => observed.forEach(({ observer }) => observer.disconnect()))
137
131
  >
138
132
  {{ item.text }}
139
133
  <button v-if="item.kind === 'revision'" @click="accept(item)">Accept</button>
134
+ <p v-if="lastRefusal?.key === item.key">{{ lastRefusal.code }}</p>
140
135
  </div>
141
136
  <DocxEditorReview.Draft :top="metrics.top + (selectionAnchorY ?? 0) * metrics.scale" />
142
137
  </template>
@@ -157,22 +152,43 @@ import MyCards from './MyCards.vue';
157
152
  </template>
158
153
  ```
159
154
 
160
- A plain `Map` is not reactive, so writes to it would not restack the cards. Use `shallowReactive(new Map())`, or a ref that you replace on each change.
155
+ A plain `Map` is not reactive. Use `shallowReactive(new Map())`, or a ref that you replace on each change.
156
+
157
+ `accept` returns `false` when the editor refuses, and `lastRefusal` names the item and the diagnostic code. `DocxEditorReview` already announces each refusal in a live region, so show it in the card as plain text. For a translated sentence, call `useReviewRefusalMessage()`.
158
+
159
+ ## Position cards and drafts
160
+
161
+ Convert a layout position to CSS pixels with `metrics.top + position * metrics.scale`.
162
+
163
+ | Input to `useStackedReviewPositions` | Description |
164
+ | --- | --- |
165
+ | `heights` | Measured card heights in CSS pixels, by item key. A card without a height reserves `defaultHeight`, and a taller card overlaps the next one. |
166
+ | `scale` | `metrics.scale`, CSS pixels per layout point. |
167
+ | `defaultHeight` | The height to reserve before a card is measured. |
168
+
169
+ `DocxEditorReview.Draft` renders only while a comment draft is open. Without `top`, it takes the packaged stack's position, so pass `top` from your own stack. To keep the box clear of your cards, add an entry at `selectionAnchorY` to the list that you stack, in document order.
161
170
 
162
- ## Root parts and card parts
171
+ ## Place review parts
163
172
 
164
- `DocxEditorReview` finds its parts among its own children by element type.
173
+ `DocxEditorReview` finds its parts among its own children by element type. Fragments are transparent in React and Vue.
165
174
 
166
- - **Root parts** are `List`, `Markers`, `AddComment`, `Draft`, and `Balloon`. Put them as direct children of `DocxEditorReview`. Fragments are transparent in React and in Vue. The rail gives these parts geometry that only it can compute, such as the comment button's `top`. A root part inside your own wrapper component is not a part. It renders as ordinary content, without that wiring.
167
- - **Card parts** are `Card`, `Empty`, and the parts inside a card, such as `Author`, `Summary`, `Accept`, and `Reply`. Put them inside `DocxEditorReview.List`.
175
+ | Part | Placement |
176
+ | --- | --- |
177
+ | `List`, `Markers`, `AddComment`, `Balloon` | Direct children of `DocxEditorReview`. Inside your own wrapper, a part renders as plain content without its geometry. |
178
+ | `Draft` | A direct child, or inside your own card component. Inside a custom stack, pass `top` explicitly. |
179
+ | `Card`, `Empty`, and card parts such as `Author`, `Summary`, `Accept`, and `Reply` | Inside `DocxEditorReview.List`. |
168
180
 
169
- With `preset` set to `false`, the rail adds no defaults. Root parts that you pass keep their wiring. Every other child renders as is inside the rail element, where `useReviewRailMetrics()` reads the rail's own measurement.
181
+ With `preset` set to `false`, the rail adds no defaults, but recognized parts keep their wiring. Other children render inside the rail element.
170
182
 
171
- ## Position the compose box
183
+ ## Limits
172
184
 
173
- `DocxEditorReview.Draft` renders only while a comment draft is open. A draft opens from `DocxEditorReview.AddComment` or from the `review.addComment` toolbar control. You can place `Draft` in either of these places:
185
+ - Disconnect each observer when its card unmounts or its item changes.
186
+ - In React, keep the heights map reference-stable. In Vue, keep it reactive.
187
+ - In the compact rail, `metrics.compact` is `true`. Place cards at `metrics.compactCardLeft`; `Draft` does this itself.
188
+ - Keep the column hidden while `metrics.left` is `null`.
174
189
 
175
- - As a direct child of `DocxEditorReview`.
176
- - Inside your own card component, as in the example. It still renders only while the draft is open.
190
+ ## See also
177
191
 
178
- Without `top`, the box sits where the packaged card stack puts it. That position comes from the packaged cards, not yours, so when you render your own cards, pass `top` from your own stack. In the narrow compact rail, the box takes the compact card's `left` in both cases, so it does not overflow the marker strip. The example places the box at the selection's anchor. To keep it clear of your cards, add an entry with the key of your choice and the anchor `selectionAnchorY` to the list that you pass to `useStackedReviewPositions`, in document order.
192
+ - [Review cards](https://www.docx-editor.dev/docs/2.x/customization/review-cards)
193
+ - [Tracked changes](https://www.docx-editor.dev/docs/2.x/pro/tracked-changes)
194
+ - [Accept or reject without scrolling](./accept-reject-without-scrolling.md)