@docx-editor.dev/editor-api 2.37.0 → 2.38.0-canary.20261113032851.sha-e2cbc55

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.
@@ -605,6 +605,53 @@ declare abstract class HandleCollection<T extends ClientObject & PromisedItem> e
605
605
  protected addressAt(value: AutomationValue, label: string, index: number): ObjectAddress | undefined;
606
606
  }
607
607
 
608
+ /** Office.js shape fill types. @public */
609
+ declare enum ShapeFillType {
610
+ noFill = "NoFill",
611
+ solid = "Solid",
612
+ gradient = "Gradient",
613
+ pattern = "Pattern",
614
+ picture = "Picture",
615
+ texture = "Texture",
616
+ mixed = "Mixed"
617
+ }
618
+ /**
619
+ * The fill of a shape, a text box, a line, or every shape of a group.
620
+ *
621
+ * `foregroundColor` reads `#RRGGBB` for a solid fill and an empty string otherwise, from the
622
+ * shape's own fill or its style's. `type` reads `Mixed` for a group whose shapes disagree.
623
+ * Writes accept `#RRGGBB`, `RRGGBB`, or a CSS color name; any other value fails the sync.
624
+ * `backgroundColor` and `set()` throw `NotSupported`.
625
+ * Pictures, charts and diagrams have no fill to set and refuse at the sync.
626
+ *
627
+ * @public
628
+ */
629
+ declare class ShapeFill extends ModelObject {
630
+ #private;
631
+ /** @internal The fill of the shape `shape` names. */
632
+ static of(context: RequestContext, label: string, owner: ObjectPath, shape: () => AutomationHandle): ShapeFill;
633
+ private constructor();
634
+ /** The fill type. Read-only. */
635
+ get type(): ShapeFillType | 'Gradient' | 'Mixed' | 'NoFill' | 'Pattern' | 'Picture' | 'Solid' | 'Texture';
636
+ /** The solid fill color as `#RRGGBB`, or an empty string for any other fill. */
637
+ get foregroundColor(): string;
638
+ set foregroundColor(value: string);
639
+ /** From 0 (opaque) to 1 (clear). 0 for anything but a solid fill. */
640
+ get transparency(): number;
641
+ set transparency(value: number);
642
+ /** Remove the fill. A later solid color brings a fill back. */
643
+ clear(): void;
644
+ /** Not supported: pattern fills have no background color to set. Throws `NotSupported`. */
645
+ get backgroundColor(): string;
646
+ set backgroundColor(_value: string);
647
+ /** Not supported: set `foregroundColor` and `transparency` one at a time. Throws `NotSupported`. */
648
+ set(_properties: unknown): void;
649
+ /** Fill with one color, `#RRGGBB`, `RRGGBB`, or a CSS color name. The transparency stays. */
650
+ setSolidColor(color: string): void;
651
+ /** @internal Plan the read this object's `load(...)` asked for. */
652
+ protected onLoad(request: ResolvedLoadOptions): void;
653
+ }
654
+
608
655
  /** Word's shape types. Supported text-bearing shapes expose their own body. @public */
