@stll/docx-core 0.28.1 → 0.30.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/README.md +6 -1
- package/dist/docx_kernel_bg.wasm +0 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +127 -6
- package/dist/ops/documentOps.d.ts +426 -28
- package/dist/ops/documentOps.js +3653 -697
- package/package.json +2 -2
|
@@ -1,11 +1,22 @@
|
|
|
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 { A as BlockContent, An as Table, 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
|
-
/**
|
|
5
|
-
|
|
4
|
+
/**
|
|
5
|
+
* The operation schema this module reads and writes.
|
|
6
|
+
*
|
|
7
|
+
* Version 4 adds paragraph deletion through `deleteBlocks`, direct and tracked
|
|
8
|
+
* whole-table operations with their exact structural inverse, terminal insertion,
|
|
9
|
+
* and cell-ending paragraph marks on tracked row operations.
|
|
10
|
+
* Version 3 added paragraph insertion through `insertBlocks` and the table-row
|
|
11
|
+
* operations `insertRow`, `deleteRow` and `setTableRows`.
|
|
12
|
+
* Version 2 added tracked changes: the `revision` stamp on the text, formatting
|
|
13
|
+
* and paragraph operations, and the review operations `setParagraphReview`,
|
|
14
|
+
* `replaceInline` and `resolveRevision`.
|
|
15
|
+
*/
|
|
16
|
+
declare const DOCUMENT_OP_SCHEMA_VERSION = 4;
|
|
6
17
|
/**
|
|
7
18
|
* The stories an operation can address. Headers, footers, notes and comment
|
|
8
|
-
* bodies are stories too; version
|
|
19
|
+
* bodies are stories too; this version addresses the main story only.
|
|
9
20
|
*/
|
|
10
21
|
declare const OP_STORIES: Readonly<{
|
|
11
22
|
readonly MAIN: "main";
|
|
@@ -84,10 +95,30 @@ type NewIds = {
|
|
|
84
95
|
/** For content controls (`w:sdtPr/w:id`). */
|
|
85
96
|
control?: readonly number[];
|
|
86
97
|
};
|
|
98
|
+
/**
|
|
99
|
+
* Who made a tracked change and when, and the revision id (`w:id`) of the
|
|
100
|
+
* first record the change creates.
|
|
101
|
+
*
|
|
102
|
+
* An operation carrying a stamp records its edit as a tracked change instead
|
|
103
|
+
* of making it: the stamp's id names the first record the edit creates and
|
|
104
|
+
* `newIds.revision` names the others, in document order. The id must be unused
|
|
105
|
+
* in the package. A new tracked wrapper that would sit next to one with the
|
|
106
|
+
* same author, date and initials merges into it and creates no record, so an
|
|
107
|
+
* author's burst of typing reads as one change.
|
|
108
|
+
*/
|
|
109
|
+
type RevisionStamp = {
|
|
110
|
+
id: number;
|
|
111
|
+
author: string;
|
|
112
|
+
/** `w:date`, as the author's client stated it. */
|
|
113
|
+
date: string;
|
|
114
|
+
initials?: string;
|
|
115
|
+
};
|
|
87
116
|
/** The paragraph fields a split gives the new paragraph, besides its id, content and mark. */
|
|
88
117
|
type SplitParagraphFields = Omit<Paragraph, "type" | "paraId" | "content" | "sectionProperties" | "pPrMark">;
|
|
89
|
-
/** The operation kinds of schema version
|
|
118
|
+
/** The operation kinds of schema version 4. */
|
|
90
119
|
declare const DOCUMENT_OP_TYPES: Readonly<{
|
|
120
|
+
readonly DELETE_BLOCKS: "deleteBlocks";
|
|
121
|
+
readonly INSERT_BLOCKS: "insertBlocks";
|
|
91
122
|
readonly INSERT_TEXT: "insertText";
|
|
92
123
|
readonly INSERT_CONTENT: "insertContent";
|
|
93
124
|
readonly DELETE_RANGE: "deleteRange";
|
|
@@ -98,6 +129,15 @@ declare const DOCUMENT_OP_TYPES: Readonly<{
|
|
|
98
129
|
readonly SPLIT_BLOCK: "splitBlock";
|
|
99
130
|
readonly JOIN_BLOCKS: "joinBlocks";
|
|
100
131
|
readonly REPLACE_BLOCKS: "replaceBlocks";
|
|
132
|
+
readonly SET_PARAGRAPH_REVIEW: "setParagraphReview";
|
|
133
|
+
readonly REPLACE_INLINE: "replaceInline";
|
|
134
|
+
readonly RESOLVE_REVISION: "resolveRevision";
|
|
135
|
+
readonly INSERT_TABLE: "insertTable";
|
|
136
|
+
readonly DELETE_TABLE: "deleteTable";
|
|
137
|
+
readonly SET_CONTAINER_BLOCKS: "setContainerBlocks";
|
|
138
|
+
readonly INSERT_ROW: "insertRow";
|
|
139
|
+
readonly DELETE_ROW: "deleteRow";
|
|
140
|
+
readonly SET_TABLE_ROWS: "setTableRows";
|
|
101
141
|
}>;
|
|
102
142
|
/** One of {@link DOCUMENT_OP_TYPES}. */
|
|
103
143
|
type DocumentOpType = (typeof DOCUMENT_OP_TYPES)[keyof typeof DOCUMENT_OP_TYPES];
|
|
@@ -109,6 +149,11 @@ type DocumentOpType = (typeof DOCUMENT_OP_TYPES)[keyof typeof DOCUMENT_OP_TYPES]
|
|
|
109
149
|
* becomes a run of its own and that run is split around it; `newIds` names
|
|
110
150
|
* the ids of the second half when the run carries some. The run decides where
|
|
111
151
|
* the text goes, so `at.zeroWidthBefore` is not read.
|
|
152
|
+
*
|
|
153
|
+
* With `revision`, the text is a tracked insertion: it is wrapped in an
|
|
154
|
+
* `Insertion` carrying the stamp, cutting the records around it down to a
|
|
155
|
+
* level that admits one. Text landing inside another stamp's insertion or
|
|
156
|
+
* move splits that record around it rather than nesting inside it.
|
|
112
157
|
*/
|
|
113
158
|
type InsertTextOp = {
|
|
114
159
|
type: typeof DOCUMENT_OP_TYPES.INSERT_TEXT;
|
|
@@ -117,6 +162,7 @@ type InsertTextOp = {
|
|
|
117
162
|
text: string;
|
|
118
163
|
runProps: InsertedRunProps;
|
|
119
164
|
newIds?: NewIds;
|
|
165
|
+
revision?: RevisionStamp;
|
|
120
166
|
};
|
|
121
167
|
/**
|
|
122
168
|
* Insert paragraph content at a position: runs, fields, markers, anything a
|
|
@@ -127,12 +173,18 @@ type InsertTextOp = {
|
|
|
127
173
|
* slice that would merge two records that were separate is refused.
|
|
128
174
|
* Absent `zeroWidthBefore` puts the point before the first zero-width child
|
|
129
175
|
* at the offset that opens a range, after the others.
|
|
176
|
+
*
|
|
177
|
+
* With `revision`, the inserted content is a tracked insertion, as for
|
|
178
|
+
* {@link InsertTextOp}. It is refused inside tracked-removed content, and
|
|
179
|
+
* when it holds a comment boundary or reference, which no tracked change can
|
|
180
|
+
* hold.
|
|
130
181
|
*/
|
|
131
182
|
type InsertContentOp = {
|
|
132
183
|
type: typeof DOCUMENT_OP_TYPES.INSERT_CONTENT;
|
|
133
184
|
at: TextPosition;
|
|
134
185
|
slice: InlineSlice;
|
|
135
186
|
newIds?: NewIds;
|
|
187
|
+
revision?: RevisionStamp;
|
|
136
188
|
};
|
|
137
189
|
/**
|
|
138
190
|
* Remove what lies between two positions of one paragraph: its units and the
|
|
@@ -147,6 +199,15 @@ type InsertContentOp = {
|
|
|
147
199
|
* `expected` is the slice the deletion must remove, compared without the
|
|
148
200
|
* fields a relayout recomputes. It is how an inverse refuses to apply to
|
|
149
201
|
* content that has changed since.
|
|
202
|
+
*
|
|
203
|
+
* With `revision`, the deletion is tracked and removes nothing. Content
|
|
204
|
+
* already inside a deletion or moved away is left as it is; content inside an
|
|
205
|
+
* insertion or a move gets a deletion nested inside that record; everything
|
|
206
|
+
* else is wrapped in a `Deletion` carrying the stamp, an inline content
|
|
207
|
+
* control the range covers whole going in with its content. A range holding
|
|
208
|
+
* a comment boundary or reference is refused, since no tracked change can
|
|
209
|
+
* hold one; `planTrackedDeletion` plans the deletions around them. A tracked
|
|
210
|
+
* deletion joins nothing, so `join` must be absent.
|
|
150
211
|
*/
|
|
151
212
|
type DeleteRangeOp = {
|
|
152
213
|
type: typeof DOCUMENT_OP_TYPES.DELETE_RANGE;
|
|
@@ -154,6 +215,8 @@ type DeleteRangeOp = {
|
|
|
154
215
|
to: TextPosition;
|
|
155
216
|
join?: number;
|
|
156
217
|
expected?: InlineSlice;
|
|
218
|
+
newIds?: NewIds;
|
|
219
|
+
revision?: RevisionStamp;
|
|
157
220
|
};
|
|
158
221
|
/**
|
|
159
222
|
* Cut the innermost `depth` records that run across a position in two,
|
|
@@ -187,6 +250,12 @@ type JoinInlineOp = {
|
|
|
187
250
|
* `joinStart` and `joinEnd` merge the runs meeting at the range ends that many
|
|
188
251
|
* levels once the patch is applied, as {@link JoinInlineOp} does; the inverse
|
|
189
252
|
* of a patch that cut runs uses them.
|
|
253
|
+
*
|
|
254
|
+
* With `revision`, every run the patch changes records a tracked property
|
|
255
|
+
* change (`w:rPrChange`) whose previous formatting is the run's own property
|
|
256
|
+
* set before the patch. A run already carrying one keeps it, and with it the
|
|
257
|
+
* formatting it started from. A tracked patch joins nothing, so `joinStart`
|
|
258
|
+
* and `joinEnd` must be absent.
|
|
190
259
|
*/
|
|
191
260
|
type SetRunPropsOp = {
|
|
192
261
|
type: typeof DOCUMENT_OP_TYPES.SET_RUN_PROPS;
|
|
@@ -198,11 +267,18 @@ type SetRunPropsOp = {
|
|
|
198
267
|
joinStart?: number;
|
|
199
268
|
joinEnd?: number;
|
|
200
269
|
newIds?: NewIds;
|
|
270
|
+
revision?: RevisionStamp;
|
|
201
271
|
};
|
|
202
272
|
/**
|
|
203
273
|
* Patch a paragraph's own property set. `expected` states the values the
|
|
204
274
|
* patched keys must have (`null` for absent) and refuses the patch as stale
|
|
205
275
|
* otherwise.
|
|
276
|
+
*
|
|
277
|
+
* With `revision`, the paragraph records a tracked property change
|
|
278
|
+
* (`w:pPrChange`) whose previous formatting is its own property set before
|
|
279
|
+
* the patch, or keeps the one it already carries. A property change holds
|
|
280
|
+
* paragraph properties only, not the paragraph mark's run properties, so a
|
|
281
|
+
* tracked patch of {@link PARAGRAPH_MARK_FORMATTING_KEYS} is refused.
|
|
206
282
|
*/
|
|
207
283
|
type SetParagraphPropsOp = {
|
|
208
284
|
type: typeof DOCUMENT_OP_TYPES.SET_PARAGRAPH_PROPS;
|
|
@@ -211,42 +287,83 @@ type SetParagraphPropsOp = {
|
|
|
211
287
|
patch: ParagraphPropsPatch;
|
|
212
288
|
whenEmpty?: EmptyPropertySet;
|
|
213
289
|
expected?: ParagraphPropsPatch;
|
|
290
|
+
revision?: RevisionStamp;
|
|
214
291
|
};
|
|
292
|
+
/**
|
|
293
|
+
* Paragraph formatting that belongs to the paragraph mark's run properties
|
|
294
|
+
* (`w:pPr/w:rPr`) rather than to the paragraph properties a `w:pPrChange`
|
|
295
|
+
* records.
|
|
296
|
+
*/
|
|
297
|
+
declare const PARAGRAPH_MARK_FORMATTING_KEYS: readonly ["runProperties", "runInWithNext"];
|
|
298
|
+
/** Which half of a split, or of a join, a rule applies to. */
|
|
299
|
+
declare const SPLIT_HALVES: Readonly<{
|
|
300
|
+
readonly FIRST: "first";
|
|
301
|
+
readonly SECOND: "second";
|
|
302
|
+
}>;
|
|
303
|
+
/** One of {@link SPLIT_HALVES}. */
|
|
304
|
+
type SplitHalf = (typeof SPLIT_HALVES)[keyof typeof SPLIT_HALVES];
|
|
215
305
|
/**
|
|
216
306
|
* Split a paragraph in two at a position.
|
|
217
307
|
*
|
|
218
|
-
*
|
|
219
|
-
*
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
*
|
|
225
|
-
*
|
|
308
|
+
* One half keeps the paragraph's identity and own fields (`paraId`, `textId`,
|
|
309
|
+
* unmodelled attributes, properties); the other is a new paragraph named
|
|
310
|
+
* `newBlockId`, taking the fields in `newParagraph`, or a copy of the
|
|
311
|
+
* paragraph's properties when the operation states none. `newHalf` says which
|
|
312
|
+
* half is new: by default the second when the position ends the paragraph
|
|
313
|
+
* (a paragraph added after it), else the first (the text before the position
|
|
314
|
+
* moves to a paragraph of its own, and the paragraph continues with the rest).
|
|
315
|
+
* The paragraph mark always ends the second half, so the section break, the
|
|
316
|
+
* mark's tracked change and the pending property changes go with it; when the
|
|
317
|
+
* second half is the new one, `newParagraph` states no property changes.
|
|
318
|
+
* `firstMark` is the tracked change of the mark the split creates, which ends
|
|
319
|
+
* the first half. Absent `zeroWidthBefore` keeps zero-width children that
|
|
320
|
+
* open a range with the second half.
|
|
226
321
|
*
|
|
227
322
|
* A split inside a tracked change, a content control or a run with a tracked
|
|
228
|
-
* property change continues it in the
|
|
323
|
+
* property change continues it in the second half as a record of its own:
|
|
229
324
|
* `newIds` names its ids, outermost record first.
|
|
325
|
+
*
|
|
326
|
+
* With `revision`, the mark the split creates is a tracked insertion
|
|
327
|
+
* (`firstMark` must then be absent), and the new paragraph, when its paragraph
|
|
328
|
+
* properties differ from the source's and it carries no property change,
|
|
329
|
+
* records one from the source's. Rejecting the mark removes it, which leaves
|
|
330
|
+
* the second half with the first's content before its own. A property change
|
|
331
|
+
* does not record the mark's run properties, so a new second half, which ends
|
|
332
|
+
* with the paragraph's own mark, must state the same ones as the paragraph.
|
|
230
333
|
*/
|
|
231
334
|
type SplitBlockOp = {
|
|
232
335
|
type: typeof DOCUMENT_OP_TYPES.SPLIT_BLOCK;
|
|
233
336
|
at: TextPosition;
|
|
234
337
|
/** `w14:paraId` of the new paragraph: eight hex digits, unused in the document. */
|
|
235
338
|
newBlockId: string;
|
|
339
|
+
newHalf?: SplitHalf;
|
|
236
340
|
newParagraph?: SplitParagraphFields;
|
|
237
341
|
firstMark?: ParagraphMarkChange;
|
|
238
342
|
newIds?: NewIds;
|
|
343
|
+
revision?: RevisionStamp;
|
|
239
344
|
};
|
|
240
345
|
/**
|
|
241
346
|
* Join a paragraph with the paragraph that directly follows it in the same
|
|
242
|
-
* container. The
|
|
243
|
-
*
|
|
244
|
-
*
|
|
245
|
-
*
|
|
347
|
+
* container. The joined paragraph has the first's paragraph properties, or
|
|
348
|
+
* the second's when the first holds no content, and the second's mark: its
|
|
349
|
+
* run properties, section break, tracked change and the pending property
|
|
350
|
+
* changes. It keeps the identity and own fields of the
|
|
351
|
+
* `survivor` half, by default the second, and the other's id is retired.
|
|
352
|
+
* `depth` merges that many levels of the records meeting at the join, as
|
|
353
|
+
* {@link JoinInlineOp} does.
|
|
354
|
+
*
|
|
355
|
+
* `expectedRetired` states the own fields of the paragraph the join retires,
|
|
356
|
+
* and `expectedSurvivor` the review fields of the one it keeps, which the
|
|
357
|
+
* join replaces; either refuses the join as stale when it differs (fields a
|
|
358
|
+
* relayout recomputes are not compared).
|
|
246
359
|
*
|
|
247
|
-
* `
|
|
248
|
-
*
|
|
249
|
-
*
|
|
360
|
+
* With `revision`, the join is tracked and moves nothing: the first
|
|
361
|
+
* paragraph's mark becomes a tracked deletion, refused when the mark already
|
|
362
|
+
* carries a tracked change, and the second takes the paragraph properties
|
|
363
|
+
* the direct join would give it as a tracked property change. Accepting removes the mark, which
|
|
364
|
+
* leaves the second paragraph with the first's content before its own: what
|
|
365
|
+
* the direct join leaves. A tracked join always leaves the second, so
|
|
366
|
+
* `survivor` must then be absent or `second`.
|
|
250
367
|
*/
|
|
251
368
|
type JoinBlocksOp = {
|
|
252
369
|
type: typeof DOCUMENT_OP_TYPES.JOIN_BLOCKS;
|
|
@@ -254,7 +371,57 @@ type JoinBlocksOp = {
|
|
|
254
371
|
blockId: string;
|
|
255
372
|
nextBlockId: string;
|
|
256
373
|
depth?: number;
|
|
257
|
-
|
|
374
|
+
survivor?: SplitHalf;
|
|
375
|
+
expectedRetired?: SplitParagraphFields;
|
|
376
|
+
expectedSurvivor?: ParagraphReviewFields;
|
|
377
|
+
newIds?: NewIds;
|
|
378
|
+
revision?: RevisionStamp;
|
|
379
|
+
};
|
|
380
|
+
/** A paragraph-relative insertion point in one block list. */
|
|
381
|
+
type BlockInsertionPoint = {
|
|
382
|
+
type: "before";
|
|
383
|
+
blockId: string;
|
|
384
|
+
} | {
|
|
385
|
+
type: "after";
|
|
386
|
+
blockId: string;
|
|
387
|
+
};
|
|
388
|
+
/**
|
|
389
|
+
* Insert paragraphs beside an existing paragraph, with pre-minted ids.
|
|
390
|
+
* Section-bearing paragraphs are refused. With `revision`, each inserted
|
|
391
|
+
* paragraph receives an inserted mark and its content an insertion wrapper.
|
|
392
|
+
* Tracked insertion requires a following paragraph in the same block list;
|
|
393
|
+
* terminal insertion and insertion immediately before non-paragraph blocks
|
|
394
|
+
* are refused as `untrackable`.
|
|
395
|
+
* Incoming revision and content-control identities are refused in tracked
|
|
396
|
+
* mode rather than nesting reviews or rewriting supplied identities.
|
|
397
|
+
*/
|
|
398
|
+
type InsertBlocksOp = {
|
|
399
|
+
type: typeof DOCUMENT_OP_TYPES.INSERT_BLOCKS;
|
|
400
|
+
story: OpStory;
|
|
401
|
+
at: BlockInsertionPoint;
|
|
402
|
+
blocks: readonly Paragraph[];
|
|
403
|
+
revision?: RevisionStamp;
|
|
404
|
+
newIds?: NewIds;
|
|
405
|
+
};
|
|
406
|
+
/**
|
|
407
|
+
* Delete adjacent paragraphs in one block list. A following paragraph keeps
|
|
408
|
+
* its identity and fields. At the end of a block list, the last selected
|
|
409
|
+
* paragraph survives: it takes the preceding paragraph's content and
|
|
410
|
+
* paragraph properties when present, keeping its own mark properties and id;
|
|
411
|
+
* without a preceding paragraph it becomes empty.
|
|
412
|
+
*
|
|
413
|
+
* With `revision`, selected content is wrapped in deletions and the removed
|
|
414
|
+
* breaks are marked. The container-final paragraph never receives a mark.
|
|
415
|
+
* Section boundaries, non-paragraph following blocks and conflicting
|
|
416
|
+
* paragraph reviews are refused rather than partially removed. Tracked deletion
|
|
417
|
+
* of content carrying revision or content-control ids is also unsupported.
|
|
418
|
+
*/
|
|
419
|
+
type DeleteBlocksOp = {
|
|
420
|
+
type: typeof DOCUMENT_OP_TYPES.DELETE_BLOCKS;
|
|
421
|
+
story: OpStory;
|
|
422
|
+
blockIds: readonly string[];
|
|
423
|
+
revision?: RevisionStamp;
|
|
424
|
+
newIds?: NewIds;
|
|
258
425
|
};
|
|
259
426
|
/**
|
|
260
427
|
* Replace a run of adjacent paragraphs with other paragraphs.
|
|
@@ -262,7 +429,7 @@ type JoinBlocksOp = {
|
|
|
262
429
|
* `expected` is the paragraphs as they stand: they are found by `paraId` and
|
|
263
430
|
* compared structurally (without the fields a relayout recomputes), so a
|
|
264
431
|
* replacement authored against another state is refused rather than applied
|
|
265
|
-
* over it.
|
|
432
|
+
* over it. Paragraph insertion uses an anchored replacement as its inverse.
|
|
266
433
|
*/
|
|
267
434
|
type ReplaceBlocksOp = {
|
|
268
435
|
type: typeof DOCUMENT_OP_TYPES.REPLACE_BLOCKS;
|
|
@@ -270,8 +437,171 @@ type ReplaceBlocksOp = {
|
|
|
270
437
|
expected: readonly Paragraph[];
|
|
271
438
|
blocks: readonly Paragraph[];
|
|
272
439
|
};
|
|
273
|
-
/**
|
|
274
|
-
|
|
440
|
+
/**
|
|
441
|
+
* A paragraph's review fields: its paragraph properties, their tracked change
|
|
442
|
+
* and its mark's tracked change. An absent field is absent on the paragraph.
|
|
443
|
+
*/
|
|
444
|
+
type ParagraphReviewFields = {
|
|
445
|
+
formatting?: ParagraphFormatting;
|
|
446
|
+
propertyChanges?: ParagraphPropertyChange[];
|
|
447
|
+
pPrMark?: ParagraphMarkChange;
|
|
448
|
+
};
|
|
449
|
+
/**
|
|
450
|
+
* Set a paragraph's review fields exactly. `expected` is what they are now,
|
|
451
|
+
* and `review` what they become; the inverse swaps the two. A new mark on a
|
|
452
|
+
* paragraph that ends its container (the story body or a table cell) is
|
|
453
|
+
* refused: there is no next paragraph to join it with.
|
|
454
|
+
*/
|
|
455
|
+
type SetParagraphReviewOp = {
|
|
456
|
+
type: typeof DOCUMENT_OP_TYPES.SET_PARAGRAPH_REVIEW;
|
|
457
|
+
story: OpStory;
|
|
458
|
+
blockId: string;
|
|
459
|
+
expected: ParagraphReviewFields;
|
|
460
|
+
review: ParagraphReviewFields;
|
|
461
|
+
};
|
|
462
|
+
/**
|
|
463
|
+
* Replace a paragraph's whole content. `expected` is the content as it
|
|
464
|
+
* stands, compared structurally; the inverse swaps it with `content`. Ids the
|
|
465
|
+
* new content carries must be unused elsewhere in the package.
|
|
466
|
+
*/
|
|
467
|
+
type ReplaceInlineOp = {
|
|
468
|
+
type: typeof DOCUMENT_OP_TYPES.REPLACE_INLINE;
|
|
469
|
+
story: OpStory;
|
|
470
|
+
blockId: string;
|
|
471
|
+
expected: readonly ParagraphContent[];
|
|
472
|
+
content: readonly ParagraphContent[];
|
|
473
|
+
};
|
|
474
|
+
/** What resolving a tracked change does with it. */
|
|
475
|
+
declare const REVISION_DECISIONS: Readonly<{
|
|
476
|
+
readonly ACCEPT: "accept";
|
|
477
|
+
readonly REJECT: "reject";
|
|
478
|
+
}>;
|
|
479
|
+
/** One of {@link REVISION_DECISIONS}. */
|
|
480
|
+
type RevisionDecision = (typeof REVISION_DECISIONS)[keyof typeof REVISION_DECISIONS];
|
|
481
|
+
/**
|
|
482
|
+
* Accept or reject tracked changes by revision id: insertions, deletions and
|
|
483
|
+
* moves, run and paragraph property changes, paragraph marks, and row insertions
|
|
484
|
+
* and deletions.
|
|
485
|
+
*
|
|
486
|
+
* - Accepting an insertion or rejecting a deletion keeps the content and
|
|
487
|
+
* drops the wrapper; the other two remove the content, changes nested in it
|
|
488
|
+
* included. A tracked change left with nothing in it goes.
|
|
489
|
+
* - Accepting a property change drops the record; rejecting one restores the
|
|
490
|
+
* formatting it recorded.
|
|
491
|
+
* - Accepting an inserted mark or rejecting a deleted one keeps the break and
|
|
492
|
+
* drops the record. The other two remove the mark, and the paragraph's
|
|
493
|
+
* properties go with it: the next paragraph is left, with its id,
|
|
494
|
+
* properties, mark and pending property changes, and the first's content
|
|
495
|
+
* before its own. The result does not depend on the order marks are
|
|
496
|
+
* resolved in. A mark with no next paragraph to join (a
|
|
497
|
+
* table follows, or the paragraph ends its container) loses its record,
|
|
498
|
+
* unless the paragraph holds no content and goes with it: removing a
|
|
499
|
+
* paragraph is a block operation, so that is refused (`untrackable`), as is
|
|
500
|
+
* a join at a section break.
|
|
501
|
+
* - Row insertions and deletions are resolved after inline changes and before
|
|
502
|
+
* paragraph marks. Keeping a row clears its structural revision; removing
|
|
503
|
+
* it also removes its nested revisions. Removing every row removes the
|
|
504
|
+
* table, preserving the surrounding paragraphs.
|
|
505
|
+
* - Records the resolution leaves meeting are merged as far as they are
|
|
506
|
+
* alike: the pieces a change cut apart are one record again.
|
|
507
|
+
*
|
|
508
|
+
* It is applied as the primitive operations it expands to, atomically, and
|
|
509
|
+
* its inverse is theirs. Ids no record carries are skipped, so resolving the
|
|
510
|
+
* same ids again changes nothing.
|
|
511
|
+
*/
|
|
512
|
+
type ResolveRevisionOp = {
|
|
513
|
+
type: typeof DOCUMENT_OP_TYPES.RESOLVE_REVISION;
|
|
514
|
+
story: OpStory;
|
|
515
|
+
revisionIds: readonly number[];
|
|
516
|
+
decision: RevisionDecision;
|
|
517
|
+
};
|
|
518
|
+
/**
|
|
519
|
+
* Insert a row at a zero-based index in the table holding `blockId`.
|
|
520
|
+
* The paragraph reference selects the innermost table containing it.
|
|
521
|
+
* With `revision`, the row, its cell content and
|
|
522
|
+
* cell-ending paragraph marks record insertion. `newIds` supplies the
|
|
523
|
+
* additional physical revision ids.
|
|
524
|
+
*/
|
|
525
|
+
type InsertRowOp = {
|
|
526
|
+
type: typeof DOCUMENT_OP_TYPES.INSERT_ROW;
|
|
527
|
+
story: OpStory;
|
|
528
|
+
blockId: string;
|
|
529
|
+
at: number;
|
|
530
|
+
row: TableRow;
|
|
531
|
+
revision?: RevisionStamp;
|
|
532
|
+
newIds?: NewIds;
|
|
533
|
+
};
|
|
534
|
+
/**
|
|
535
|
+
* Remove the row holding `blockId`, or record a row and cell-content deletion
|
|
536
|
+
* with `revision`. The innermost containing row is selected. `expected`, when
|
|
537
|
+
* present, refuses a stale row. Direct removal of the last row removes its
|
|
538
|
+
* table; tracked deletion keeps a row not pending deletion.
|
|
539
|
+
*/
|
|
540
|
+
type DeleteRowOp = {
|
|
541
|
+
type: typeof DOCUMENT_OP_TYPES.DELETE_ROW;
|
|
542
|
+
story: OpStory;
|
|
543
|
+
blockId: string;
|
|
544
|
+
expected?: TableRow;
|
|
545
|
+
revision?: RevisionStamp;
|
|
546
|
+
newIds?: NewIds;
|
|
547
|
+
};
|
|
548
|
+
/**
|
|
549
|
+
* Replace a table's rows exactly, with a structural staleness precondition.
|
|
550
|
+
* This is the inverse and resolution primitive for row operations. An empty
|
|
551
|
+
* row list removes the table, with an exact structural inverse.
|
|
552
|
+
*/
|
|
553
|
+
type SetTableRowsOp = {
|
|
554
|
+
type: typeof DOCUMENT_OP_TYPES.SET_TABLE_ROWS;
|
|
555
|
+
story: OpStory;
|
|
556
|
+
blockId: string;
|
|
557
|
+
expected: readonly TableRow[];
|
|
558
|
+
rows: readonly TableRow[];
|
|
559
|
+
};
|
|
560
|
+
/**
|
|
561
|
+
* Insert a table before or after a paragraph. Tracking records each row,
|
|
562
|
+
* cell content and cell-ending paragraph mark. At a container's end,
|
|
563
|
+
* `terminal` moves the source content into a new preceding paragraph while
|
|
564
|
+
* retaining the source id and fields on the untracked final paragraph.
|
|
565
|
+
*/
|
|
566
|
+
type InsertTableOp = {
|
|
567
|
+
type: typeof DOCUMENT_OP_TYPES.INSERT_TABLE;
|
|
568
|
+
story: OpStory;
|
|
569
|
+
at: BlockInsertionPoint;
|
|
570
|
+
table: Table;
|
|
571
|
+
revision?: RevisionStamp;
|
|
572
|
+
newIds?: NewIds;
|
|
573
|
+
terminal?: {
|
|
574
|
+
beforeBlockId: string;
|
|
575
|
+
};
|
|
576
|
+
};
|
|
577
|
+
/**
|
|
578
|
+
* Remove the innermost table holding the addressed paragraph. Its block list
|
|
579
|
+
* must retain a paragraph for the inverse. Tracking records row, cell-content
|
|
580
|
+
* and cell-ending paragraph-mark deletions without removing content.
|
|
581
|
+
*/
|
|
582
|
+
type DeleteTableOp = {
|
|
583
|
+
type: typeof DOCUMENT_OP_TYPES.DELETE_TABLE;
|
|
584
|
+
story: OpStory;
|
|
585
|
+
blockId: string;
|
|
586
|
+
expected?: Table;
|
|
587
|
+
revision?: RevisionStamp;
|
|
588
|
+
newIds?: NewIds;
|
|
589
|
+
};
|
|
590
|
+
/**
|
|
591
|
+
* Exact structural inverse for table edits. The addressed paragraph must
|
|
592
|
+
* remain in the same block list; unrelated edits in that list make it stale.
|
|
593
|
+
* Section boundaries and story-final marks are preserved; cell-ending marks
|
|
594
|
+
* are exact model data, including after independent row resolution.
|
|
595
|
+
*/
|
|
596
|
+
type SetContainerBlocksOp = {
|
|
597
|
+
type: typeof DOCUMENT_OP_TYPES.SET_CONTAINER_BLOCKS;
|
|
598
|
+
story: OpStory;
|
|
599
|
+
blockId: string;
|
|
600
|
+
expected: readonly BlockContent[];
|
|
601
|
+
blocks: readonly BlockContent[];
|
|
602
|
+
};
|
|
603
|
+
/** A schema-version-4 document operation. */
|
|
604
|
+
type DocumentOp = DeleteBlocksOp | InsertTableOp | DeleteTableOp | SetContainerBlocksOp | InsertBlocksOp | InsertTextOp | InsertContentOp | DeleteRangeOp | SplitInlineOp | JoinInlineOp | SetRunPropsOp | SetParagraphPropsOp | SplitBlockOp | JoinBlocksOp | ReplaceBlocksOp | SetParagraphReviewOp | ReplaceInlineOp | ResolveRevisionOp | InsertRowOp | DeleteRowOp | SetTableRowsOp;
|
|
275
605
|
/**
|
|
276
606
|
* An operation as it is journaled and sent: the schema that reads it, and the
|
|
277
607
|
* operation. A reader refuses an envelope of a schema it does not know rather
|
|
@@ -331,7 +661,7 @@ declare const DOCUMENT_OP_REFUSAL_REASONS: Readonly<{
|
|
|
331
661
|
* two and names too few `newIds` for the halves after the first.
|
|
332
662
|
*/
|
|
333
663
|
readonly NEEDS_NEW_IDS: "needsNewIds";
|
|
334
|
-
/** A new revision or content-control id is not an integer from 0 to 2^31 - 1. */
|
|
664
|
+
/** A new revision or content-control id (a stamp's too) is not an integer from 0 to 2^31 - 1. */
|
|
335
665
|
readonly INVALID_NEW_ID: "invalidNewId";
|
|
336
666
|
/**
|
|
337
667
|
* The operation would merge two records carrying the same revision or
|
|
@@ -354,6 +684,20 @@ declare const DOCUMENT_OP_REFUSAL_REASONS: Readonly<{
|
|
|
354
684
|
readonly EMPTY_CONTENT: "emptyContent";
|
|
355
685
|
/** A replacement names no paragraph to replace, or none to put in its place. */
|
|
356
686
|
readonly EMPTY_BLOCK_LIST: "emptyBlockList";
|
|
687
|
+
/**
|
|
688
|
+
* The operation would record a tracked change over one the target already
|
|
689
|
+
* carries (a paragraph mark, a split that would drop a paragraph's property
|
|
690
|
+
* change), or would give a tracked split a mark of its own.
|
|
691
|
+
*/
|
|
692
|
+
readonly REVISION_CONFLICT: "revisionConflict";
|
|
693
|
+
/** The operation would put a mark on a paragraph that ends its story body or table cell. */
|
|
694
|
+
readonly CONTAINER_FINAL_MARK: "containerFinalMark";
|
|
695
|
+
/**
|
|
696
|
+
* No tracked change can record the edit, or no resolution op can carry it
|
|
697
|
+
* out yet: comment boundaries in a tracked range, the paragraph mark's run
|
|
698
|
+
* properties, a join at a section break, a record inside a field.
|
|
699
|
+
*/
|
|
700
|
+
readonly UNTRACKABLE: "untrackable";
|
|
357
701
|
/** Seed contract: a main-story paragraph has no `paraId`. */
|
|
358
702
|
readonly MISSING_BLOCK_ID: "missingBlockId";
|
|
359
703
|
/** Seed contract: two paragraphs in the package carry one id. */
|
|
@@ -382,12 +726,20 @@ type AppliedDocumentOp = {
|
|
|
382
726
|
/** Apply in order to restore the input document. */
|
|
383
727
|
inverse: readonly DocumentOp[];
|
|
384
728
|
touched: TouchedBlocks;
|
|
729
|
+
/**
|
|
730
|
+
* The revision ids of the tracked changes the operation recorded, in
|
|
731
|
+
* document order: its stamp's id and the new ids its other records took.
|
|
732
|
+
* Empty for a direct operation, and for a tracked one that merged into a
|
|
733
|
+
* change carrying the same stamp.
|
|
734
|
+
*/
|
|
735
|
+
revisions: readonly number[];
|
|
385
736
|
};
|
|
386
737
|
/** Apply one operation to a document that meets the seed contract. */
|
|
387
738
|
declare const applyDocumentOp: (document: Document, op: DocumentOp) => Result<AppliedDocumentOp, DocumentOpRefusal>;
|
|
388
739
|
/**
|
|
389
740
|
* Apply operations in order, atomically: the first refusal is returned and
|
|
390
|
-
* the document is unchanged. The inverse undoes the whole list
|
|
741
|
+
* the document is unchanged. The inverse undoes the whole list, and
|
|
742
|
+
* `revisions` lists each operation's in turn.
|
|
391
743
|
*/
|
|
392
744
|
declare const applyDocumentOps: (document: Document, ops: readonly DocumentOp[]) => Result<AppliedDocumentOp, DocumentOpRefusal>;
|
|
393
745
|
//#endregion
|
|
@@ -418,4 +770,50 @@ declare const OBJECT_REPLACEMENT_CHARACTER = "";
|
|
|
418
770
|
*/
|
|
419
771
|
declare const paragraphLogicalText: (paragraph: Paragraph) => string;
|
|
420
772
|
//#endregion
|
|
421
|
-
|
|
773
|
+
//#region src/ops/plan.d.ts
|
|
774
|
+
/**
|
|
775
|
+
* How many `newIds.revision` entries an operation takes on a document,
|
|
776
|
+
* besides its stamp's id: the length of the shortest list of unused ids it
|
|
777
|
+
* applies with. Content-control ids are supplied freely while counting. The
|
|
778
|
+
* refusal is the one the operation meets whatever ids it is given.
|
|
779
|
+
*/
|
|
780
|
+
declare const revisionIdDemand: (document: Document, op: DocumentOp) => Result<number, DocumentOpRefusal>;
|
|
781
|
+
/** The range a tracked deletion covers, its stamp, and the ids its later pieces take. */
|
|
782
|
+
type PlanTrackedDeletionOptions = {
|
|
783
|
+
from: TextPosition;
|
|
784
|
+
to: TextPosition;
|
|
785
|
+
revision: RevisionStamp;
|
|
786
|
+
/** Ids for the stamps of the tracked deletions after the first, and for the records they cut. */
|
|
787
|
+
newIds?: NewIds;
|
|
788
|
+
};
|
|
789
|
+
/**
|
|
790
|
+
* Plan a same-list range as inline deletions followed by tracked paragraph
|
|
791
|
+
* joins. Own insertions are retracted directly; comment anchors remain.
|
|
792
|
+
* Inline ranges run in reverse order, then joins run from last to first.
|
|
793
|
+
* All physical revision ids come from one pool for the complete batch.
|
|
794
|
+
*/
|
|
795
|
+
declare const planTrackedDeletion: (document: Document, options: PlanTrackedDeletionOptions) => Result<DocumentOp[], DocumentOpRefusal>;
|
|
796
|
+
//#endregion
|
|
797
|
+
//#region src/ops/rangeReplacement.d.ts
|
|
798
|
+
/**
|
|
799
|
+
* A range replacement fragment: newly identified paragraphs before its last
|
|
800
|
+
* paragraph, and the inline tail inserted into the retained original paragraph.
|
|
801
|
+
* Each new paragraph's own fields apply to it, including when it takes the
|
|
802
|
+
* source prefix. The last fragment keeps the original survivor's identity.
|
|
803
|
+
* Closed inline slices are required; review and content-control ids in the
|
|
804
|
+
* fragment, and section-bearing paragraphs, are unsupported.
|
|
805
|
+
*/
|
|
806
|
+
type PlanTrackedReplaceOptions = PlanTrackedDeletionOptions & {
|
|
807
|
+
replacement: {
|
|
808
|
+
paragraphs: readonly Paragraph[];
|
|
809
|
+
tail: InlineSlice;
|
|
810
|
+
};
|
|
811
|
+
};
|
|
812
|
+
/**
|
|
813
|
+
* Plan a tracked replacement of a same-list range: the range's tracked
|
|
814
|
+
* deletion followed by the replacement fragment as tracked insertions.
|
|
815
|
+
* All physical revision ids come from one pool for the complete batch.
|
|
816
|
+
*/
|
|
817
|
+
declare const planTrackedReplace: (document: Document, options: PlanTrackedReplaceOptions) => Result<DocumentOp[], DocumentOpRefusal>;
|
|
818
|
+
//#endregion
|
|
819
|
+
export { type AppliedDocumentOp, type BlockInsertionPoint, DOCUMENT_OP_REFUSAL_REASONS, DOCUMENT_OP_SCHEMA_VERSION, DOCUMENT_OP_TYPES, type DeleteBlocksOp, type DeleteRangeOp, type DeleteRowOp, type DeleteTableOp, 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 InsertTableOp, 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, type PlanTrackedReplaceOptions, REVISION_DECISIONS, type ReplaceBlocksOp, type ReplaceInlineOp, type ResolveRevisionOp, type RevisionDecision, type RevisionStamp, type RunPropsPatch, SPLIT_HALVES, type SetContainerBlocksOp, 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, planTrackedReplace, revisionIdDemand, toOpEnvelope, validateOpsDocument };
|