@docx-editor.dev/editor-api 2.30.0 → 2.31.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 +164 -3
- package/dist/browser.d.mts +3 -3
- package/dist/browser.d.ts +3 -3
- package/dist/browser.js +1 -1
- package/dist/browser.mjs +1 -1
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{server-BHhcVU2-.d.mts → server-Dw4k9h0p.d.mts} +642 -19
- package/dist/{server-BHhcVU2-.d.ts → server-Dw4k9h0p.d.ts} +642 -19
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AutomationHandle, AutomationSpan, AutomationOperation, AutomationValue, AutomationSpanRef, RevisionBatchResult, RevisionAuthorResult, DiagnosticCode, AutomationHost, AutomationCapabilities, AutomationPaginationOptions, ByteSizeBucket, DocumentOpenDiagnosticCode, DocumentPartKind, DiagnosticErrorName, EditDiagnosticCode } from '@docx-editor.dev/core/automation';
|
|
1
|
+
import { AutomationHandle, AutomationSpan, AutomationOperation, AutomationValue, AutomationSpanRef, RevisionBatchResult, RevisionAuthorResult, DiagnosticCode, HistoryGroup, AutomationHost, AutomationCapabilities, AutomationPaginationOptions, ByteSizeBucket, DocumentOpenDiagnosticCode, DocumentPartKind, DiagnosticErrorName, EditDiagnosticCode } from '@docx-editor.dev/core/automation';
|
|
2
2
|
import { CollaborationModuleContribution } from '@docx-editor.dev/core/collaboration';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -102,6 +102,11 @@ interface QueuedAction {
|
|
|
102
102
|
readonly nullableLoad?: ObjectPath;
|
|
103
103
|
/** The consumer-facing name of what this action is for, for errors. Never a handle. */
|
|
104
104
|
readonly label: string;
|
|
105
|
+
/**
|
|
106
|
+
* The answer queues reads for the same sync: a listing whose items load properties named
|
|
107
|
+
* with `items/`. A sync that writes sends such a listing, and those reads, before its writes.
|
|
108
|
+
*/
|
|
109
|
+
readonly continues?: boolean;
|
|
105
110
|
/** Detach coalesced setters when sync captures this action, before asynchronous reads. */
|
|
106
111
|
capture?(): void;
|
|
107
112
|
/** Release coalesced state when a batch completes or is discarded. */
|
|
@@ -123,6 +128,22 @@ declare class ActionQueue {
|
|
|
123
128
|
/** What is queued right now, for tests and for the empty-batch shortcut. */
|
|
124
129
|
get pending(): readonly QueuedAction[];
|
|
125
130
|
push(action: QueuedAction): void;
|
|
131
|
+
/**
|
|
132
|
+
* Run `work` and return what it queued instead of queueing it.
|
|
133
|
+
*
|
|
134
|
+
* Synchronous on purpose: nothing a consumer writes can run while `work` does, so no call of
|
|
135
|
+
* theirs can land in the returned list.
|
|
136
|
+
*/
|
|
137
|
+
collect(work: () => void): QueuedAction[];
|
|
138
|
+
/**
|
|
139
|
+
* Run `work` while a sync settles an answer, and keep what it queued for that same sync.
|
|
140
|
+
*
|
|
141
|
+
* This is how `load('items/text')` reads each item: the items are known only once the listing
|
|
142
|
+
* has answered, and the sync that sent the listing sends their reads before it resolves.
|
|
143
|
+
*/
|
|
144
|
+
continuing(work: () => void): void;
|
|
145
|
+
/** Hand over the reads `continuing` kept, and forget them. */
|
|
146
|
+
takeContinuations(): readonly QueuedAction[];
|
|
126
147
|
/** Hand over everything queued and forget it. Never replayed — see the file header. */
|
|
127
148
|
take(): readonly QueuedAction[];
|
|
128
149
|
/** Drop everything queued: what a finished run does with actions nobody synced. */
|
|
@@ -221,11 +242,15 @@ declare abstract class ItemCollection<T extends ClientObject> extends ClientObje
|
|
|
221
242
|
* The members this collection was loaded with.
|
|
222
243
|
*
|
|
223
244
|
* `PropertyNotLoaded` until a `load(...)` has been synced: a collection that answered `[]`
|
|
224
|
-
* before it had been read would be indistinguishable from an empty document.
|
|
245
|
+
* before it had been read would be indistinguishable from an empty document. Name an item
|
|
246
|
+
* property with an `items/` path, such as `load('items/text')`, to load it on every member in
|
|
247
|
+
* the same sync.
|
|
225
248
|
*/
|
|
226
249
|
get items(): readonly T[];
|
|
227
250
|
/** @internal Take the members straight from the command that produced them. */
|
|
228
251
|
fill(value: AutomationValue, label: string): void;
|
|
252
|
+
/** @internal Collections accept `items/<property>` paths. */
|
|
253
|
+
protected get loadsItemPaths(): boolean;
|
|
229
254
|
/** @internal Plan the read this object's `load(...)` asked for. */
|
|
230
255
|
protected onLoad(request: ResolvedLoadOptions): void;
|
|
231
256
|
/** One member, by which end of the collection it is at. */
|
|
@@ -896,9 +921,8 @@ type SelectionMode = 'Select' | 'Start' | 'End';
|
|
|
896
921
|
* enclose. A bookmark whose markers left with the text they surrounded refuses rather than
|
|
897
922
|
* answering where they used to be.
|
|
898
923
|
*
|
|
899
|
-
* `start
|
|
900
|
-
*
|
|
901
|
-
* marker pair, which the canonical write path does not offer.
|
|
924
|
+
* `start` and `end` are absent by design: they are document-wide character offsets, the
|
|
925
|
+
* coordinate space this API does not maintain.
|
|
902
926
|
*
|
|
903
927
|
* @public
|
|
904
928
|
*/
|
|
@@ -931,6 +955,17 @@ declare class Bookmark extends ModelObject implements PromisedItem {
|
|
|
931
955
|
* `NotSupported` where there is no reader.
|
|
932
956
|
*/
|
|
933
957
|
select(selectionMode_?: SelectionMode): void;
|
|
958
|
+
/**
|
|
959
|
+
* Delete this bookmark. The text it marks stays.
|
|
960
|
+
*
|
|
961
|
+
* @example
|
|
962
|
+
* ```ts
|
|
963
|
+
* const bookmark = context.document.body.bookmarks.getFirst();
|
|
964
|
+
* bookmark.delete();
|
|
965
|
+
* await context.sync();
|
|
966
|
+
* ```
|
|
967
|
+
*/
|
|
968
|
+
delete(): void;
|
|
934
969
|
/** @internal Plan the read this object's `load(...)` asked for. */
|
|
935
970
|
protected onLoad(request: ResolvedLoadOptions): void;
|
|
936
971
|
}
|
|
@@ -1376,8 +1411,11 @@ interface RevisionAuthorOptions {
|
|
|
1376
1411
|
* The tracked changes on a document, story or range, as of the batch that loaded them.
|
|
1377
1412
|
*
|
|
1378
1413
|
* `items` omits structural cards whose Word subtype this API cannot name; see {@link Revision}.
|
|
1379
|
-
*
|
|
1380
|
-
* story and refuse atomically if any `readOnly` or otherwise unsupported
|
|
1414
|
+
* On a story's collection, `acceptAll` / `rejectAll` still resolve every store-resolvable
|
|
1415
|
+
* revision in the story and refuse atomically if any `readOnly` or otherwise unsupported
|
|
1416
|
+
* revision remains. On {@link Range.revisions} and `getReviewItemRevisions`, they resolve the
|
|
1417
|
+
* changes the range overlaps or the key names, and `resolve` and `setAuthor` refuse with
|
|
1418
|
+
* `NotSupported`.
|
|
1381
1419
|
*
|
|
1382
1420
|
* @public
|
|
1383
1421
|
*/
|
|
@@ -1385,6 +1423,10 @@ declare class RevisionCollection extends HandleCollection<Revision> {
|
|
|
1385
1423
|
#private;
|
|
1386
1424
|
/** @internal The pending decisions of one story. */
|
|
1387
1425
|
static of(context: RequestContext, label: string, owner: ObjectPath, body: AutomationHandle): RevisionCollection;
|
|
1426
|
+
/** @internal The pending decisions a range overlaps, read from the range at plan time. */
|
|
1427
|
+
static inSpan(context: RequestContext, label: string, owner: ObjectPath, span: () => AutomationSpanRef): RevisionCollection;
|
|
1428
|
+
/** @internal The pending decisions one review-queue key names. */
|
|
1429
|
+
static ofReviewKey(context: RequestContext, label: string, owner: ObjectPath, key: string): RevisionCollection;
|
|
1388
1430
|
private constructor();
|
|
1389
1431
|
/**
|
|
1390
1432
|
* Keep every change in this story, as ONE decision and one undo unit.
|
|
@@ -1393,6 +1435,14 @@ declare class RevisionCollection extends HandleCollection<Revision> {
|
|
|
1393
1435
|
* omitted from `items`. Refuses the sync outright where any `readOnly` or otherwise
|
|
1394
1436
|
* unsupported revision remains, rather than reporting the story as reviewed while pending
|
|
1395
1437
|
* changes remain.
|
|
1438
|
+
*
|
|
1439
|
+
* On a collection from {@link Range.revisions}, resolves every change the range overlaps at
|
|
1440
|
+
* sync time, structural changes absent from `items` included. A change the range covers in
|
|
1441
|
+
* part resolves whole, characters outside the range included. On a collection from
|
|
1442
|
+
* `getReviewItemRevisions`, resolves the changes the key names, and refuses with
|
|
1443
|
+
* `InvalidObjectPath` when the key names nothing. Either way, the sync refuses whole when one
|
|
1444
|
+
* of the changes is read-only or cannot be resolved, and a change that an earlier decision in
|
|
1445
|
+
* the same sync resolved the same way is skipped.
|
|
1396
1446
|
*/
|
|
1397
1447
|
acceptAll(): void;
|
|
1398
1448
|
/** Undo every change, likewise as one decision. */
|
|
@@ -1403,6 +1453,8 @@ declare class RevisionCollection extends HandleCollection<Revision> {
|
|
|
1403
1453
|
* Pass an empty array to select nothing. Duplicate objects resolve once; stale targets
|
|
1404
1454
|
* are reported as unknown-revision. This must be the only write in its sync batch.
|
|
1405
1455
|
* Unlike acceptAll/rejectAll, unsupported decisions do not block independent changes.
|
|
1456
|
+
* A collection from `Range.revisions` or `getReviewItemRevisions` refuses this call with
|
|
1457
|
+
* `NotSupported`.
|
|
1406
1458
|
*
|
|
1407
1459
|
* @example
|
|
1408
1460
|
* ```ts
|
|
@@ -1421,6 +1473,8 @@ declare class RevisionCollection extends HandleCollection<Revision> {
|
|
|
1421
1473
|
* author, including structural ones absent from `items`. An empty array selects nothing.
|
|
1422
1474
|
* Each change keeps its date unless you pass `options.date`. Keep this the only write in
|
|
1423
1475
|
* its sync batch. Revision objects you pass stay valid and read the new author after a load.
|
|
1476
|
+
* A collection from `Range.revisions` or `getReviewItemRevisions` refuses this call with
|
|
1477
|
+
* `NotSupported`.
|
|
1424
1478
|
*
|
|
1425
1479
|
* @example
|
|
1426
1480
|
* ```ts
|
|
@@ -1534,6 +1588,71 @@ declare class Range extends ModelObject implements PromisedItem {
|
|
|
1534
1588
|
set hyperlink(value: string);
|
|
1535
1589
|
/** The bookmarks whose text this range overlaps, in document order. */
|
|
1536
1590
|
get bookmarks(): BookmarkCollection;
|
|
1591
|
+
/**
|
|
1592
|
+
* Add a bookmark around this range, or at its position when the range is empty.
|
|
1593
|
+
*
|
|
1594
|
+
* Names compare without case and are unique in the whole document. A bookmark with the same
|
|
1595
|
+
* name moves here, also from another story (a header, a footer, or a note), in the same sync.
|
|
1596
|
+
* A name starts with a letter, or with an underscore for a hidden bookmark, holds only
|
|
1597
|
+
* letters, digits and underscores, and has at most 40 characters. Any other name fails
|
|
1598
|
+
* `context.sync()` with `InvalidArgument`, and nothing in that batch is written. Bookmarks are
|
|
1599
|
+
* not revisions, so with `TrackMineOnly` the markers are written directly.
|
|
1600
|
+
*
|
|
1601
|
+
* @example
|
|
1602
|
+
* ```ts
|
|
1603
|
+
* const range = context.document.body.paragraphs.getFirst().getRange();
|
|
1604
|
+
* range.insertBookmark('Intro');
|
|
1605
|
+
* await context.sync();
|
|
1606
|
+
* ```
|
|
1607
|
+
*/
|
|
1608
|
+
insertBookmark(name: string): void;
|
|
1609
|
+
/**
|
|
1610
|
+
* The names of the bookmarks in or overlapping this range, in document order.
|
|
1611
|
+
*
|
|
1612
|
+
* A range holds a bookmark when the two share text, and a point bookmark when the point is
|
|
1613
|
+
* inside the range or at its start. An empty range holds the bookmarks around it. Pass
|
|
1614
|
+
* `includeAdjacent` to add bookmarks that only touch the range at one end, and
|
|
1615
|
+
* `includeHidden` to add hidden bookmarks, whose names start with an underscore.
|
|
1616
|
+
*
|
|
1617
|
+
* @example
|
|
1618
|
+
* ```ts
|
|
1619
|
+
* const names = range.getBookmarks(true, false);
|
|
1620
|
+
* await context.sync();
|
|
1621
|
+
* console.log(names.value);
|
|
1622
|
+
* ```
|
|
1623
|
+
*/
|
|
1624
|
+
getBookmarks(includeHidden?: boolean, includeAdjacent?: boolean): ClientResult<string[]>;
|
|
1625
|
+
/**
|
|
1626
|
+
* The tracked changes whose characters this range overlaps, in document order.
|
|
1627
|
+
*
|
|
1628
|
+
* Lists the same `Revision` objects the story's collection lists, so a change reached here is
|
|
1629
|
+
* the one `body.revisions` holds. A collapsed range lists the changes it touches. A paragraph
|
|
1630
|
+
* mark change is listed only when the range continues into the next paragraph, so reach the
|
|
1631
|
+
* mark change of a whole paragraph through `body.revisions`. Membership
|
|
1632
|
+
* uses document positions, so the runtime's `revisionTextView` changes what `text` reads, not
|
|
1633
|
+
* which changes are listed. A change partly inside the range is listed whole. A replacement
|
|
1634
|
+
* stored as a deletion followed by an insertion lists as two members.
|
|
1635
|
+
*
|
|
1636
|
+
* On this collection, `acceptAll()` and `rejectAll()` resolve every change the range overlaps,
|
|
1637
|
+
* structural changes absent from `items` included, and a partly covered change resolves whole.
|
|
1638
|
+
* They refuse the whole sync when one of those changes is read-only or cannot be resolved.
|
|
1639
|
+
* `resolve()` and `setAuthor()` refuse with `NotSupported`; use the story's collection.
|
|
1640
|
+
*
|
|
1641
|
+
* A range can overlap changes nobody meant to decide: a change nested inside another, or one
|
|
1642
|
+
* by another author beside it. To decide the change a review card shows, use
|
|
1643
|
+
* `getReviewItemRevisions`.
|
|
1644
|
+
*
|
|
1645
|
+
* @example Accept every change in a search result
|
|
1646
|
+
* ```ts
|
|
1647
|
+
* const matches = context.document.body.search('indemnify');
|
|
1648
|
+
* matches.load('items');
|
|
1649
|
+
* await context.sync();
|
|
1650
|
+
*
|
|
1651
|
+
* for (const match of matches.items) match.revisions.acceptAll();
|
|
1652
|
+
* await context.sync();
|
|
1653
|
+
* ```
|
|
1654
|
+
*/
|
|
1655
|
+
get revisions(): RevisionCollection;
|
|
1537
1656
|
/** Every occurrence of `searchText` inside this range, as ranges. */
|
|
1538
1657
|
search(searchText: string, options?: SearchOptions): RangeCollection;
|
|
1539
1658
|
/**
|
|
@@ -1542,7 +1661,17 @@ declare class Range extends ModelObject implements PromisedItem {
|
|
|
1542
1661
|
*
|
|
1543
1662
|
* With server `document.changeTrackingMode = 'TrackMineOnly'`, this creates a tracked text
|
|
1544
1663
|
* edit attributed to the runtime author. Tracked range replacement supports adjacent sibling paragraphs outside collaboration.
|
|
1545
|
-
* Table and wrapper boundaries
|
|
1664
|
+
* Table and wrapper boundaries refuse. Edits can go inside or beside another author's pending
|
|
1665
|
+
* text insertion or deletion: a deletion of their inserted text nests inside their insertion,
|
|
1666
|
+
* new text inside their insertion splits it in two, and the returned range names the new text
|
|
1667
|
+
* after any deleted text. Each author's change stays a separate decision. These refuse with
|
|
1668
|
+
* `NotImplemented`, and `debugInfo.innerError.code` names the rule: a range of only deleted
|
|
1669
|
+
* text (`edit.tracked-deleted-text-only`); another author's paragraph mark, formatting, move, or
|
|
1670
|
+
* structural change, or a link or content control inside their insertion
|
|
1671
|
+
* (`edit.tracked-foreign-revision-unsupported`); and your own pending change, including a
|
|
1672
|
+
* range a tracked write returned (`edit.tracked-own-pending-change`). In a collaboration
|
|
1673
|
+
* session, the API refuses strikes over another author's pending insertion or deletion,
|
|
1674
|
+
* and edits that start inside or right after one, with `edit.tracked-foreign-revision-unsupported`. Font and paragraph
|
|
1546
1675
|
* formatting support property revisions.
|
|
1547
1676
|
* Empty text with `Replace` deletes the range; empty text at an insertion point is a no-op.
|
|
1548
1677
|
* Agent tools that intend a replacement should validate non-empty model output first.
|
|
@@ -1596,7 +1725,13 @@ declare class Range extends ModelObject implements PromisedItem {
|
|
|
1596
1725
|
insertField(insertLocation: InsertLocation | 'Before' | 'After' | 'Start' | 'End' | 'Replace', fieldType?: FieldTypeLiteral, text?: string, removeFormatting?: boolean): Field;
|
|
1597
1726
|
/** Inline pictures fully contained within this snapshot range. */
|
|
1598
1727
|
get inlinePictures(): InlinePictureCollection;
|
|
1599
|
-
/**
|
|
1728
|
+
/**
|
|
1729
|
+
* Insert a bounded PNG/JPEG image. Sync before configuring the returned picture.
|
|
1730
|
+
*
|
|
1731
|
+
* Works on server, browser, and collaborative runtimes; on a collaborative runtime the
|
|
1732
|
+
* picture, its media part, and its relationship replicate to every participant. Insertion
|
|
1733
|
+
* must be the only mutation in its sync, and tracking refuses it.
|
|
1734
|
+
*/
|
|
1600
1735
|
insertInlinePictureFromBase64(base64EncodedImage: string, insertLocation: InsertLocation | 'Before' | 'After' | 'Start' | 'End' | 'Replace'): InlinePicture;
|
|
1601
1736
|
/**
|
|
1602
1737
|
* Line, page, and next-page section breaks are supported; other break types refuse at sync.
|
|
@@ -1739,6 +1874,13 @@ declare class Paragraph extends ModelObject implements PromisedItem {
|
|
|
1739
1874
|
get list(): List;
|
|
1740
1875
|
/** Address this paragraph's content or an endpoint. Sync before using the returned range. */
|
|
1741
1876
|
getRange(rangeLocation?: 'Whole' | 'Content' | 'Start' | 'End' | 'Before' | 'After'): Range;
|
|
1877
|
+
/**
|
|
1878
|
+
* Every occurrence of `searchText` in this paragraph, as ranges, in reading order.
|
|
1879
|
+
*
|
|
1880
|
+
* Takes the same options as `Body.search`. You can search a paragraph from `getFirst()` in the
|
|
1881
|
+
* same `context.sync()` that finds it.
|
|
1882
|
+
*/
|
|
1883
|
+
search(searchText: string, searchOptions?: SearchOptions): RangeCollection;
|
|
1742
1884
|
/** Start a new independent bullet list with this paragraph. Sync before using the returned list. */
|
|
1743
1885
|
startNewList(): List;
|
|
1744
1886
|
/** Join an existing list at a zero-based nesting level. */
|
|
@@ -1761,8 +1903,9 @@ declare class Paragraph extends ModelObject implements PromisedItem {
|
|
|
1761
1903
|
* paragraph whose mark ends a section; a paragraph with an inline content control; a
|
|
1762
1904
|
* paragraph with a complex field boundary whose matching boundary is in another paragraph;
|
|
1763
1905
|
* and a paragraph that nests inline content more than 64 levels deep. It refuses with
|
|
1764
|
-
* `NotImplemented` when the paragraph
|
|
1765
|
-
*
|
|
1906
|
+
* `NotImplemented` when the paragraph has your own pending change or another author's pending
|
|
1907
|
+
* paragraph mark, formatting, move, or structural change, and when the start of the next
|
|
1908
|
+
* paragraph has any pending change. Delete adjacent paragraphs in one sync:
|
|
1766
1909
|
* a later sync beside your own pending deletion refuses, because the two would review as one
|
|
1767
1910
|
* decision. A refusal refuses the whole sync.
|
|
1768
1911
|
*/
|
|
@@ -1794,6 +1937,9 @@ declare class Paragraph extends ModelObject implements PromisedItem {
|
|
|
1794
1937
|
* {@link Paragraph.split} answers are filled in by the split's own command rather than by a
|
|
1795
1938
|
* separate listing read.
|
|
1796
1939
|
*
|
|
1940
|
+
* Load the paragraphs and a property of each in one sync with an `items/` path, such as
|
|
1941
|
+
* `paragraphs.load('items/text')`.
|
|
1942
|
+
*
|
|
1797
1943
|
* @public
|
|
1798
1944
|
*/
|
|
1799
1945
|
declare class ParagraphCollection extends ItemCollection<Paragraph> {
|
|
@@ -1834,6 +1980,9 @@ declare class ParagraphCollection extends ItemCollection<Paragraph> {
|
|
|
1834
1980
|
* collections: each item carries its own paragraph-plus-offset endpoints instead of an opaque
|
|
1835
1981
|
* host-minted id.
|
|
1836
1982
|
*
|
|
1983
|
+
* Load the ranges and a property of each in one sync with an `items/` path, such as
|
|
1984
|
+
* `results.load('items/text')`.
|
|
1985
|
+
*
|
|
1837
1986
|
* @public
|
|
1838
1987
|
*/
|
|
1839
1988
|
declare class RangeCollection extends ItemCollection<Range> {
|
|
@@ -2137,6 +2286,32 @@ declare class Document extends ModelObject {
|
|
|
2137
2286
|
get footnotes(): NoteItemCollection;
|
|
2138
2287
|
/** The document's endnotes, in the order its notes part writes them. */
|
|
2139
2288
|
get endnotes(): NoteItemCollection;
|
|
2289
|
+
/**
|
|
2290
|
+
* Delete the bookmark with this name, compared without case, from whichever story declares
|
|
2291
|
+
* it. The text stays. A name no bookmark has changes nothing.
|
|
2292
|
+
*
|
|
2293
|
+
* @example
|
|
2294
|
+
* ```ts
|
|
2295
|
+
* context.document.deleteBookmark('Intro');
|
|
2296
|
+
* await context.sync();
|
|
2297
|
+
* ```
|
|
2298
|
+
*/
|
|
2299
|
+
deleteBookmark(name: string): void;
|
|
2300
|
+
/**
|
|
2301
|
+
* The range of the bookmark with this name, compared without case. The main text is searched
|
|
2302
|
+
* first, then headers, footers and notes. `ItemNotFound` at the sync when no bookmark has the
|
|
2303
|
+
* name.
|
|
2304
|
+
*
|
|
2305
|
+
* @example
|
|
2306
|
+
* ```ts
|
|
2307
|
+
* const range = context.document.getBookmarkRange('Intro');
|
|
2308
|
+
* range.load('text');
|
|
2309
|
+
* await context.sync();
|
|
2310
|
+
* ```
|
|
2311
|
+
*/
|
|
2312
|
+
getBookmarkRange(name: string): Range;
|
|
2313
|
+
/** Like {@link Document.getBookmarkRange}, but a missing bookmark answers a null object. */
|
|
2314
|
+
getBookmarkRangeOrNullObject(name: string): Range;
|
|
2140
2315
|
/** @internal Plan the read this object's `load(...)` asked for. */
|
|
2141
2316
|
protected onLoad(request: ResolvedLoadOptions): void;
|
|
2142
2317
|
}
|
|
@@ -2148,12 +2323,14 @@ type DocxEditorErrorCode =
|
|
|
2148
2323
|
/** A `ClientResult` value was read before the sync that fills it. */
|
|
2149
2324
|
| 'ValueNotLoaded'
|
|
2150
2325
|
/**
|
|
2151
|
-
* The object cannot be addressed, in
|
|
2326
|
+
* The object cannot be addressed, in one of three ways.
|
|
2152
2327
|
*
|
|
2153
2328
|
* NOT YET: an item accessor answers a proxy the read that names it has not answered for, and it
|
|
2154
2329
|
* becomes usable at the next `sync()`. NOT ANY MORE: its run ended and nothing tracked it, which
|
|
2155
|
-
* is terminal.
|
|
2156
|
-
*
|
|
2330
|
+
* is terminal. GONE: the document no longer holds the object, because an edit removed or merged
|
|
2331
|
+
* it; `debugInfo.innerError.code` is then `edit.stale-target` and the message says so. One
|
|
2332
|
+
* code because from a consumer's side all three are "this object cannot be used here"; the
|
|
2333
|
+
* message says which one, because the fix for one is not the fix for the others.
|
|
2157
2334
|
*/
|
|
2158
2335
|
| 'InvalidObjectPath'
|
|
2159
2336
|
/** The object still belongs to a run that has not finished, so it cannot be handed over. */
|
|
@@ -2194,6 +2371,13 @@ type DocxEditorErrorCode =
|
|
|
2194
2371
|
| 'StaleDocument'
|
|
2195
2372
|
/** The host is live but holds no document right now — an editor between mounts. */
|
|
2196
2373
|
| 'DocumentUnavailable'
|
|
2374
|
+
/**
|
|
2375
|
+
* A preview is open over the editor, so it refuses this write or a second preview. Commit or
|
|
2376
|
+
* discard the open preview first. Browser runtime only.
|
|
2377
|
+
*/
|
|
2378
|
+
| 'PreviewActive'
|
|
2379
|
+
/** The preview has ended — committed, discarded, or replaced by a remount — so it cannot commit. */
|
|
2380
|
+
| 'PreviewEnded'
|
|
2197
2381
|
/** The document refused the change, or answered something this runtime cannot use. */
|
|
2198
2382
|
| 'GeneralException';
|
|
2199
2383
|
/**
|
|
@@ -2321,8 +2505,248 @@ declare class DocxEditorError extends Error {
|
|
|
2321
2505
|
*/
|
|
2322
2506
|
declare function isDocxEditorError(value: unknown): value is DocxEditorError;
|
|
2323
2507
|
|
|
2508
|
+
/**
|
|
2509
|
+
* Where a {@link DocumentPreview} is in its life.
|
|
2510
|
+
*
|
|
2511
|
+
* - `active`: the page shows the preview, and the live document has not moved since the
|
|
2512
|
+
* preview began.
|
|
2513
|
+
* - `stale`: the live document moved after the preview began: a collaboration peer edited it,
|
|
2514
|
+
* or a local write landed while the callback ran. The page still shows the preview.
|
|
2515
|
+
* `commit()` refuses with `StaleDocument`; `commit({ rebase: true })` replays it on the
|
|
2516
|
+
* current document instead.
|
|
2517
|
+
* - `ended`: the preview was committed, discarded, or ended because its runtime was disposed or
|
|
2518
|
+
* the editor loaded, detached, or remounted. The page shows the live document. Final.
|
|
2519
|
+
*
|
|
2520
|
+
* @example
|
|
2521
|
+
* ```ts
|
|
2522
|
+
* preview.onStatusChanged((status) => {
|
|
2523
|
+
* applyButton.textContent = status === 'stale' ? 'Apply to the current text' : 'Apply';
|
|
2524
|
+
* });
|
|
2525
|
+
* ```
|
|
2526
|
+
* @public
|
|
2527
|
+
*/
|
|
2528
|
+
type DocumentPreviewStatus = 'active' | 'stale' | 'ended';
|
|
2529
|
+
/**
|
|
2530
|
+
* What {@link DocxEditorRuntime.preview} hands its callback: an ordinary request context
|
|
2531
|
+
* whose reads and writes address the preview, not the live document.
|
|
2532
|
+
*
|
|
2533
|
+
* Write it as you would write the final edit, from data you already have. The editor stays
|
|
2534
|
+
* editable while the callback runs, so a callback that waits on a model call lets the document
|
|
2535
|
+
* move under it, and the preview then starts `stale`. Ask the model first, then preview.
|
|
2536
|
+
*
|
|
2537
|
+
* Text and formatting edits work in the body, headers, footers, and notes. The callback cannot
|
|
2538
|
+
* write tables, pictures, fields, lists, hyperlinks, content controls, or page setup, create or
|
|
2539
|
+
* delete headers, footers, or notes, or move the selection: `context.sync()` refuses those with
|
|
2540
|
+
* `NotSupported`. Comments are written in the body only, as in `run()`.
|
|
2541
|
+
*
|
|
2542
|
+
* @example
|
|
2543
|
+
* ```ts
|
|
2544
|
+
* const proposal = await model.propose(clauseText); // before the preview, not inside it
|
|
2545
|
+
* const preview = await runtime.preview(async (context) => {
|
|
2546
|
+
* context.document.changeTrackingMode = 'TrackMineOnly';
|
|
2547
|
+
* const range = context.document.body.search(proposal.find).getFirst();
|
|
2548
|
+
* range.insertText(proposal.replace, 'Replace');
|
|
2549
|
+
* await context.sync();
|
|
2550
|
+
* });
|
|
2551
|
+
* ```
|
|
2552
|
+
* @public
|
|
2553
|
+
*/
|
|
2554
|
+
type PreviewCallback<T = void> = (context: RequestContext) => Promise<T>;
|
|
2555
|
+
/**
|
|
2556
|
+
* Options for {@link DocumentPreview.commit}.
|
|
2557
|
+
*
|
|
2558
|
+
* @example
|
|
2559
|
+
* ```ts
|
|
2560
|
+
* await preview.commit({ rebase: true });
|
|
2561
|
+
* ```
|
|
2562
|
+
* @public
|
|
2563
|
+
*/
|
|
2564
|
+
interface CommitPreviewOptions {
|
|
2565
|
+
/**
|
|
2566
|
+
* When the live document moved after the preview began, replay the preview on the current
|
|
2567
|
+
* document instead of refusing. Ranges follow the text they name, so an edit elsewhere, even
|
|
2568
|
+
* earlier in the same paragraph, rebases. The replay still refuses with `StaleDocument`, and
|
|
2569
|
+
* writes nothing, when a replayed read answers differently or a write would overwrite text
|
|
2570
|
+
* that changed: a search finds a different number of matches, text the preview read now
|
|
2571
|
+
* reads otherwise, or the range, paragraph, or span a write replaces or formats holds other
|
|
2572
|
+
* text. Omitted or false, any move refuses.
|
|
2573
|
+
*/
|
|
2574
|
+
readonly rebase?: boolean;
|
|
2575
|
+
}
|
|
2576
|
+
/**
|
|
2577
|
+
* Other wording, shown in the page over the live document until it is committed or
|
|
2578
|
+
* discarded. Answered by {@link DocxEditorRuntime.preview}.
|
|
2579
|
+
*
|
|
2580
|
+
* This is DocxEditor infrastructure with no Office.js equivalent.
|
|
2581
|
+
*
|
|
2582
|
+
* @example
|
|
2583
|
+
* ```ts
|
|
2584
|
+
* const preview = await runtime.preview(async (context) => {
|
|
2585
|
+
* context.document.changeTrackingMode = 'TrackMineOnly';
|
|
2586
|
+
* const range = context.document.body.search('thirty (30) days').getFirst();
|
|
2587
|
+
* range.insertText('forty-five (45) days', 'Replace');
|
|
2588
|
+
* await context.sync();
|
|
2589
|
+
* });
|
|
2590
|
+
* preview.reveal(); // scroll to the counter-proposal
|
|
2591
|
+
* // The page shows it as a tracked change. The live document is unchanged.
|
|
2592
|
+
* if (userAccepted) await preview.commit();
|
|
2593
|
+
* else preview.discard();
|
|
2594
|
+
* ```
|
|
2595
|
+
* @public
|
|
2596
|
+
*/
|
|
2597
|
+
interface DocumentPreview<T = void> {
|
|
2598
|
+
/**
|
|
2599
|
+
* What the callback answered, as `run()` answers its callback's value. Return plain data from
|
|
2600
|
+
* the callback, never a proxy: proxies end with the callback.
|
|
2601
|
+
*
|
|
2602
|
+
* @example
|
|
2603
|
+
* ```ts
|
|
2604
|
+
* const preview = await runtime.preview(async (context) => {
|
|
2605
|
+
* const range = context.document.body.search('thirty (30) days').getFirst();
|
|
2606
|
+
* range.insertText('forty-five (45) days', 'Replace');
|
|
2607
|
+
* await context.sync();
|
|
2608
|
+
* return { replaced: 'thirty (30) days' };
|
|
2609
|
+
* });
|
|
2610
|
+
* console.log(preview.result.replaced);
|
|
2611
|
+
* ```
|
|
2612
|
+
*/
|
|
2613
|
+
readonly result: T;
|
|
2614
|
+
/**
|
|
2615
|
+
* Where the preview is in its life. Read it at any time; it changes without a sync.
|
|
2616
|
+
*
|
|
2617
|
+
* @example
|
|
2618
|
+
* ```ts
|
|
2619
|
+
* if (preview.status === 'stale') await preview.commit({ rebase: true });
|
|
2620
|
+
* ```
|
|
2621
|
+
*/
|
|
2622
|
+
readonly status: DocumentPreviewStatus;
|
|
2623
|
+
/**
|
|
2624
|
+
* Write the preview to the live document as one undo step, then end the preview.
|
|
2625
|
+
*
|
|
2626
|
+
* Commit first validates every recorded batch against a fresh fork of the live document.
|
|
2627
|
+
* A divergent read changes neither the live document nor its undo and redo history.
|
|
2628
|
+
* It then replays the batches against the live document inside one editor history group.
|
|
2629
|
+
* Editor event listeners run after replay and its history group finish.
|
|
2630
|
+
* It never runs the callback again. A tracking mode the callback set
|
|
2631
|
+
* stays set on this runtime afterwards, as it does after `run()`.
|
|
2632
|
+
*
|
|
2633
|
+
* Refusals:
|
|
2634
|
+
*
|
|
2635
|
+
* - `StaleDocument` when the live document moved after the preview began
|
|
2636
|
+
* (`expectedRevision` and `actualRevision` say from where to where). Nothing is written and
|
|
2637
|
+
* the preview stays open: call `commit({ rebase: true })` or `discard()`.
|
|
2638
|
+
* - `StaleDocument` from `commit({ rebase: true })` when a replayed read answers differently
|
|
2639
|
+
* or a write would overwrite changed text (`edit.preview-diverged`). Nothing stays written, and the preview ends.
|
|
2640
|
+
* - `PreviewEnded` when the preview was already committed, discarded, or ended by a remount.
|
|
2641
|
+
* - Any refusal the live document gives a replayed batch, such as a collaboration session
|
|
2642
|
+
* that is not ready. Replayed writes before it are undone as one step, and the preview ends.
|
|
2643
|
+
* If that undo itself fails, the error is `GeneralException` with target `preview.rollback`.
|
|
2644
|
+
*
|
|
2645
|
+
* @example
|
|
2646
|
+
* ```ts
|
|
2647
|
+
* try {
|
|
2648
|
+
* await preview.commit();
|
|
2649
|
+
* } catch (error) {
|
|
2650
|
+
* if (!isDocxEditorError(error) || error.code !== 'StaleDocument') throw error;
|
|
2651
|
+
* if (preview.status === 'stale') await preview.commit({ rebase: true });
|
|
2652
|
+
* }
|
|
2653
|
+
* ```
|
|
2654
|
+
*/
|
|
2655
|
+
commit(options?: CommitPreviewOptions): Promise<void>;
|
|
2656
|
+
/**
|
|
2657
|
+
* End the preview without writing anything. The page shows the live document again, with
|
|
2658
|
+
* its selection, scroll position, and focus as they were. A tracking mode the callback set
|
|
2659
|
+
* is discarded with the preview. Safe to call more than once and after `commit()`.
|
|
2660
|
+
* Disposing the runtime that opened the preview discards it too.
|
|
2661
|
+
*
|
|
2662
|
+
* @example
|
|
2663
|
+
* ```ts
|
|
2664
|
+
* cancelButton.onclick = () => preview.discard();
|
|
2665
|
+
* ```
|
|
2666
|
+
*/
|
|
2667
|
+
discard(): void;
|
|
2668
|
+
/**
|
|
2669
|
+
* Scroll the page to the first paragraph of the document body the preview changed. Answers
|
|
2670
|
+
* false, scrolling nothing, when the preview has ended or changed no body paragraph: an
|
|
2671
|
+
* edit only in a header, a footer, or a note is not found.
|
|
2672
|
+
*
|
|
2673
|
+
* @example
|
|
2674
|
+
* ```ts
|
|
2675
|
+
* const preview = await runtime.preview(counterProposal);
|
|
2676
|
+
* preview.reveal();
|
|
2677
|
+
* ```
|
|
2678
|
+
*/
|
|
2679
|
+
reveal(): boolean;
|
|
2680
|
+
/**
|
|
2681
|
+
* Be told when {@link DocumentPreview.status} changes: to `stale` when the live document
|
|
2682
|
+
* moves, and to `ended` once. Returns a function that removes the listener.
|
|
2683
|
+
*
|
|
2684
|
+
* @example
|
|
2685
|
+
* ```ts
|
|
2686
|
+
* const stop = preview.onStatusChanged((status) => {
|
|
2687
|
+
* if (status === 'stale') showBanner('The clause changed since this preview.');
|
|
2688
|
+
* });
|
|
2689
|
+
* ```
|
|
2690
|
+
*/
|
|
2691
|
+
onStatusChanged(listener: (status: DocumentPreviewStatus) => void): () => void;
|
|
2692
|
+
}
|
|
2693
|
+
|
|
2324
2694
|
/** What a `run` callback is given, and what it may answer with. */
|
|
2325
2695
|
type RunCallback<T> = (context: RequestContext) => Promise<T>;
|
|
2696
|
+
/**
|
|
2697
|
+
* Options for {@link DocxEditorRuntime.run}, passed before the callback.
|
|
2698
|
+
*
|
|
2699
|
+
* This is DocxEditor infrastructure, not part of the Office.js object model: the Office.js
|
|
2700
|
+
* `run` function has no options and no undo grouping.
|
|
2701
|
+
*
|
|
2702
|
+
* @example
|
|
2703
|
+
* ```ts
|
|
2704
|
+
* // One review decision, one undo step: the editor's writes and every sync of the run.
|
|
2705
|
+
* const decision = editor.beginHistoryGroup();
|
|
2706
|
+
* try {
|
|
2707
|
+
* const resolved = editor.exec(
|
|
2708
|
+
* { type: 'resolveAllReviewChanges', action: 'reject', keys },
|
|
2709
|
+
* { historyGroup: decision }
|
|
2710
|
+
* );
|
|
2711
|
+
* if (!resolved.ok) throw new Error(resolved.reason);
|
|
2712
|
+
* await runtime.run({ historyGroup: decision }, async (context) => {
|
|
2713
|
+
* const ranges = context.document.body.search('30 days');
|
|
2714
|
+
* ranges.load('items');
|
|
2715
|
+
* await context.sync();
|
|
2716
|
+
* const target = ranges.items[0];
|
|
2717
|
+
* if (!target) throw new Error('The document has no "30 days" text.');
|
|
2718
|
+
* const replaced = target.insertText('45 days', 'Replace');
|
|
2719
|
+
* await context.sync();
|
|
2720
|
+
* replaced.insertComment('Counter-proposal: 45 days.');
|
|
2721
|
+
* await context.sync();
|
|
2722
|
+
* });
|
|
2723
|
+
* } finally {
|
|
2724
|
+
* decision.end();
|
|
2725
|
+
* }
|
|
2726
|
+
* ```
|
|
2727
|
+
* @public
|
|
2728
|
+
*/
|
|
2729
|
+
interface RunOptions {
|
|
2730
|
+
/**
|
|
2731
|
+
* Make every write this run commits part of an open editor history group, so one undo
|
|
2732
|
+
* reverts them together with the group's other writes.
|
|
2733
|
+
*
|
|
2734
|
+
* Pass the handle `editor.beginHistoryGroup()` returns, unchanged.
|
|
2735
|
+
*
|
|
2736
|
+
* Browser runtime only. A server or collaborative runtime refuses the run with
|
|
2737
|
+
* `NotSupported` before the callback starts. A closed handle, or a handle from another
|
|
2738
|
+
* editor, refuses with `InvalidArgument` and `target: 'historyGroup'` before the callback
|
|
2739
|
+
* starts. A handle that closes during the run refuses the next `context.sync()` the same way,
|
|
2740
|
+
* and that sync writes nothing. Runs without this option never join a group.
|
|
2741
|
+
*
|
|
2742
|
+
* The run has no `ExecResult`. The whole run is one write of the group: after the callback
|
|
2743
|
+
* finishes, `historyGroup.lastOutcome` holds its outcome, which is `split` if any sync split
|
|
2744
|
+
* the group. A split also emits the editor's `historyDiagnostic` event.
|
|
2745
|
+
*/
|
|
2746
|
+
readonly historyGroup?: HistoryGroup;
|
|
2747
|
+
/** Objects a previous run tracked, adopted by this run. The same as the object argument. */
|
|
2748
|
+
readonly previousObjects?: ClientObject | readonly ClientObject[];
|
|
2749
|
+
}
|
|
2326
2750
|
/** Capabilities exposed by a DocxEditor runtime, frozen for its lifetime. */
|
|
2327
2751
|
interface DocumentCapabilities {
|
|
2328
2752
|
/** There is a document to address at all. False for a browser host between mounts. */
|
|
@@ -2337,6 +2761,20 @@ interface DocumentCapabilities {
|
|
|
2337
2761
|
readonly scrolling: boolean;
|
|
2338
2762
|
/** The host lays the document out, so paginated positions are meaningful. */
|
|
2339
2763
|
readonly layout: boolean;
|
|
2764
|
+
/**
|
|
2765
|
+
* `preview()` is offered: true for a runtime over a live browser editor, false for a server
|
|
2766
|
+
* runtime, which has no page to show a preview in.
|
|
2767
|
+
*
|
|
2768
|
+
* @example
|
|
2769
|
+
* ```ts
|
|
2770
|
+
* if (runtime.capabilities.preview) {
|
|
2771
|
+
* const preview = await runtime.preview(counterProposal);
|
|
2772
|
+
* } else {
|
|
2773
|
+
* await runtime.run(counterProposal); // write directly, for example on a server
|
|
2774
|
+
* }
|
|
2775
|
+
* ```
|
|
2776
|
+
*/
|
|
2777
|
+
readonly preview: boolean;
|
|
2340
2778
|
}
|
|
2341
2779
|
/**
|
|
2342
2780
|
* A runtime: one document host, many runs.
|
|
@@ -2358,6 +2796,75 @@ interface DocxEditorRuntime {
|
|
|
2358
2796
|
run<T>(callback: RunCallback<T>): Promise<T>;
|
|
2359
2797
|
/** Run one batch of work, adopting objects a previous run tracked. */
|
|
2360
2798
|
run<T>(object: ClientObject | readonly ClientObject[], callback: RunCallback<T>): Promise<T>;
|
|
2799
|
+
/**
|
|
2800
|
+
* Run one batch of work with options, such as an editor history group.
|
|
2801
|
+
*
|
|
2802
|
+
* @example
|
|
2803
|
+
* ```ts
|
|
2804
|
+
* const decision = editor.beginHistoryGroup();
|
|
2805
|
+
* await runtime.run({ historyGroup: decision }, async (context) => {
|
|
2806
|
+
* context.document.body.insertParagraph('Revised terms follow.', 'End');
|
|
2807
|
+
* await context.sync();
|
|
2808
|
+
* });
|
|
2809
|
+
* ```
|
|
2810
|
+
*/
|
|
2811
|
+
run<T>(options: RunOptions, callback: RunCallback<T>): Promise<T>;
|
|
2812
|
+
/**
|
|
2813
|
+
* Show other wording in the page without writing it, until the answered preview is
|
|
2814
|
+
* committed or discarded.
|
|
2815
|
+
*
|
|
2816
|
+
* The callback gets an ordinary request context. Its reads and writes address a private
|
|
2817
|
+
* copy of the document, and the page paints that copy when the callback finishes. The live
|
|
2818
|
+
* document, its undo history, and every collaboration peer see nothing until
|
|
2819
|
+
* `preview.commit()`, which writes the preview as one undo step. This is DocxEditor
|
|
2820
|
+
* infrastructure; Office.js has no preview.
|
|
2821
|
+
*
|
|
2822
|
+
* The live editor stays editable while the callback runs; build the preview from data you
|
|
2823
|
+
* already have, because a write that lands meanwhile makes the preview start `stale`. Once
|
|
2824
|
+
* the preview shows, the editor refuses document writes: `editor.exec()` edits, typing,
|
|
2825
|
+
* undo and redo, and writes from any runtime, which refuse with `PreviewActive`. Zoom,
|
|
2826
|
+
* paragraph marks, the review pane toggle, and selection keep working. Reads from `run()` see
|
|
2827
|
+
* the live document; reads inside the preview callback see the preview. The review rail and
|
|
2828
|
+
* the editor's text highlights keep describing the live document, and the highlights are
|
|
2829
|
+
* hidden while the preview shows.
|
|
2830
|
+
*
|
|
2831
|
+
* In suggesting mode, a write the callback makes with tracking off becomes a suggestion
|
|
2832
|
+
* attributed to the editor's author, in the preview and at commit alike, as it does in
|
|
2833
|
+
* `run()`.
|
|
2834
|
+
*
|
|
2835
|
+
* Refusals, after each of which nothing is shown and nothing is written; `debugInfo.innerError`
|
|
2836
|
+
* names the reason:
|
|
2837
|
+
*
|
|
2838
|
+
* - `NotSupported` (target `preview`) on a server runtime, while the editor is open for
|
|
2839
|
+
* viewing (`edit.read-only`), while an external refresh replaces the document
|
|
2840
|
+
* (`edit.refresh-in-progress`), or during an input method composition
|
|
2841
|
+
* (`edit.preview-composing`).
|
|
2842
|
+
* - `PreviewActive` (`edit.preview-active`) while another preview is open on the editor.
|
|
2843
|
+
* - `DocumentUnavailable` while the editor holds no mounted document.
|
|
2844
|
+
* - `NotSupported` (`edit.preview-unsupported`) from `context.sync()` for a write a preview
|
|
2845
|
+
* cannot show: tables, pictures, fields, lists, hyperlinks, content controls, creating or
|
|
2846
|
+
* deleting headers, footers, and notes, section and page setup, page and section breaks,
|
|
2847
|
+
* and selection. Text edits in headers, footers, and notes show and commit.
|
|
2848
|
+
* - The same refusal `run()` would give for a write the live editor refuses: a protected
|
|
2849
|
+
* range, a generated table of contents, a collaboration session that is not ready, or a
|
|
2850
|
+
* comment outside the body (`edit.unsupported-story`). A preview never shows what its
|
|
2851
|
+
* commit would refuse.
|
|
2852
|
+
* - Any error the callback throws. The preview ends, and the error propagates unchanged.
|
|
2853
|
+
*
|
|
2854
|
+
* @example
|
|
2855
|
+
* ```ts
|
|
2856
|
+
* const preview = await runtime.preview(async (context) => {
|
|
2857
|
+
* context.document.changeTrackingMode = 'TrackMineOnly';
|
|
2858
|
+
* const range = context.document.body.search('thirty (30) days of receipt').getFirst();
|
|
2859
|
+
* range.insertText('forty-five (45) days of receipt', 'Replace');
|
|
2860
|
+
* await context.sync();
|
|
2861
|
+
* });
|
|
2862
|
+
* preview.reveal();
|
|
2863
|
+
* // Later, from the review UI:
|
|
2864
|
+
* await preview.commit(); // or preview.discard()
|
|
2865
|
+
* ```
|
|
2866
|
+
*/
|
|
2867
|
+
preview<T = void>(callback: PreviewCallback<T>): Promise<DocumentPreview<T>>;
|
|
2361
2868
|
/** Release the host. Idempotent. */
|
|
2362
2869
|
dispose(): void;
|
|
2363
2870
|
}
|
|
@@ -2412,7 +2919,7 @@ declare class TrackedObjects {
|
|
|
2412
2919
|
/** What a context needs from the runtime that made it. */
|
|
2413
2920
|
interface RuntimeSession {
|
|
2414
2921
|
readonly host: AutomationHost;
|
|
2415
|
-
readonly capabilities:
|
|
2922
|
+
readonly capabilities: DocumentCapabilities;
|
|
2416
2923
|
/** Who a comment this runtime writes is recorded as, or absent when it may not write one. */
|
|
2417
2924
|
readonly author?: string;
|
|
2418
2925
|
/** Revision view used by standard Office-compatible text reads and searches. */
|
|
@@ -2586,10 +3093,17 @@ interface LoadQueryOptions {
|
|
|
2586
3093
|
* paragraph.load('text');
|
|
2587
3094
|
* paragraph.load(['text', 'style']);
|
|
2588
3095
|
* paragraphs.load({ select: 'items', top: 5 });
|
|
3096
|
+
* paragraphs.load('items/text,items/style');
|
|
2589
3097
|
* ```
|
|
2590
3098
|
*
|
|
2591
|
-
*
|
|
2592
|
-
*
|
|
3099
|
+
* On a collection, `items/<property>` loads `items` and that property on each item in the same
|
|
3100
|
+
* `context.sync()`. A property name without the `items/` prefix means the same thing on a
|
|
3101
|
+
* collection, so `paragraphs.load('text')` equals `paragraphs.load('items/text')`.
|
|
3102
|
+
*
|
|
3103
|
+
* Only one level of navigation is supported. A deeper path, such as `items/font/bold`, and a
|
|
3104
|
+
* navigation path on an object that is not a collection, such as `font/bold`, are refused as
|
|
3105
|
+
* `InvalidArgument`, with the path as the error's `target`. Load the navigation object itself
|
|
3106
|
+
* instead, for example `paragraph.font.load('bold')` for each item.
|
|
2593
3107
|
*
|
|
2594
3108
|
* @public
|
|
2595
3109
|
*/
|
|
@@ -2597,6 +3111,11 @@ type LoadOption = string | readonly string[] | LoadQueryOptions;
|
|
|
2597
3111
|
interface ResolvedLoadOptions {
|
|
2598
3112
|
/** Selected property names. Empty means "this object's default set". */
|
|
2599
3113
|
readonly select: readonly string[];
|
|
3114
|
+
/**
|
|
3115
|
+
* Property names selected with an `items/` path, to load on each item of a collection. Empty
|
|
3116
|
+
* when none was named. An object that is not a collection refuses a non-empty list.
|
|
3117
|
+
*/
|
|
3118
|
+
readonly itemSelect: readonly string[];
|
|
2600
3119
|
readonly top?: number;
|
|
2601
3120
|
readonly skip?: number;
|
|
2602
3121
|
}
|
|
@@ -2640,6 +3159,8 @@ declare abstract class ClientObject implements RuntimeManagedObject {
|
|
|
2640
3159
|
load(option?: LoadOption): this;
|
|
2641
3160
|
/** What this kind of object does with a resolved load request. */
|
|
2642
3161
|
protected abstract onLoad(request: ResolvedLoadOptions): void;
|
|
3162
|
+
/** @internal Whether `load(...)` accepts `items/<property>` paths. Only collections do. */
|
|
3163
|
+
protected get loadsItemPaths(): boolean;
|
|
2643
3164
|
/** @internal This object's address, or the placeholder standing in until a sync resolves it. */
|
|
2644
3165
|
protected get path(): ObjectPath;
|
|
2645
3166
|
/** @internal The owning context's internal surface. */
|
|
@@ -2861,6 +3382,108 @@ declare class Body extends ModelObject {
|
|
|
2861
3382
|
get tables(): TableCollection;
|
|
2862
3383
|
}
|
|
2863
3384
|
|
|
3385
|
+
/**
|
|
3386
|
+
* The tracked changes a review card stands for, by the key the editor's review queue gives it.
|
|
3387
|
+
*
|
|
3388
|
+
* Pass the `key` of a revision item from `editor.getReviewItems()` or `useReview().items`. The
|
|
3389
|
+
* collection holds that change only, or the deletion and the insertion of a paired replacement.
|
|
3390
|
+
* Unlike {@link Range.revisions} on the card's range, it never holds a nested or adjacent change
|
|
3391
|
+
* by another author.
|
|
3392
|
+
*
|
|
3393
|
+
* A key that names nothing in the document, such as one whose change was already resolved,
|
|
3394
|
+
* loads an empty collection, and `acceptAll()` or `rejectAll()` on it refuses with
|
|
3395
|
+
* `InvalidObjectPath`. A comment or custom node key refuses with `NotSupported` at the call.
|
|
3396
|
+
* `resolve()` and `setAuthor()` refuse with `NotSupported` on this collection.
|
|
3397
|
+
*
|
|
3398
|
+
* This is a DocxEditor addition. Office.js has no review queue and no key for a revision.
|
|
3399
|
+
*
|
|
3400
|
+
* @param context - The request context of the current `run()`.
|
|
3401
|
+
* @param key - The review item's `key`.
|
|
3402
|
+
* @returns The change or changes that the key names.
|
|
3403
|
+
*
|
|
3404
|
+
* @example Accept the change a review card shows
|
|
3405
|
+
* ```ts
|
|
3406
|
+
* import { getReviewItemRevisions } from '@docx-editor.dev/editor-api/browser';
|
|
3407
|
+
*
|
|
3408
|
+
* const key = item.key; // From useReview().items or editor.getReviewItems().
|
|
3409
|
+
* await runtime.run(async (context) => {
|
|
3410
|
+
* getReviewItemRevisions(context, key).acceptAll();
|
|
3411
|
+
* await context.sync();
|
|
3412
|
+
* });
|
|
3413
|
+
* ```
|
|
3414
|
+
*
|
|
3415
|
+
* @public
|
|
3416
|
+
*/
|
|
3417
|
+
declare function getReviewItemRevisions(context: RequestContext, key: string): RevisionCollection;
|
|
3418
|
+
/**
|
|
3419
|
+
* The range a review item covers, by the key the editor's review queue gives it.
|
|
3420
|
+
*
|
|
3421
|
+
* Pass the `key` of an item from `editor.getReviewItems()` or `useReview().items`. A tracked
|
|
3422
|
+
* change resolves to the characters it covers. A paired replacement key resolves to one range
|
|
3423
|
+
* over both its deletion and its insertion. A comment or reply resolves to the range its thread
|
|
3424
|
+
* is anchored to. The range is a snapshot like any other.
|
|
3425
|
+
*
|
|
3426
|
+
* To act on the card's own change, use {@link getReviewItemRevisions}. {@link Range.revisions} on
|
|
3427
|
+
* this range also lists nested or adjacent changes that the range overlaps.
|
|
3428
|
+
*
|
|
3429
|
+
* A key that names nothing in the document, such as one whose change was already accepted, or a
|
|
3430
|
+
* comment with no anchor in the document, fails the sync with `ItemNotFound`. Use
|
|
3431
|
+
* {@link getReviewItemRangeOrNullObject} to test for that instead. A custom node's key refuses
|
|
3432
|
+
* with `NotSupported` at the call.
|
|
3433
|
+
*
|
|
3434
|
+
* This is a DocxEditor addition. Office.js has no review queue and no key for a revision.
|
|
3435
|
+
*
|
|
3436
|
+
* @param context - The request context of the current `run()`.
|
|
3437
|
+
* @param key - The review item's `key`.
|
|
3438
|
+
* @returns A range that becomes addressable at the next `context.sync()`.
|
|
3439
|
+
*
|
|
3440
|
+
* @example Read the words a comment card is about
|
|
3441
|
+
* ```ts
|
|
3442
|
+
* import { getReviewItemRange } from '@docx-editor.dev/editor-api/browser';
|
|
3443
|
+
*
|
|
3444
|
+
* const key = item.key; // From useReview().items or editor.getReviewItems().
|
|
3445
|
+
* const text = await runtime.run(async (context) => {
|
|
3446
|
+
* const range = getReviewItemRange(context, key);
|
|
3447
|
+
* range.load('text');
|
|
3448
|
+
* await context.sync();
|
|
3449
|
+
* return range.text;
|
|
3450
|
+
* });
|
|
3451
|
+
* ```
|
|
3452
|
+
*
|
|
3453
|
+
* @public
|
|
3454
|
+
*/
|
|
3455
|
+
declare function getReviewItemRange(context: RequestContext, key: string): Range;
|
|
3456
|
+
/**
|
|
3457
|
+
* The range a review item covers, or a null object when the key names nothing.
|
|
3458
|
+
*
|
|
3459
|
+
* The same lookup as {@link getReviewItemRange}. A key that names nothing in the document
|
|
3460
|
+
* answers a range whose `isNullObject` is `true` after the sync, instead of failing it.
|
|
3461
|
+
*
|
|
3462
|
+
* This is a DocxEditor addition. Office.js has no review queue and no key for a revision.
|
|
3463
|
+
*
|
|
3464
|
+
* @param context - The request context of the current `run()`.
|
|
3465
|
+
* @param key - The review item's `key`.
|
|
3466
|
+
* @returns A range whose `isNullObject` is known after the next `context.sync()`.
|
|
3467
|
+
*
|
|
3468
|
+
* @example Skip a card whose change another reviewer already resolved
|
|
3469
|
+
* ```ts
|
|
3470
|
+
* import { getReviewItemRangeOrNullObject } from '@docx-editor.dev/editor-api/browser';
|
|
3471
|
+
*
|
|
3472
|
+
* const key = item.key; // From useReview().items or editor.getReviewItems().
|
|
3473
|
+
* await runtime.run(async (context) => {
|
|
3474
|
+
* const range = getReviewItemRangeOrNullObject(context, key);
|
|
3475
|
+
* range.load('text');
|
|
3476
|
+
* await context.sync();
|
|
3477
|
+
*
|
|
3478
|
+
* if (range.isNullObject) return;
|
|
3479
|
+
* console.log(range.text);
|
|
3480
|
+
* });
|
|
3481
|
+
* ```
|
|
3482
|
+
*
|
|
3483
|
+
* @public
|
|
3484
|
+
*/
|
|
3485
|
+
declare function getReviewItemRangeOrNullObject(context: RequestContext, key: string): Range;
|
|
3486
|
+
|
|
2864
3487
|
/** Explicit measurement inputs for headless field calculation. @public */
|
|
2865
3488
|
interface ServerPaginationOptions extends AutomationPaginationOptions {
|
|
2866
3489
|
}
|
|
@@ -3004,5 +3627,5 @@ interface CreateServerOptions {
|
|
|
3004
3627
|
/** Options for {@link createCollaborative}. @public */
|
|
3005
3628
|
type CreateCollaborativeOptions = CreateServerOptions;
|
|
3006
3629
|
|
|
3007
|
-
export {
|
|
3008
|
-
export type { BesideLocation as B, CreateServerOptions as C, DocxEditorServerRuntime as D, DocxEditorDebugInfo as
|
|
3630
|
+
export { ListNumbering as $, Alignment as A, DocumentProperties as E, DocxEditorError as I, Field as O, FieldCollection as P, FieldType as Q, Font as S, InlinePicture as U, InlinePictureCollection as V, InsertLocation as W, List as X, ListBullet as Y, ListCollection as Z, ListItem as _, NoteItem as a2, NoteItemCollection as a3, PageOrientation as a5, PageSetup as a6, Paragraph as a7, ParagraphCollection as a9, TableCell as aA, TableCellCollection as aB, TableCollection as aC, TableRow as aD, TableRowCollection as aE, TrackedObjects as aF, UnderlineType as aG, VerticalAlignment as aH, getReviewItemRange as aI, getReviewItemRangeOrNullObject as aJ, getReviewItemRevisions as aK, isDocxEditorError as aL, Range as ad, RangeCollection as ae, RemoveDocInfoType as ag, RequestContext as ah, Revision as ai, RevisionCollection as al, Section as as, SectionCollection as at, Shape as aw, ShapeCollection as ax, ShapeType as ay, Table as az, Body as b, Bookmark as e, BookmarkCollection as f, BreakType as g, ChangeTrackingMode as h, ClientObject as i, ClientResult as j, Comment as k, CommentCollection as l, CommentReply as m, CommentReplyCollection as n, ContentControl as p, ContentControlCollection as q, ContentControlType as t, Document as v };
|
|
3631
|
+
export type { BesideLocation as B, CreateServerOptions as C, DocxEditorServerRuntime as D, DocumentXmlLimits as F, DocumentZipLimits as G, DocxEditorDebugInfo as H, DocxEditorErrorCode as J, DocxEditorErrorInit as K, DocxEditorInnerError as L, DocxEditorRuntime as M, EditorModule as N, FieldTypeLiteral as R, HeaderFooterType as T, CreateCollaborativeOptions as a, LoadOption as a0, LoadQueryOptions as a1, NoteItemType as a4, ParagraphAlignment as a8, ParagraphInsertTextLocation as aa, ParagraphReadingOrder as ab, PreviewCallback as ac, RangeInsertTextLocation as af, RevisionAuthorOptions as aj, RevisionAuthorSelection as ak, RevisionTextView as am, RevisionType as an, RunCallback as ao, RunOptions as ap, RuntimeDiagnostic as aq, SearchOptions as ar, SelectionMode as au, ServerPaginationOptions as av, BodyInsertParagraphLocation as c, BodyInsertTextLocation as d, CommitPreviewOptions as o, ContentControlLockState as r, ContentControlSubtype as s, ContentControlValue as u, DocumentCapabilities as w, DocumentLimits as x, DocumentPreview as y, DocumentPreviewStatus as z };
|