609
656
  declare enum ShapeType {
610
657
  unsupported = "Unsupported",
@@ -645,6 +692,12 @@ declare class Shape extends ModelObject implements PromisedItem {
645
692
  * Shapes without their own supported text story also refuse access.
646
693
  */
647
694
  get body(): Body;
695
+ /**
696
+ * The shape's fill. A group's fill is every shape it holds. Pictures, charts and diagrams
697
+ * refuse at the sync. The outline has no Office.js member; the editor's `setShapeOutline`
698
+ * command sets it.
699
+ */
700
+ get fill(): ShapeFill;
648
701
  /** @internal Plan the read this object's `load(...)` asked for. */
649
702
  protected onLoad(request: ResolvedLoadOptions): void;
650
703
  }
@@ -1358,7 +1411,9 @@ declare class ContentControl extends ModelObject implements PromisedItem {
1358
1411
  * Remove the control.
1359
1412
  *
1360
1413
  * `keepContent` true is Word's own "Remove content control": the wrapper goes and the text it
1361
- * held stays exactly where it was. False takes the content with it.
1414
+ * held stays exactly where it was. False takes the content with it. False refuses with
1415
+ * `NotSupported` for a block control that follows a table at the end of a body, note, or
1416
+ * text box, because that story keeps a paragraph after the table.
1362
1417
  */
1363
1418
  delete(keepContent: boolean): void;
1364
1419
  /** @internal Plan the read this object's `load(...)` asked for. */
@@ -1827,6 +1882,10 @@ declare class Paragraph extends ModelObject implements PromisedItem {
1827
1882
  * paragraph's text and its paragraph mark. Accepting it removes the paragraph; rejecting it
1828
1883
  * restores the paragraph.
1829
1884
  *
1885
+ * A body, note, or text box that ends with a table keeps the empty paragraph after it: deleting
1886
+ * that paragraph without tracking refuses with `NotSupported` (`edit.operation-unsupported`).
1887
+ * Clear it instead.
1888
+ *
1830
1889
  * A tracked deletion refuses with `NotSupported` for the last paragraph of a story, table
1831
1890
  * cell, or content control; a paragraph directly before a table or block content control; a
1832
1891
  * paragraph whose mark ends a section; a paragraph with an inline content control; a
@@ -2249,6 +2308,8 @@ declare class Revision extends ModelObject implements PromisedItem {
2249
2308
  * earlier decision removed is skipped. Read `debugInfo.innerError.code` on a refusal, such as
2250
2309
  * `review.retained-structure` for a row that must stay to keep a nested table, or
2251
2310
  * `review.locked-content` and `review.bound-content` for a change a content control keeps.
2311
+ * Under enforced tracked-changes protection the sync refuses with `GeneralException` and
2312
+ * `edit.protected-content`.
2252
2313
  *
2253
2314
  * In a React or Vue host with the review module, use `useReview().accept` from
2254
2315
  * `@docx-editor.dev/pro/react` or `@docx-editor.dev/pro/vue` for a review UI.
@@ -2322,6 +2383,10 @@ declare class RevisionCollection extends HandleCollection<Revision> {
2322
2383
  * `InvalidObjectPath` when the key names nothing. Either way, the sync refuses whole when one
2323
2384
  * of the changes is read-only or cannot be resolved, and a change that an earlier decision in
2324
2385
  * the same sync resolved the same way is skipped.
2386
+ *
2387
+ * Under enforced tracked-changes protection (`w:edit="trackedChanges"`), every decision,
2388
+ * `resolve()`, and `setAuthor()` refuses the sync with `GeneralException` and
2389
+ * `edit.protected-content`, and nothing changes.
2325
2390
  */
2326
2391
  acceptAll(): void;
2327
2392
  /** Undo every change, likewise as one decision. */
@@ -2911,6 +2976,31 @@ declare class Body extends ModelObject {
2911
2976
  * You can load the returned range in the same sync. Editing it needs a sync first.
2912
2977
  */
2913
2978
  insertText(text: string, insertLocation: InsertLocation.replace | InsertLocation.start | InsertLocation.end | 'Replace' | 'Start' | 'End'): Range;
2979
+ /**
2980
+ * Replace the whole document with the DOCX file in `base64File`. Answers the new body's range.
2981
+ *
2982
+ * Only `Replace` on the main body is supported: the file's body, headers, footers, styles,
2983
+ * comments, and tracked changes replace this document's as one undoable edit, and a
2984
+ * collaboration session shares it as an ordinary edit. `Start` and `End` refuse with
2985
+ * `NotSupported`, and so does a header, footer, or note body. Must be the only write in its
2986
+ * sync. Refused while `changeTrackingMode` tracks changes, because the replacement records
2987
+ * no revisions. Refused with `NotImplemented` when the document holds a locked or data-bound
2988
+ * content control, as every other write that would overwrite one is.
2989
+ *
2990
+ * Invalid base64 or a file that is not a DOCX package refuses with `InvalidArgument`. Every
2991
+ * refusal leaves the document and its undo history unchanged.
2992
+ *
2993
+ * You can load the returned range in the same sync. Objects read before the replacement can
2994
+ * refuse with `InvalidObjectPath` afterward when their content is gone: read them again.
2995
+ *
2996
+ * @example
2997
+ * ```ts
2998
+ * const range = context.document.body.insertFileFromBase64(docxBase64, 'Replace');
2999
+ * range.load('text');
3000
+ * await context.sync();
3001
+ * ```
3002
+ */
3003
+ insertFileFromBase64(base64File: string, insertLocation: InsertLocation.replace | InsertLocation.start | InsertLocation.end | 'Replace' | 'Start' | 'End'): Range;
2914
3004
  /**
2915
3005
  * Add a paragraph at the start or the end of the story. Answers the new paragraph.
2916
3006
  * You can load the returned paragraph in the same sync. Editing it needs a sync first.
@@ -4255,5 +4345,5 @@ interface CreateServerOptions {
4255
4345
  /** Options for {@link createCollaborative}. @public */
4256
4346
  type CreateCollaborativeOptions = CreateServerOptions;
4257
4347
 
4258
- export { List as $, Alignment as A, DocumentProperties as I, DocxEditorError as M, Field as S, FieldCollection as T, FieldType as U, Font as W, InlinePicture as Y, InlinePictureCollection as Z, InsertLocation as _, ListBullet as a0, ListCollection as a1, ListItem as a2, ListNumbering as a3, NoteItem as a6, NoteItemCollection as a7, PageOrientation 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, PageSetup as aa, Paragraph as ab, ParagraphCollection as ad, Range as ah, RangeCollection as ai, RangeLocation as ak, RemoveDocInfoType as al, RequestContext as am, Revision as an, RevisionCollection as aq, Section as aw, SectionCollection as ax, Body as c, Bookmark as f, BookmarkCollection as g, BreakType as h, ChangeTrackingMode as i, ChangeTrackingVersion as j, ClientObject as k, ClientResult as l, Comment as m, CommentCollection as n, CommentReply as o, CommentReplyCollection as p, CompareTarget as r, ContentControl as s, ContentControlCollection as t, ContentControlType as w, Document as y };
4348
+ export { List as $, Alignment as A, DocumentProperties as I, DocxEditorError as M, Field as S, FieldCollection as T, FieldType as U, Font as W, InlinePicture as Y, InlinePictureCollection as Z, InsertLocation as _, ListBullet as a0, ListCollection as a1, ListItem as a2, ListNumbering as a3, NoteItem as a6, NoteItemCollection as a7, PageOrientation as a9, Shape as aA, ShapeCollection as aB, ShapeFill as aC, ShapeFillType as aD, ShapeType as aE, Style as aF, StyleCollection as aG, StyleType as aH, Table as aI, TableCell as aJ, TableCellCollection as aK, TableCollection as aL, TableRow as aM, TableRowCollection as aN, TrackedObjects as aO, UnderlineType as aP, VerticalAlignment as aQ, getReviewItemRange as aR, getReviewItemRangeOrNullObject as aS, getReviewItemRevisions as aT, isDocxEditorError as aU, PageSetup as aa, Paragraph as ab, ParagraphCollection as ad, Range as ah, RangeCollection as ai, RangeLocation as ak, RemoveDocInfoType as al, RequestContext as am, Revision as an, RevisionCollection as aq, Section as aw, SectionCollection as ax, Body as c, Bookmark as f, BookmarkCollection as g, BreakType as h, ChangeTrackingMode as i, ChangeTrackingVersion as j, ClientObject as k, ClientResult as l, Comment as m, CommentCollection as n, CommentReply as o, CommentReplyCollection as p, CompareTarget as r, ContentControl as s, ContentControlCollection as t, ContentControlType as w, Document as y };
4259
4349
  export type { BesideLocation as B, CreateServerOptions as C, DocxEditorRuntime as D, DocumentCompareOptions as E, DocumentLimits as F, DocumentPreview as G, DocumentPreviewStatus as H, DocumentXmlLimits as J, DocumentZipLimits as K, DocxEditorDebugInfo as L, DocxEditorErrorCode as N, DocxEditorErrorInit as O, DocxEditorInnerError as P, EditorModule as Q, RevisionTextView as R, FieldTypeLiteral as V, HeaderFooterType as X, DocxEditorServerRuntime as a, LoadOption as a4, LoadQueryOptions as a5, NoteItemType as a8, ParagraphAlignment as ac, ParagraphInsertTextLocation as ae, ParagraphReadingOrder as af, PreviewCallback as ag, RangeInsertTextLocation as aj, RevisionAuthorOptions as ao, RevisionAuthorSelection as ap, RevisionType as ar, RunCallback as as, RunOptions as at, RuntimeDiagnostic as au, SearchOptions as av, SelectionMode as ay, ServerPaginationOptions as az, CreateCollaborativeOptions as b, BodyInsertParagraphLocation as d, BodyInsertTextLocation as e, CommitPreviewOptions as q, ContentControlLockState as u, ContentControlSubtype as v, ContentControlValue as x, DocumentCapabilities as z };
@@ -605,6 +605,53 @@ declare abstract class HandleCollection<T extends ClientObject & PromisedItem> e
605
605
  protected addressAt(value: AutomationValue, label: string, index: number): ObjectAddress | undefined;
606
606
  }
607
607
 
608
+ /** Office.js shape fill types. @public */
609
+ declare enum ShapeFillType {
610
+ noFill = "NoFill",
611
+ solid = "Solid",
612
+ gradient = "Gradient",
613
+ pattern = "Pattern",
614
+ picture = "Picture",
615
+ texture = "Texture",
616
+ mixed = "Mixed"
617
+ }
618
+ /**
619
+ * The fill of a shape, a text box, a line, or every shape of a group.
620
+ *
621
+ * `foregroundColor` reads `#RRGGBB` for a solid fill and an empty string otherwise, from the
622
+ * shape's own fill or its style's. `type` reads `Mixed` for a group whose shapes disagree.
623
+ * Writes accept `#RRGGBB`, `RRGGBB`, or a CSS color name; any other value fails the sync.
624
+ * `backgroundColor` and `set()` throw `NotSupported`.
625
+ * Pictures, charts and diagrams have no fill to set and refuse at the sync.
626
+ *
627
+ * @public
628
+ */
629
+ declare class ShapeFill extends ModelObject {
630
+ #private;
631
+ /** @internal The fill of the shape `shape` names. */
632
+ static of(context: RequestContext, label: string, owner: ObjectPath, shape: () => AutomationHandle): ShapeFill;
633
+ private constructor();
634
+ /** The fill type. Read-only. */
635
+ get type(): ShapeFillType | 'Gradient' | 'Mixed' | 'NoFill' | 'Pattern' | 'Picture' | 'Solid' | 'Texture';
636
+ /** The solid fill color as `#RRGGBB`, or an empty string for any other fill. */
637
+ get foregroundColor(): string;
638
+ set foregroundColor(value: string);
639
+ /** From 0 (opaque) to 1 (clear). 0 for anything but a solid fill. */
640
+ get transparency(): number;
641
+ set transparency(value: number);
642
+ /** Remove the fill. A later solid color brings a fill back. */
643
+ clear(): void;
644
+ /** Not supported: pattern fills have no background color to set. Throws `NotSupported`. */
645
+ get backgroundColor(): string;
646
+ set backgroundColor(_value: string);
647
+ /** Not supported: set `foregroundColor` and `transparency` one at a time. Throws `NotSupported`. */
648
+ set(_properties: unknown): void;
649
+ /** Fill with one color, `#RRGGBB`, `RRGGBB`, or a CSS color name. The transparency stays. */
650
+ setSolidColor(color: string): void;
651
+ /** @internal Plan the read this object's `load(...)` asked for. */
652
+ protected onLoad(request: ResolvedLoadOptions): void;
653
+ }
654
+
608
655
  /** Word's shape types. Supported text-bearing shapes expose their own body. @public */
609
656
  declare enum ShapeType {
610
657
  unsupported = "Unsupported",
@@ -645,6 +692,12 @@ declare class Shape extends ModelObject implements PromisedItem {
645
692
  * Shapes without their own supported text story also refuse access.
646
693
  */
647
694
  get body(): Body;
695
+ /**
696
+ * The shape's fill. A group's fill is every shape it holds. Pictures, charts and diagrams
697
+ * refuse at the sync. The outline has no Office.js member; the editor's `setShapeOutline`
698
+ * command sets it.
699
+ */
700
+ get fill(): ShapeFill;
648
701
  /** @internal Plan the read this object's `load(...)` asked for. */
649
702
  protected onLoad(request: ResolvedLoadOptions): void;
650
703
  }
@@ -1358,7 +1411,9 @@ declare class ContentControl extends ModelObject implements PromisedItem {
1358
1411
  * Remove the control.
1359
1412
  *
1360
1413
  * `keepContent` true is Word's own "Remove content control": the wrapper goes and the text it
1361
- * held stays exactly where it was. False takes the content with it.
1414
+ * held stays exactly where it was. False takes the content with it. False refuses with
1415
+ * `NotSupported` for a block control that follows a table at the end of a body, note, or
1416
+ * text box, because that story keeps a paragraph after the table.
1362
1417
  */
1363
1418
  delete(keepContent: boolean): void;
1364
1419
  /** @internal Plan the read this object's `load(...)` asked for. */
@@ -1827,6 +1882,10 @@ declare class Paragraph extends ModelObject implements PromisedItem {
1827
1882
  * paragraph's text and its paragraph mark. Accepting it removes the paragraph; rejecting it
1828
1883
  * restores the paragraph.
1829
1884
  *
1885
+ * A body, note, or text box that ends with a table keeps the empty paragraph after it: deleting
1886
+ * that paragraph without tracking refuses with `NotSupported` (`edit.operation-unsupported`).
1887
+ * Clear it instead.
1888
+ *
1830
1889
  * A tracked deletion refuses with `NotSupported` for the last paragraph of a story, table
1831
1890
  * cell, or content control; a paragraph directly before a table or block content control; a
1832
1891
  * paragraph whose mark ends a section; a paragraph with an inline content control; a
@@ -2249,6 +2308,8 @@ declare class Revision extends ModelObject implements PromisedItem {
2249
2308
  * earlier decision removed is skipped. Read `debugInfo.innerError.code` on a refusal, such as
2250
2309
  * `review.retained-structure` for a row that must stay to keep a nested table, or
2251
2310
  * `review.locked-content` and `review.bound-content` for a change a content control keeps.
2311
+ * Under enforced tracked-changes protection the sync refuses with `GeneralException` and
2312
+ * `edit.protected-content`.
2252
2313
  *
2253
2314
  * In a React or Vue host with the review module, use `useReview().accept` from
2254
2315
  * `@docx-editor.dev/pro/react` or `@docx-editor.dev/pro/vue` for a review UI.
@@ -2322,6 +2383,10 @@ declare class RevisionCollection extends HandleCollection<Revision> {
2322
2383
  * `InvalidObjectPath` when the key names nothing. Either way, the sync refuses whole when one
2323
2384
  * of the changes is read-only or cannot be resolved, and a change that an earlier decision in
2324
2385
  * the same sync resolved the same way is skipped.
2386
+ *
2387
+ * Under enforced tracked-changes protection (`w:edit="trackedChanges"`), every decision,
2388
+ * `resolve()`, and `setAuthor()` refuses the sync with `GeneralException` and
2389
+ * `edit.protected-content`, and nothing changes.
2325
2390
  */
2326
2391
  acceptAll(): void;
2327
2392
  /** Undo every change, likewise as one decision. */
@@ -2911,6 +2976,31 @@ declare class Body extends ModelObject {
2911
2976
  * You can load the returned range in the same sync. Editing it needs a sync first.
2912
2977
  */
2913
2978
  insertText(text: string, insertLocation: InsertLocation.replace | InsertLocation.start | InsertLocation.end | 'Replace' | 'Start' | 'End'): Range;
2979
+ /**
2980
+ * Replace the whole document with the DOCX file in `base64File`. Answers the new body's range.
2981
+ *
2982
+ * Only `Replace` on the main body is supported: the file's body, headers, footers, styles,
2983
+ * comments, and tracked changes replace this document's as one undoable edit, and a
2984
+ * collaboration session shares it as an ordinary edit. `Start` and `End` refuse with
2985
+ * `NotSupported`, and so does a header, footer, or note body. Must be the only write in its
2986
+ * sync. Refused while `changeTrackingMode` tracks changes, because the replacement records
2987
+ * no revisions. Refused with `NotImplemented` when the document holds a locked or data-bound
2988
+ * content control, as every other write that would overwrite one is.
2989
+ *
2990
+ * Invalid base64 or a file that is not a DOCX package refuses with `InvalidArgument`. Every
2991
+ * refusal leaves the document and its undo history unchanged.
2992
+ *
2993
+ * You can load the returned range in the same sync. Objects read before the replacement can
2994
+ * refuse with `InvalidObjectPath` afterward when their content is gone: read them again.
2995
+ *
2996
+ * @example
2997
+ * ```ts
2998
+ * const range = context.document.body.insertFileFromBase64(docxBase64, 'Replace');
2999
+ * range.load('text');
3000
+ * await context.sync();
3001
+ * ```
3002
+ */
3003
+ insertFileFromBase64(base64File: string, insertLocation: InsertLocation.replace | InsertLocation.start | InsertLocation.end | 'Replace' | 'Start' | 'End'): Range;
2914
3004
  /**
2915
3005
  * Add a paragraph at the start or the end of the story. Answers the new paragraph.
2916
3006
  * You can load the returned paragraph in the same sync. Editing it needs a sync first.
@@ -4255,5 +4345,5 @@ interface CreateServerOptions {
4255
4345
  /** Options for {@link createCollaborative}. @public */
4256
4346
  type CreateCollaborativeOptions = CreateServerOptions;
4257
4347
 
4258
- export { List as $, Alignment as A, DocumentProperties as I, DocxEditorError as M, Field as S, FieldCollection as T, FieldType as U, Font as W, InlinePicture as Y, InlinePictureCollection as Z, InsertLocation as _, ListBullet as a0, ListCollection as a1, ListItem as a2, ListNumbering as a3, NoteItem as a6, NoteItemCollection as a7, PageOrientation 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, PageSetup as aa, Paragraph as ab, ParagraphCollection as ad, Range as ah, RangeCollection as ai, RangeLocation as ak, RemoveDocInfoType as al, RequestContext as am, Revision as an, RevisionCollection as aq, Section as aw, SectionCollection as ax, Body as c, Bookmark as f, BookmarkCollection as g, BreakType as h, ChangeTrackingMode as i, ChangeTrackingVersion as j, ClientObject as k, ClientResult as l, Comment as m, CommentCollection as n, CommentReply as o, CommentReplyCollection as p, CompareTarget as r, ContentControl as s, ContentControlCollection as t, ContentControlType as w, Document as y };
4348
+ export { List as $, Alignment as A, DocumentProperties as I, DocxEditorError as M, Field as S, FieldCollection as T, FieldType as U, Font as W, InlinePicture as Y, InlinePictureCollection as Z, InsertLocation as _, ListBullet as a0, ListCollection as a1, ListItem as a2, ListNumbering as a3, NoteItem as a6, NoteItemCollection as a7, PageOrientation as a9, Shape as aA, ShapeCollection as aB, ShapeFill as aC, ShapeFillType as aD, ShapeType as aE, Style as aF, StyleCollection as aG, StyleType as aH, Table as aI, TableCell as aJ, TableCellCollection as aK, TableCollection as aL, TableRow as aM, TableRowCollection as aN, TrackedObjects as aO, UnderlineType as aP, VerticalAlignment as aQ, getReviewItemRange as aR, getReviewItemRangeOrNullObject as aS, getReviewItemRevisions as aT, isDocxEditorError as aU, PageSetup as aa, Paragraph as ab, ParagraphCollection as ad, Range as ah, RangeCollection as ai, RangeLocation as ak, RemoveDocInfoType as al, RequestContext as am, Revision as an, RevisionCollection as aq, Section as aw, SectionCollection as ax, Body as c, Bookmark as f, BookmarkCollection as g, BreakType as h, ChangeTrackingMode as i, ChangeTrackingVersion as j, ClientObject as k, ClientResult as l, Comment as m, CommentCollection as n, CommentReply as o, CommentReplyCollection as p, CompareTarget as r, ContentControl as s, ContentControlCollection as t, ContentControlType as w, Document as y };
4259
4349
  export type { BesideLocation as B, CreateServerOptions as C, DocxEditorRuntime as D, DocumentCompareOptions as E, DocumentLimits as F, DocumentPreview as G, DocumentPreviewStatus as H, DocumentXmlLimits as J, DocumentZipLimits as K, DocxEditorDebugInfo as L, DocxEditorErrorCode as N, DocxEditorErrorInit as O, DocxEditorInnerError as P, EditorModule as Q, RevisionTextView as R, FieldTypeLiteral as V, HeaderFooterType as X, DocxEditorServerRuntime as a, LoadOption as a4, LoadQueryOptions as a5, NoteItemType as a8, ParagraphAlignment as ac, ParagraphInsertTextLocation as ae, ParagraphReadingOrder as af, PreviewCallback as ag, RangeInsertTextLocation as aj, RevisionAuthorOptions as ao, RevisionAuthorSelection as ap, RevisionType as ar, RunCallback as as, RunOptions as at, RuntimeDiagnostic as au, SearchOptions as av, SelectionMode as ay, ServerPaginationOptions as az, CreateCollaborativeOptions as b, BodyInsertParagraphLocation as d, BodyInsertTextLocation as e, CommitPreviewOptions as q, ContentControlLockState as u, ContentControlSubtype as v, ContentControlValue as x, DocumentCapabilities as z };
@@ -47,6 +47,166 @@ const result = useHighlights(
47
47
 
48
48
  A function source runs again after each document change, so the marks follow the text. The set is removed when the component unmounts.
49
49
 
50
+ ## Run the source again
51
+
52
+ A function source runs again after document changes. If it also reads your own state, call `refresh()` after that state changes. Examples are a word that you add to a dictionary, or a result that arrives from a server. The following component stops marking a term after you ignore it.
53
+
54
+ **React**
55
+
56
+ ```tsx
57
+ import { useCallback, useRef } from 'react';
58
+ import { useHighlights, type Editor } from '@docx-editor.dev/react';
59
+
60
+ export function TermMarks({ terms }: { terms: readonly string[] }) {
61
+ const ignored = useRef(new Set<string>());
62
+ const findTerms = useCallback(
63
+ (editor: Editor) =>
64
+ editor
65
+ .findMatches(terms, { wholeWord: true })
66
+ .flat()
67
+ .filter((match) => !ignored.current.has(match.text)),
68
+ [terms]
69
+ );
70
+ const { refresh } = useHighlights('terms', findTerms);
71
+ const ignore = (term: string) => {
72
+ ignored.current.add(term);
73
+ refresh();
74
+ };
75
+ return <button onClick={() => ignore(terms[0] ?? '')}>Ignore first term</button>;
76
+ }
77
+ ```
78
+
79
+ **Vue**
80
+
81
+ ```vue
82
+ <script setup lang="ts">
83
+ import { useHighlights, type Editor } from '@docx-editor.dev/vue';
84
+
85
+ const props = defineProps<{ terms: readonly string[] }>();
86
+ // A plain Set is not reactive, so the source does not run again by itself.
87
+ const ignored = new Set<string>();
88
+ const marks = useHighlights('terms', (editor: Editor) =>
89
+ editor
90
+ .findMatches(props.terms, { wholeWord: true })
91
+ .flat()
92
+ .filter((match) => !ignored.has(match.text))
93
+ );
94
+ function ignore(term: string) {
95
+ ignored.add(term);
96
+ marks.value.refresh();
97
+ }
98
+ </script>
99
+
100
+ <template>
101
+ <button @click="ignore(props.terms[0] ?? '')">Ignore first term</button>
102
+ </template>
103
+ ```
104
+
105
+ `refresh()` replaces a run that waits for typing to pause, so the source runs once. In React, the set updates at once, and `refresh` keeps its identity across renders. Call it from an effect or an event handler, not during render. In Vue, the set updates in the next flush, before the next paint. After the component unmounts, `refresh()` does nothing.
106
+
107
+ ## Read highlights in the context menu
108
+
109
+ Call `useContextMenuHighlights(name)` in a row inside `ContextMenu.Start` to read the highlights that the menu is about. For a right-click, these are the highlights under the pointer. If the menu opens from the keyboard, with Shift+F10 or the Menu key, these are the highlights that contain the caret. Add your own fields to each range, and read them back from `range`. The following rows offer a replacement for a marked term, from a right-click or from the keyboard.
110
+
111
+ **React**
112
+
113
+ ```tsx
114
+ import {
115
+ DocxEditor,
116
+ useContextMenuHighlights,
117
+ useDocxEditor,
118
+ useHighlights,
119
+ type Editor,
120
+ type TextMatch,
121
+ } from '@docx-editor.dev/react';
122
+
123
+ type TermRange = TextMatch & { readonly replacement: string };
124
+
125
+ function ReplacementRows({ recheck }: { recheck: () => void }) {
126
+ const editor = useDocxEditor();
127
+ const [hit] = useContextMenuHighlights<TermRange>('terms');
128
+ if (!hit || !editor) return null;
129
+ const replace = () => {
130
+ const result = editor.exec({
131
+ type: 'replaceMatch',
132
+ // Where the term is now, and the text it must still have.
133
+ match: {
134
+ blockId: hit.range.blockId,
135
+ start: hit.start,
136
+ length: hit.length,
137
+ expectedText: hit.range.text,
138
+ },
139
+ text: hit.range.replacement,
140
+ });
141
+ // The text changed after the menu opened: check the document again.
142
+ if (!result.ok && result.code === 'notFound') recheck();
143
+ };
144
+ return <DocxEditor.ContextMenu.Item label={hit.range.replacement} onSelect={replace} />;
145
+ }
146
+
147
+ // Render inside DocxEditor.Viewport. Pass a stable `findTerms`, such as one from useCallback.
148
+ export function TermMenu({ findTerms }: { findTerms: (editor: Editor) => TermRange[] }) {
149
+ const { refresh } = useHighlights('terms', findTerms);
150
+ return (
151
+ <DocxEditor.ContextMenu>
152
+ <DocxEditor.ContextMenu.Start>
153
+ <ReplacementRows recheck={refresh} />
154
+ </DocxEditor.ContextMenu.Start>
155
+ </DocxEditor.ContextMenu>
156
+ );
157
+ }
158
+ ```
159
+
160
+ **Vue**
161
+
162
+ ```vue
163
+ <script setup lang="ts">
164
+ import {
165
+ DocxEditor,
166
+ useContextMenuHighlights,
167
+ useDocxEditor,
168
+ type TextMatch,
169
+ } from '@docx-editor.dev/vue';
170
+
171
+ type TermRange = TextMatch & { readonly replacement: string };
172
+
173
+ // Pass `refresh` from the value of useHighlights('terms', ...).
174
+ const props = defineProps<{ recheck: () => void }>();
175
+ const editor = useDocxEditor();
176
+ const hits = useContextMenuHighlights<TermRange>('terms');
177
+
178
+ function replace() {
179
+ const hit = hits.value[0];
180
+ if (!hit || !editor.value) return;
181
+ const result = editor.value.exec({
182
+ type: 'replaceMatch',
183
+ // Where the term is now, and the text it must still have.
184
+ match: {
185
+ blockId: hit.range.blockId,
186
+ start: hit.start,
187
+ length: hit.length,
188
+ expectedText: hit.range.text,
189
+ },
190
+ text: hit.range.replacement,
191
+ });
192
+ // The text changed after the menu opened: check the document again.
193
+ if (!result.ok && result.code === 'notFound') props.recheck();
194
+ }
195
+ </script>
196
+
197
+ <template>
198
+ <DocxEditor.ContextMenu.Item
199
+ v-if="hits[0]"
200
+ :label="hits[0].range.replacement"
201
+ @select="replace"
202
+ />
203
+ </template>
204
+ ```
205
+
206
+ A highlight moves with its text, so use the hit's `start` and `length`, not the offsets of `range`. The hook reads the highlights again when the document changes while the menu is open. A term that moves away from the pointer or the caret is no longer reported. `expectedText` makes the replacement refuse with `notFound` if the text changed anyway.
207
+
208
+ For a keyboard open, a highlight counts when the caret is inside it or at either end, in the same paragraph. For a range selection, the caret is the end where the selection stops. The hit's `rect` is the highlight's rectangle on the caret's line. The hook returns an empty array while the menu is closed. To tell a right-click from a keyboard open, call `useContextMenuAnchor()` and check `trigger`.
209
+
50
210
  ## Configure a highlight set
51
211
 
52
212
  | Argument or field | Description |
@@ -56,6 +216,7 @@ A function source runs again after each document change, so the marks follow the
56
216
  | `options.className` | CSS classes added to every mark of the set. |
57
217
  | `options.activeIndex` | The range to show in the active color, such as the current result of your own search list. |
58
218
  | `applied` | The number of ranges that resolve and paint. |
219
+ | `refresh()` | Runs the source again, or applies an array again. |
59
220
 
60
221
  ## Use highlights outside components
61
222
 
@@ -2,11 +2,11 @@
2
2
 
3
3
  # Replace as a tracked change
4
4
 
5
- Find text with `editor.findMatches` and replace a match with the `replaceMatch` command in suggesting mode. On a server, set `document.changeTrackingMode` and call `insertText(text, 'Replace')`.
5
+ Find text with `editor.findMatches` and replace a match with the `replaceMatch` command in suggesting mode. To replace every match, use the `replaceAllMatches` command. On a server, set `document.changeTrackingMode` and call `insertText(text, 'Replace')`.
6
6
 
7
7
  ## Replace text in the editor
8
8
 
9
- The following button proposes a replacement for the first body match, so the body must be the open story. `replaceMatch` also accepts a match in the open header, footer, or note, and refuses text-box matches. The editor needs an `author` and `reviewModule()` in its modules, or `setEditingMode('suggesting')` refuses.
9
+ The following button proposes a replacement for the first body match. `replaceMatch` also replaces a match in a header, footer, or note without opening that story. It refuses text-box matches, and it returns `notFound` when the matched text changed after the search. The editor needs an `author` and `reviewModule()` in its modules, or `setEditingMode('suggesting')` refuses.
10
10
 
11
11
  **React**
12
12
 
@@ -17,7 +17,7 @@ export function ProposeTerm({ from, to }: { from: string; to: string }) {
17
17
  const editor = useDocxEditor();
18
18
  const run = () => {
19
19
  if (!editor || !editor.setEditingMode('suggesting').ok) return;
20
- // Body matches have no `scope`. replaceMatch needs the match's story open.
20
+ // Body matches have no `scope`.
21
21
  const match = editor.findMatches(from, { matchCase: true }).find((found) => !found.scope);
22
22
  if (!match) return;
23
23
  const result = editor.exec({ type: 'replaceMatch', match, text: to });
@@ -42,7 +42,7 @@ const editor = useDocxEditor();
42
42
  function run() {
43
43
  const current = editor.value;
44
44
  if (!current || !current.setEditingMode('suggesting').ok) return;
45
- // Body matches have no `scope`. replaceMatch needs the match's story open.
45
+ // Body matches have no `scope`.
46
46
  const match = current.findMatches(props.from, { matchCase: true }).find((found) => !found.scope);
47
47
  if (!match) return;
48
48
  const result = current.exec({ type: 'replaceMatch', match, text: props.to });
@@ -55,7 +55,66 @@ function run() {
55
55
  </template>
56
56
  ```
57
57
 
58
- The replacement is a tracked change by the editor's `author`. The button prevents its `mousedown` default, so the selection and scroll position do not move. To replace every match in one undo step, run `{ type: 'replaceAllMatches', query, text }` through `exec`.
58
+ The replacement is a tracked change by the editor's `author`. The button prevents its `mousedown` default, so the selection and scroll position do not move.
59
+
60
+ ## Replace every match in the editor
61
+
62
+ The following button proposes a replacement for every match in the body, tables, headers, footers, notes, and text boxes. One undo step reverts all of them.
63
+
64
+ **React**
65
+
66
+ ```tsx
67
+ import { useDocxEditor } from '@docx-editor.dev/react';
68
+
69
+ export function ProposeEverywhere({ from, to }: { from: string; to: string }) {
70
+ const editor = useDocxEditor();
71
+ const run = () => {
72
+ if (!editor || !editor.setEditingMode('suggesting').ok) return;
73
+ const result = editor.exec({
74
+ type: 'replaceAllMatches',
75
+ query: from,
76
+ text: to,
77
+ matchCase: true,
78
+ });
79
+ if (result.ok) console.log(`${result.replacements?.replaced ?? 0} proposed`);
80
+ else console.warn(result.code, result.reason);
81
+ };
82
+ return (
83
+ <button onMouseDown={(event) => event.preventDefault()} onClick={run}>
84
+ Propose {to} everywhere
85
+ </button>
86
+ );
87
+ }
88
+ ```
89
+
90
+ **Vue**
91
+
92
+ ```vue
93
+ <script setup lang="ts">
94
+ import { useDocxEditor } from '@docx-editor.dev/vue';
95
+
96
+ const props = defineProps<{ from: string; to: string }>();
97
+ const editor = useDocxEditor();
98
+ function run() {
99
+ const current = editor.value;
100
+ if (!current || !current.setEditingMode('suggesting').ok) return;
101
+ const result = current.exec({
102
+ type: 'replaceAllMatches',
103
+ query: props.from,
104
+ text: props.to,
105
+ matchCase: true,
106
+ });
107
+ if (result.ok) console.log(`${result.replacements?.replaced ?? 0} proposed`);
108
+ else console.warn(result.code, result.reason);
109
+ }
110
+ </script>
111
+
112
+ <template>
113
+ <button @mousedown.prevent @click="run">Propose {{ to }} everywhere</button>
114
+ </template>
115
+ ```
116
+
117
+ No story needs to be open. The command skips struck text and matches that cannot take plain text, such as field results and locked content controls, and counts them in `result.replacements.skipped`.
59
118
 
60
119
  ## Replace text on a server
61
120
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docx-editor.dev/editor-api",
3
- "version": "2.37.0",
3
+ "version": "2.38.0-canary.20261113032851.sha-e2cbc55",
4
4
  "description": "Document automation for DOCX: a batching object model that drives a document from a server or from an editor already open in a page",
5
5
  "sideEffects": false,
6
6
  "engines": {
@@ -92,6 +92,6 @@
92
92
  "access": "public"
93
93
  },
94
94
  "peerDependencies": {
95
- "@docx-editor.dev/core": "~2.37.0"
95
+ "@docx-editor.dev/core": "2.38.0-canary.20261113032851.sha-e2cbc55"
96
96
  }
97
97
  }