@stll/docx-core 0.28.1 → 0.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,19 @@
1
- import { Jt as ParagraphMarkChange, Kt as Paragraph, Wr as TextFormatting, kr as ParagraphFormatting, n as Document, qt as ParagraphContent } from "../document-DrtmJ_hz.js";
1
+ import { Jt as ParagraphMarkChange, Kt as Paragraph, Wr as TextFormatting, Xt as ParagraphPropertyChange, kr as ParagraphFormatting, n as Document, qt as ParagraphContent, zn as TableRow } from "../document-DrtmJ_hz.js";
2
2
  import { Result } from "better-result";
3
3
  //#region src/ops/types.d.ts
4
- /** The operation schema this module reads and writes. */
5
- declare const DOCUMENT_OP_SCHEMA_VERSION = 1;
4
+ /**
5
+ * The operation schema this module reads and writes.
6
+ *
7
+ * Version 3 adds paragraph insertion through `insertBlocks` and the table-row
8
+ * operations `insertRow`, `deleteRow` and `setTableRows`.
9
+ * Version 2 added tracked changes: the `revision` stamp on the text, formatting
10
+ * and paragraph operations, and the review operations `setParagraphReview`,
11
+ * `replaceInline` and `resolveRevision`.
12
+ */
13
+ declare const DOCUMENT_OP_SCHEMA_VERSION = 3;
6
14
  /**
7
15
  * The stories an operation can address. Headers, footers, notes and comment
8
- * bodies are stories too; version 1 addresses the main story only.
16
+ * bodies are stories too; this version addresses the main story only.
9
17
  */
