@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.
- package/OFFICE_JS_GUIDE.md +20 -0
- package/README.md +8 -13
- package/dist/browser.d.mts +2 -2
- package/dist/browser.d.ts +2 -2
- package/dist/browser.js +1 -1
- package/dist/browser.mjs +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{server-DMIAaVbA.d.mts → server-CodejWwc.d.mts} +67 -3
- package/dist/{server-DMIAaVbA.d.ts → server-CodejWwc.d.ts} +67 -3
- package/docs/accept-reject-without-scrolling.md +31 -48
- package/docs/comment-on-found-text.md +47 -23
- package/docs/custom-review-cards.md +50 -34
- package/docs/highlight-ranges.md +26 -6
- package/docs/index.md +21 -21
- package/docs/propose-rewrite.md +87 -138
- package/docs/tracked-replacement.md +41 -20
- package/package.json +2 -2
|
@@ -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 {
|
|
4193
|
-
export type { BesideLocation as B, CreateServerOptions as C, DocxEditorServerRuntime as D,
|
|
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 {
|
|
4193
|
-
export type { BesideLocation as B, CreateServerOptions as C, DocxEditorServerRuntime as D,
|
|
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
|
-
|
|
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
|
|
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
|
|
54
|
-
{{ item.text }}
|
|
55
|
-
<button :disabled="item.readOnly" @click
|
|
56
|
-
<button :disabled="item.readOnly" @click
|
|
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. `
|
|
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
|
-
|
|
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
|
-
##
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
|
|
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
|
|
24
|
+
if (!match || !editor?.selectMatch(match).ok) return setStatus('No match');
|
|
25
|
+
setStatus(comment(`Define "${term}".`) ? '' : 'Refused');
|
|
19
26
|
};
|
|
20
|
-
return
|
|
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
|
|
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
|
-
`
|
|
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
|
|
67
|
+
## Comment on a server
|
|
50
68
|
|
|
51
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
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
|
-
##
|
|
92
|
+
## See also
|
|
71
93
|
|
|
72
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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:
|
|
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 ===
|
|
111
|
+
if (current?.el === node) return;
|
|
118
112
|
current?.observer.disconnect();
|
|
119
113
|
observed.delete(key);
|
|
120
|
-
if (!
|
|
114
|
+
if (!node) {
|
|
121
115
|
heights.delete(key);
|
|
122
116
|
return;
|
|
123
117
|
}
|
|
124
|
-
const observer = new ResizeObserver(() => heights.set(key,
|
|
125
|
-
observer.observe(
|
|
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
|
|
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
|
-
##
|
|
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
|
-
|
|
167
|
-
|
|
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
|
|
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
|
-
##
|
|
183
|
+
## Limits
|
|
172
184
|
|
|
173
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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)
|