10
18
  declare const OP_STORIES: Readonly<{
11
19
  readonly MAIN: "main";
@@ -84,10 +92,29 @@ type NewIds = {
84
92
  /** For content controls (`w:sdtPr/w:id`). */
85
93
  control?: readonly number[];
86
94
  };
95
+ /**
96
+ * Who made a tracked change and when, and the revision id (`w:id`) of the
97
+ * first record the change creates.
98
+ *
99
+ * An operation carrying a stamp records its edit as a tracked change instead
100
+ * of making it: the stamp's id names the first record the edit creates and
101
+ * `newIds.revision` names the others, in document order. The id must be unused
102
+ * in the package. A new tracked wrapper that would sit next to one with the
103
+ * same author, date and initials merges into it and creates no record, so an
104
+ * author's burst of typing reads as one change.
105
+ */
106
+ type RevisionStamp = {
107
+ id: number;
108
+ author: string;
109
+ /** `w:date`, as the author's client stated it. */
110
+ date: string;
111
+ initials?: string;
112
+ };
87
113
  /** The paragraph fields a split gives the new paragraph, besides its id, content and mark. */
88
114
  type SplitParagraphFields = Omit<Paragraph, "type" | "paraId" | "content" | "sectionProperties" | "pPrMark">;
89
- /** The operation kinds of schema version 1. */
115
+ /** The operation kinds of schema version 3. */
90
116
  declare const DOCUMENT_OP_TYPES: Readonly<{
117
+ readonly INSERT_BLOCKS: "insertBlocks";
91
118
  readonly INSERT_TEXT: "insertText";
92
119
  readonly INSERT_CONTENT: "insertContent";
93
120
  readonly DELETE_RANGE: "deleteRange";
@@ -98,6 +125,12 @@ declare const DOCUMENT_OP_TYPES: Readonly<{
98
125
  readonly SPLIT_BLOCK: "splitBlock";
99
126
  readonly JOIN_BLOCKS: "joinBlocks";
100
127
  readonly REPLACE_BLOCKS: "replaceBlocks";
128
+ readonly SET_PARAGRAPH_REVIEW: "setParagraphReview";
129
+ readonly REPLACE_INLINE: "replaceInline";
130
+ readonly RESOLVE_REVISION: "resolveRevision";
131
+ readonly INSERT_ROW: "insertRow";
132
+ readonly DELETE_ROW: "deleteRow";
133
+ readonly SET_TABLE_ROWS: "setTableRows";
101
134
  }>;
102
135
  /** One of {@link DOCUMENT_OP_TYPES}. */
103
136
  type DocumentOpType = (typeof DOCUMENT_OP_TYPES)[keyof typeof DOCUMENT_OP_TYPES];
@@ -109,6 +142,11 @@ type DocumentOpType = (typeof DOCUMENT_OP_TYPES)[keyof typeof DOCUMENT_OP_TYPES]
109
142
  * becomes a run of its own and that run is split around it; `newIds` names
110
143
  * the ids of the second half when the run carries some. The run decides where
111
144
  * the text goes, so `at.zeroWidthBefore` is not read.
145
+ *
146
+ * With `revision`, the text is a tracked insertion: it is wrapped in an
147
+ * `Insertion` carrying the stamp, cutting the records around it down to a
148
+ * level that admits one. Text landing inside another stamp's insertion or
149
+ * move splits that record around it rather than nesting inside it.
112
150
  */
113
151
  type InsertTextOp = {
114
152
  type: typeof DOCUMENT_OP_TYPES.INSERT_TEXT;
@@ -117,6 +155,7 @@ type InsertTextOp = {
117
155
  text: string;
118
156
  runProps: InsertedRunProps;
119
157
  newIds?: NewIds;
158
+ revision?: RevisionStamp;
120
159
  };
121
160
  /**
122
161
  * Insert paragraph content at a position: runs, fields, markers, anything a
@@ -127,12 +166,18 @@ type InsertTextOp = {
127
166
  * slice that would merge two records that were separate is refused.
128
167
  * Absent `zeroWidthBefore` puts the point before the first zero-width child
129
168
  * at the offset that opens a range, after the others.
169
+ *
170
+ * With `revision`, the inserted content is a tracked insertion, as for
171
+ * {@link InsertTextOp}. It is refused inside tracked-removed content, and
172
+ * when it holds a comment boundary or reference, which no tracked change can
173
+ * hold.
130
174
  */
131
175
  type InsertContentOp = {
132
176
  type: typeof DOCUMENT_OP_TYPES.INSERT_CONTENT;
133
177
  at: TextPosition;
134
178
  slice: InlineSlice;
135
179
  newIds?: NewIds;
180
+ revision?: RevisionStamp;
136
181
  };
137
182
  /**
138
183
  * Remove what lies between two positions of one paragraph: its units and the
@@ -147,6 +192,15 @@ type InsertContentOp = {
147
192
  * `expected` is the slice the deletion must remove, compared without the
148
193
  * fields a relayout recomputes. It is how an inverse refuses to apply to
149
194
  * content that has changed since.
195
+ *
196
+ * With `revision`, the deletion is tracked and removes nothing. Content
197
+ * already inside a deletion or moved away is left as it is; content inside an
198
+ * insertion or a move gets a deletion nested inside that record; everything
199
+ * else is wrapped in a `Deletion` carrying the stamp, an inline content
200
+ * control the range covers whole going in with its content. A range holding
201
+ * a comment boundary or reference is refused, since no tracked change can
202
+ * hold one; `planTrackedDeletion` plans the deletions around them. A tracked
203
+ * deletion joins nothing, so `join` must be absent.
150
204
  */
151
205
  type DeleteRangeOp = {
152
206
  type: typeof DOCUMENT_OP_TYPES.DELETE_RANGE;
@@ -154,6 +208,8 @@ type DeleteRangeOp = {
154
208
  to: TextPosition;
155
209
  join?: number;
156
210
  expected?: InlineSlice;
211
+ newIds?: NewIds;
212
+ revision?: RevisionStamp;
157
213
  };
158
214
  /**
159
215
  * Cut the innermost `depth` records that run across a position in two,
@@ -187,6 +243,12 @@ type JoinInlineOp = {
187
243
  * `joinStart` and `joinEnd` merge the runs meeting at the range ends that many
188
244
  * levels once the patch is applied, as {@link JoinInlineOp} does; the inverse
189
245
  * of a patch that cut runs uses them.
246
+ *
247
+ * With `revision`, every run the patch changes records a tracked property
248
+ * change (`w:rPrChange`) whose previous formatting is the run's own property
249
+ * set before the patch. A run already carrying one keeps it, and with it the
250
+ * formatting it started from. A tracked patch joins nothing, so `joinStart`
251
+ * and `joinEnd` must be absent.
190
252
  */
191
253
  type SetRunPropsOp = {
192
254
  type: typeof DOCUMENT_OP_TYPES.SET_RUN_PROPS;
@@ -198,11 +260,18 @@ type SetRunPropsOp = {
198
260
  joinStart?: number;
199
261
  joinEnd?: number;
200
262
  newIds?: NewIds;
263
+ revision?: RevisionStamp;
201
264
  };
202
265
  /**
203
266
  * Patch a paragraph's own property set. `expected` states the values the
204
267
  * patched keys must have (`null` for absent) and refuses the patch as stale
205
268
  * otherwise.
269
+ *
270
+ * With `revision`, the paragraph records a tracked property change
271
+ * (`w:pPrChange`) whose previous formatting is its own property set before
272
+ * the patch, or keeps the one it already carries. A property change holds
273
+ * paragraph properties only, not the paragraph mark's run properties, so a
274
+ * tracked patch of {@link PARAGRAPH_MARK_FORMATTING_KEYS} is refused.
206
275
  */
207
276
  type SetParagraphPropsOp = {
208
277
  type: typeof DOCUMENT_OP_TYPES.SET_PARAGRAPH_PROPS;
@@ -211,42 +280,81 @@ type SetParagraphPropsOp = {
211
280
  patch: ParagraphPropsPatch;
212
281
  whenEmpty?: EmptyPropertySet;
213
282
  expected?: ParagraphPropsPatch;
283
+ revision?: RevisionStamp;
214
284
  };
285
+ /**
286
+ * Paragraph formatting that belongs to the paragraph mark's run properties
287
+ * (`w:pPr/w:rPr`) rather than to the paragraph properties a `w:pPrChange`
288
+ * records.
289
+ */
290
+ declare const PARAGRAPH_MARK_FORMATTING_KEYS: readonly ["runProperties", "runInWithNext"];
291
+ /** Which half of a split, or of a join, a rule applies to. */
292
+ declare const SPLIT_HALVES: Readonly<{
293
+ readonly FIRST: "first";
294
+ readonly SECOND: "second";
295
+ }>;
296
+ /** One of {@link SPLIT_HALVES}. */
297
+ type SplitHalf = (typeof SPLIT_HALVES)[keyof typeof SPLIT_HALVES];
215
298
  /**
216
299
  * Split a paragraph in two at a position.
217
300
  *
218
- * The half before the position keeps the paragraph's identity: its `paraId`,
219
- * `textId`, unmodelled attributes and tracked property change. The half after
220
- * it is a new paragraph named `newBlockId`; it holds the paragraph mark, so the
221
- * section break and a tracked mark change move with it. It takes the fields in
222
- * `newParagraph`, or a copy of the paragraph's properties when the operation
223
- * states none. `firstMark` is the tracked change of the mark the split
224
- * creates. Absent `zeroWidthBefore` keeps zero-width children that open a
225
- * range with the new paragraph.
301
+ * One half keeps the paragraph's identity and own fields (`paraId`, `textId`,
302
+ * unmodelled attributes, properties); the other is a new paragraph named
303
+ * `newBlockId`, taking the fields in `newParagraph`, or a copy of the
304
+ * paragraph's properties when the operation states none. `newHalf` says which
305
+ * half is new: by default the second when the position ends the paragraph
306
+ * (a paragraph added after it), else the first (the text before the position
307
+ * moves to a paragraph of its own, and the paragraph continues with the rest).
308
+ * The paragraph mark always ends the second half, so the section break, the
309
+ * mark's tracked change and the pending property changes go with it; when the
310
+ * second half is the new one, `newParagraph` states no property changes.
311
+ * `firstMark` is the tracked change of the mark the split creates, which ends
312
+ * the first half. Absent `zeroWidthBefore` keeps zero-width children that
313
+ * open a range with the second half.
226
314
  *
227
315
  * A split inside a tracked change, a content control or a run with a tracked
228
- * property change continues it in the new paragraph as a record of its own:
316
+ * property change continues it in the second half as a record of its own:
229
317
  * `newIds` names its ids, outermost record first.
318
+ *
319
+ * With `revision`, the mark the split creates is a tracked insertion
320
+ * (`firstMark` must then be absent), and the new paragraph, when its paragraph
321
+ * properties differ from the source's and it carries no property change,
322
+ * records one from the source's. Rejecting the mark removes it, which leaves
323
+ * the second half with the first's content before its own.
230
324
  */
231
325
  type SplitBlockOp = {
232
326
  type: typeof DOCUMENT_OP_TYPES.SPLIT_BLOCK;
233
327
  at: TextPosition;
234
328
  /** `w14:paraId` of the new paragraph: eight hex digits, unused in the document. */
235
329
  newBlockId: string;
330
+ newHalf?: SplitHalf;
236
331
  newParagraph?: SplitParagraphFields;
237
332
  firstMark?: ParagraphMarkChange;
238
333
  newIds?: NewIds;
334
+ revision?: RevisionStamp;
239
335
  };
240
336
  /**
241
337
  * Join a paragraph with the paragraph that directly follows it in the same
242
- * container. The first keeps its identity and properties; the second's content
243
- * and paragraph mark (section break, tracked mark change) join it, and the
244
- * second's id is retired. `depth` merges that many levels of the records
245
- * meeting at the join, as {@link JoinInlineOp} does.
338
+ * container. The joined paragraph has the first's paragraph properties, or
339
+ * the second's when the first holds no content, and the second's mark: its
340
+ * run properties, section break, tracked change and the pending property
341
+ * changes. It keeps the identity and own fields of the
342
+ * `survivor` half, by default the second, and the other's id is retired.
343
+ * `depth` merges that many levels of the records meeting at the join, as
344
+ * {@link JoinInlineOp} does.
345
+ *
346
+ * `expectedRetired` states the own fields of the paragraph the join retires,
347
+ * and `expectedSurvivor` the review fields of the one it keeps, which the
348
+ * join replaces; either refuses the join as stale when it differs (fields a
349
+ * relayout recomputes are not compared).
246
350
  *
247
- * `expectedSecond` states the second paragraph's own fields, which the join
248
- * discards, and refuses the join as stale when they differ (fields a relayout
249
- * recomputes are not compared).
351
+ * With `revision`, the join is tracked and moves nothing: the first
352
+ * paragraph's mark becomes a tracked deletion, refused when the mark already
353
+ * carries a tracked change, and the second takes the paragraph properties
354
+ * the direct join would give it as a tracked property change. Accepting removes the mark, which
355
+ * leaves the second paragraph with the first's content before its own: what
356
+ * the direct join leaves. A tracked join always leaves the second, so
357
+ * `survivor` must then be absent or `second`.
250
358
  */
251
359
  type JoinBlocksOp = {
252
360
  type: typeof DOCUMENT_OP_TYPES.JOIN_BLOCKS;
@@ -254,7 +362,37 @@ type JoinBlocksOp = {
254
362
  blockId: string;
255
363
  nextBlockId: string;
256
364
  depth?: number;
257
- expectedSecond?: SplitParagraphFields;
365
+ survivor?: SplitHalf;
366
+ expectedRetired?: SplitParagraphFields;
367
+ expectedSurvivor?: ParagraphReviewFields;
368
+ newIds?: NewIds;
369
+ revision?: RevisionStamp;
370
+ };
371
+ /** A paragraph-relative insertion point in one block list. */
372
+ type BlockInsertionPoint = {
373
+ type: "before";
374
+ blockId: string;
375
+ } | {
376
+ type: "after";
377
+ blockId: string;
378
+ };
379
+ /**
380
+ * Insert paragraphs beside an existing paragraph, with pre-minted ids.
381
+ * Section-bearing paragraphs are refused. With `revision`, each inserted
382
+ * paragraph receives an inserted mark and its content an insertion wrapper.
383
+ * Tracked insertion requires a following paragraph in the same block list;
384
+ * terminal insertion and insertion immediately before non-paragraph blocks
385
+ * are refused as `untrackable`.
386
+ * Incoming revision and content-control identities are refused in tracked
387
+ * mode rather than nesting reviews or rewriting supplied identities.
388
+ */
389
+ type InsertBlocksOp = {
390
+ type: typeof DOCUMENT_OP_TYPES.INSERT_BLOCKS;
391
+ story: OpStory;
392
+ at: BlockInsertionPoint;
393
+ blocks: readonly Paragraph[];
394
+ revision?: RevisionStamp;
395
+ newIds?: NewIds;
258
396
  };
259
397
  /**
260
398
  * Replace a run of adjacent paragraphs with other paragraphs.
@@ -262,7 +400,7 @@ type JoinBlocksOp = {
262
400
  * `expected` is the paragraphs as they stand: they are found by `paraId` and
263
401
  * compared structurally (without the fields a relayout recomputes), so a
264
402
  * replacement authored against another state is refused rather than applied
265
- * over it. No other operation's inverse is a replacement.
403
+ * over it. Paragraph insertion uses an anchored replacement as its inverse.
266
404
  */
267
405
  type ReplaceBlocksOp = {
268
406
  type: typeof DOCUMENT_OP_TYPES.REPLACE_BLOCKS;
@@ -270,8 +408,128 @@ type ReplaceBlocksOp = {
270
408
  expected: readonly Paragraph[];
271
409
  blocks: readonly Paragraph[];
272
410
  };
273
- /** A schema-version-1 document operation. */
274
- type DocumentOp = InsertTextOp | InsertContentOp | DeleteRangeOp | SplitInlineOp | JoinInlineOp | SetRunPropsOp | SetParagraphPropsOp | SplitBlockOp | JoinBlocksOp | ReplaceBlocksOp;
411
+ /**
412
+ * A paragraph's review fields: its paragraph properties, their tracked change
413
+ * and its mark's tracked change. An absent field is absent on the paragraph.
414
+ */
415
+ type ParagraphReviewFields = {
416
+ formatting?: ParagraphFormatting;
417
+ propertyChanges?: ParagraphPropertyChange[];
418
+ pPrMark?: ParagraphMarkChange;
419
+ };
420
+ /**
421
+ * Set a paragraph's review fields exactly. `expected` is what they are now,
422
+ * and `review` what they become; the inverse swaps the two. A new mark on a
423
+ * paragraph that ends its container (the story body or a table cell) is
424
+ * refused: there is no next paragraph to join it with.
425
+ */
426
+ type SetParagraphReviewOp = {
427
+ type: typeof DOCUMENT_OP_TYPES.SET_PARAGRAPH_REVIEW;
428
+ story: OpStory;
429
+ blockId: string;
430
+ expected: ParagraphReviewFields;
431
+ review: ParagraphReviewFields;
432
+ };
433
+ /**
434
+ * Replace a paragraph's whole content. `expected` is the content as it
435
+ * stands, compared structurally; the inverse swaps it with `content`. Ids the
436
+ * new content carries must be unused elsewhere in the package.
437
+ */
438
+ type ReplaceInlineOp = {
439
+ type: typeof DOCUMENT_OP_TYPES.REPLACE_INLINE;
440
+ story: OpStory;
441
+ blockId: string;
442
+ expected: readonly ParagraphContent[];
443
+ content: readonly ParagraphContent[];
444
+ };
445
+ /** What resolving a tracked change does with it. */
446
+ declare const REVISION_DECISIONS: Readonly<{
447
+ readonly ACCEPT: "accept";
448
+ readonly REJECT: "reject";
449
+ }>;
450
+ /** One of {@link REVISION_DECISIONS}. */
451
+ type RevisionDecision = (typeof REVISION_DECISIONS)[keyof typeof REVISION_DECISIONS];
452
+ /**
453
+ * Accept or reject tracked changes by revision id: insertions, deletions and
454
+ * moves, run and paragraph property changes, paragraph marks, and row insertions
455
+ * and deletions.
456
+ *
457
+ * - Accepting an insertion or rejecting a deletion keeps the content and
458
+ * drops the wrapper; the other two remove the content, changes nested in it
459
+ * included. A tracked change left with nothing in it goes.
460
+ * - Accepting a property change drops the record; rejecting one restores the
461
+ * formatting it recorded.
462
+ * - Accepting an inserted mark or rejecting a deleted one keeps the break and
463
+ * drops the record. The other two remove the mark, and the paragraph's
464
+ * properties go with it: the next paragraph is left, with its id,
465
+ * properties, mark and pending property changes, and the first's content
466
+ * before its own. The result does not depend on the order marks are
467
+ * resolved in. A mark with no next paragraph to join (a
468
+ * table follows, or the paragraph ends its container) loses its record,
469
+ * unless the paragraph holds no content and goes with it: removing a
470
+ * paragraph is a block operation, so that is refused (`untrackable`), as is
471
+ * a join at a section break.
472
+ * - Row insertions and deletions are resolved after inline changes and before
473
+ * paragraph marks. Keeping a row clears its structural revision; removing
474
+ * it also removes its nested revisions. Removing every row requires a
475
+ * whole-table operation and is refused as `untrackable`.
476
+ * - Records the resolution leaves meeting are merged as far as they are
477
+ * alike: the pieces a change cut apart are one record again.
478
+ *
479
+ * It is applied as the primitive operations it expands to, atomically, and
480
+ * its inverse is theirs. Ids no record carries are skipped, so resolving the
481
+ * same ids again changes nothing.
482
+ */
483
+ type ResolveRevisionOp = {
484
+ type: typeof DOCUMENT_OP_TYPES.RESOLVE_REVISION;
485
+ story: OpStory;
486
+ revisionIds: readonly number[];
487
+ decision: RevisionDecision;
488
+ };
489
+ /**
490
+ * Insert a row at a zero-based index in the table holding `blockId`.
491
+ * The paragraph reference selects the innermost table containing it.
492
+ * With `revision`, the row and its cell content record an insertion; no
493
+ * paragraph mark changes. `newIds` names the additional wrapper ids.
494
+ */
495
+ type InsertRowOp = {
496
+ type: typeof DOCUMENT_OP_TYPES.INSERT_ROW;
497
+ story: OpStory;
498
+ blockId: string;
499
+ at: number;
500
+ row: TableRow;
501
+ revision?: RevisionStamp;
502
+ newIds?: NewIds;
503
+ };
504
+ /**
505
+ * Remove the row holding `blockId`, or record a row and cell-content deletion
506
+ * with `revision`. The innermost containing row is selected. `expected`, when
507
+ * present, refuses a stale row. Removing the last row requires a table
508
+ * operation and is refused; tracked deletion keeps a row not pending deletion.
509
+ */
510
+ type DeleteRowOp = {
511
+ type: typeof DOCUMENT_OP_TYPES.DELETE_ROW;
512
+ story: OpStory;
513
+ blockId: string;
514
+ expected?: TableRow;
515
+ revision?: RevisionStamp;
516
+ newIds?: NewIds;
517
+ };
518
+ /**
519
+ * Replace a table's rows exactly, with a structural staleness precondition.
520
+ * This is the inverse and resolution primitive for row operations. The table
521
+ * holding `blockId` must retain at least one row; whole-table removal is a
522
+ * separate operation.
523
+ */
524
+ type SetTableRowsOp = {
525
+ type: typeof DOCUMENT_OP_TYPES.SET_TABLE_ROWS;
526
+ story: OpStory;
527
+ blockId: string;
528
+ expected: readonly TableRow[];
529
+ rows: readonly TableRow[];
530
+ };
531
+ /** A schema-version-3 document operation. */
532
+ type DocumentOp = InsertBlocksOp | InsertTextOp | InsertContentOp | DeleteRangeOp | SplitInlineOp | JoinInlineOp | SetRunPropsOp | SetParagraphPropsOp | SplitBlockOp | JoinBlocksOp | ReplaceBlocksOp | SetParagraphReviewOp | ReplaceInlineOp | ResolveRevisionOp | InsertRowOp | DeleteRowOp | SetTableRowsOp;
275
533
  /**
276
534
  * An operation as it is journaled and sent: the schema that reads it, and the
277
535
  * operation. A reader refuses an envelope of a schema it does not know rather
@@ -331,7 +589,7 @@ declare const DOCUMENT_OP_REFUSAL_REASONS: Readonly<{
331
589
  * two and names too few `newIds` for the halves after the first.
332
590
  */
333
591
  readonly NEEDS_NEW_IDS: "needsNewIds";
334
- /** A new revision or content-control id is not an integer from 0 to 2^31 - 1. */
592
+ /** A new revision or content-control id (a stamp's too) is not an integer from 0 to 2^31 - 1. */
335
593
  readonly INVALID_NEW_ID: "invalidNewId";
336
594
  /**
337
595
  * The operation would merge two records carrying the same revision or
@@ -354,6 +612,20 @@ declare const DOCUMENT_OP_REFUSAL_REASONS: Readonly<{
354
612
  readonly EMPTY_CONTENT: "emptyContent";
355
613
  /** A replacement names no paragraph to replace, or none to put in its place. */
356
614
  readonly EMPTY_BLOCK_LIST: "emptyBlockList";
615
+ /**
616
+ * The operation would record a tracked change over one the target already
617
+ * carries (a paragraph mark, a split that would drop a paragraph's property
618
+ * change), or would give a tracked split a mark of its own.
619
+ */
620
+ readonly REVISION_CONFLICT: "revisionConflict";
621
+ /** The operation would put a mark on a paragraph that ends its story body or table cell. */
622
+ readonly CONTAINER_FINAL_MARK: "containerFinalMark";
623
+ /**
624
+ * No tracked change can record the edit, or no resolution op can carry it
625
+ * out yet: comment boundaries in a tracked range, the paragraph mark's run
626
+ * properties, a join at a section break, a record inside a field.
627
+ */
628
+ readonly UNTRACKABLE: "untrackable";
357
629
  /** Seed contract: a main-story paragraph has no `paraId`. */
358
630
  readonly MISSING_BLOCK_ID: "missingBlockId";
359
631
  /** Seed contract: two paragraphs in the package carry one id. */
@@ -382,12 +654,20 @@ type AppliedDocumentOp = {
382
654
  /** Apply in order to restore the input document. */
383
655
  inverse: readonly DocumentOp[];
384
656
  touched: TouchedBlocks;
657
+ /**
658
+ * The revision ids of the tracked changes the operation recorded, in
659
+ * document order: its stamp's id and the new ids its other records took.
660
+ * Empty for a direct operation, and for a tracked one that merged into a
661
+ * change carrying the same stamp.
662
+ */
663
+ revisions: readonly number[];
385
664
  };
386
665
  /** Apply one operation to a document that meets the seed contract. */
387
666
  declare const applyDocumentOp: (document: Document, op: DocumentOp) => Result<AppliedDocumentOp, DocumentOpRefusal>;
388
667
  /**
389
668
  * Apply operations in order, atomically: the first refusal is returned and
390
- * the document is unchanged. The inverse undoes the whole list.
669
+ * the document is unchanged. The inverse undoes the whole list, and
670
+ * `revisions` lists each operation's in turn.
391
671
  */
392
672
  declare const applyDocumentOps: (document: Document, ops: readonly DocumentOp[]) => Result<AppliedDocumentOp, DocumentOpRefusal>;
393
673
  //#endregion
@@ -418,4 +698,35 @@ declare const OBJECT_REPLACEMENT_CHARACTER = "";
418
698
  */
419
699
  declare const paragraphLogicalText: (paragraph: Paragraph) => string;
420
700
  //#endregion
421
- export { type AppliedDocumentOp, DOCUMENT_OP_REFUSAL_REASONS, DOCUMENT_OP_SCHEMA_VERSION, DOCUMENT_OP_TYPES, type DeleteRangeOp, type DocumentOp, type DocumentOpEnvelope, DocumentOpRefusal, type DocumentOpRefusalReason, type DocumentOpType, DocumentOpsContractError, EMPTY_PROPERTY_SETS, type EmptyPropertySet, type FormattingPatch, INHERIT_RUN_PROPS, type InlineSlice, type InsertContentOp, type InsertTextOp, type InsertedRunProps, type JoinBlocksOp, type JoinInlineOp, type NewIds, OBJECT_REPLACEMENT_CHARACTER, OP_STORIES, type OpStory, type ParagraphPropsPatch, type ReplaceBlocksOp, type RunPropsPatch, type SetParagraphPropsOp, type SetRunPropsOp, type SplitBlockOp, type SplitInlineOp, type SplitParagraphFields, type TextPosition, type TouchedBlocks, applyDocumentOp, applyDocumentOps, normalizeForOps, paragraphLength, paragraphLogicalText, toOpEnvelope, validateOpsDocument };
701
+ //#region src/ops/plan.d.ts
702
+ /**
703
+ * How many `newIds.revision` entries an operation takes on a document,
704
+ * besides its stamp's id: the length of the shortest list of unused ids it
705
+ * applies with. Content-control ids are supplied freely while counting. The
706
+ * refusal is the one the operation meets whatever ids it is given.
707
+ */
708
+ declare const revisionIdDemand: (document: Document, op: DocumentOp) => Result<number, DocumentOpRefusal>;
709
+ /** The range a tracked deletion covers, its stamp, and the ids its later pieces take. */
710
+ type PlanTrackedDeletionOptions = {
711
+ from: TextPosition;
712
+ to: TextPosition;
713
+ revision: RevisionStamp;
714
+ /** Ids for the stamps of the tracked deletions after the first, and for the records they cut. */
715
+ newIds?: NewIds;
716
+ };
717
+ /**
718
+ * The operations a tracked deletion of a range is made of, to apply in
719
+ * order as one batch: a direct `deleteRange` for each stretch of the author's
720
+ * own insertions (retracting a suggestion removes it), and a tracked one for
721
+ * each other stretch, split around comment boundaries and references, which
722
+ * no tracked change can hold and which therefore stay. Stretches go from the
723
+ * last to the first, so each position still names what it named in the
724
+ * input. The positions default their `zeroWidthBefore` as `deleteRange` does.
725
+ *
726
+ * The first tracked deletion carries the stamp's id. Each later one takes the
727
+ * next id of `newIds.revision` the package does not use for its stamp, then
728
+ * the ones it needs for the records it cuts.
729
+ */
730
+ declare const planTrackedDeletion: (document: Document, options: PlanTrackedDeletionOptions) => Result<DocumentOp[], DocumentOpRefusal>;
731
+ //#endregion
732
+ export { type AppliedDocumentOp, type BlockInsertionPoint, DOCUMENT_OP_REFUSAL_REASONS, DOCUMENT_OP_SCHEMA_VERSION, DOCUMENT_OP_TYPES, type DeleteRangeOp, type DeleteRowOp, type DocumentOp, type DocumentOpEnvelope, DocumentOpRefusal, type DocumentOpRefusalReason, type DocumentOpType, DocumentOpsContractError, EMPTY_PROPERTY_SETS, type EmptyPropertySet, type FormattingPatch, INHERIT_RUN_PROPS, type InlineSlice, type InsertBlocksOp, type InsertContentOp, type InsertRowOp, type InsertTextOp, type InsertedRunProps, type JoinBlocksOp, type JoinInlineOp, type NewIds, OBJECT_REPLACEMENT_CHARACTER, OP_STORIES, type OpStory, PARAGRAPH_MARK_FORMATTING_KEYS, type ParagraphPropsPatch, type ParagraphReviewFields, type PlanTrackedDeletionOptions, REVISION_DECISIONS, type ReplaceBlocksOp, type ReplaceInlineOp, type ResolveRevisionOp, type RevisionDecision, type RevisionStamp, type RunPropsPatch, SPLIT_HALVES, type SetParagraphPropsOp, type SetParagraphReviewOp, type SetRunPropsOp, type SetTableRowsOp, type SplitBlockOp, type SplitHalf, type SplitInlineOp, type SplitParagraphFields, type TextPosition, type TouchedBlocks, applyDocumentOp, applyDocumentOps, normalizeForOps, paragraphLength, paragraphLogicalText, planTrackedDeletion, revisionIdDemand, toOpEnvelope, validateOpsDocument };