@stll/docx-core 0.30.1 → 0.32.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 +4 -0
- package/dist/{document-DdWrTPQY.js → document-3WKQA1r3.js} +20 -1
- package/dist/{document-DrtmJ_hz.d.ts → document-C73n0FqK.d.ts} +92 -15
- package/dist/docx_kernel_bg.wasm +0 -0
- package/dist/{xmlEscape-T-2DeGlS.js → href-2XSCK-T8.js} +49 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +404 -72
- package/dist/model/document.d.ts +2 -2
- package/dist/model/document.js +2 -2
- package/dist/ops/documentOps.d.ts +739 -26
- package/dist/ops/documentOps.js +10164 -2331
- package/dist/projection.d.ts +2 -2
- package/dist/schema/sequenceChildren.d.ts +2 -1
- package/dist/schema/sequenceChildren.js +2 -2
- package/dist/{sequenceChildren-BIixCB49.js → sequenceChildren-B8ODeI3J.js} +99 -1
- package/dist/zip/writeZipPart.d.ts +12 -0
- package/dist/zip/writeZipPart.js +12 -0
- package/package.json +6 -1
|
@@ -1,9 +1,53 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { $t as ParagraphMarkChange, Br as TableCellFormatting, Dr as NumberingDefinitions, Fn as Table, Kr as TableRowFormatting, M as BlockContent, Or as NumberingInstance, Pn as TabContent, Pr as ParagraphFormatting, Qt as ParagraphContent, R as BreakContent, Vr as TableFormatting, Wn as TableRow, X as DocumentBody, Yr as TextFormatting, Zt as Paragraph, _t as INSERTION_SEAM_POLICIES, bn as SectionProperties, c as ExhaustiveFields, h as Relationship, i as DocumentSettings, m as MediaFile, mi as HeadingOutlineLevel, mn as RunContent, mt as HeaderFooterType, nt as Endnote, o as DocxPackage, pn as Run, pt as HeaderFooter, r as Document, tn as ParagraphPropertyChange, ut as Footnote, vr as AbstractNumbering, y as StyleDefinitions, yn as Section } from "../document-C73n0FqK.js";
|
|
2
2
|
import { Result } from "better-result";
|
|
3
|
+
//#region src/ops/noteMarks.d.ts
|
|
4
|
+
declare const noteUsesCustomMark: (document: Document, note: Footnote | Endnote) => boolean;
|
|
5
|
+
//#endregion
|
|
3
6
|
//#region src/ops/types.d.ts
|
|
7
|
+
/** JSON-safe map presence, including an explicitly undefined section map. */
|
|
8
|
+
type SectionMapState = {
|
|
9
|
+
type: "omitted";
|
|
10
|
+
} | {
|
|
11
|
+
type: "undefined";
|
|
12
|
+
} | {
|
|
13
|
+
type: "entries";
|
|
14
|
+
value: readonly (readonly [HeaderFooterType, HeaderFooter])[];
|
|
15
|
+
};
|
|
16
|
+
/** Section content is derived from the body's canonical blocks. */
|
|
17
|
+
type SectionViewEntry = {
|
|
18
|
+
properties: SectionProperties;
|
|
19
|
+
headers: SectionMapState;
|
|
20
|
+
footers: SectionMapState;
|
|
21
|
+
};
|
|
22
|
+
/** Exact presence and metadata of the derived section view. */
|
|
23
|
+
type SectionViewState = {
|
|
24
|
+
type: "omitted";
|
|
25
|
+
} | {
|
|
26
|
+
type: "undefined";
|
|
27
|
+
} | {
|
|
28
|
+
type: "sections";
|
|
29
|
+
value: readonly SectionViewEntry[];
|
|
30
|
+
};
|
|
31
|
+
type SectionViewChange = {
|
|
32
|
+
expected: readonly SectionViewEntry[];
|
|
33
|
+
restore: readonly SectionViewEntry[];
|
|
34
|
+
};
|
|
4
35
|
/**
|
|
5
36
|
* The operation schema this module reads and writes.
|
|
6
37
|
*
|
|
38
|
+
* Version 9 adds exact, JSON-safe package resource replacement for clipboard imports.
|
|
39
|
+
* Version 8 adds semantic table edits and exact whole-table restoration.
|
|
40
|
+
* Version 7 adds lossless own-undefined operation snapshot presence and
|
|
41
|
+
* explicit revision-boundary provenance. An explicit undefined patch value now
|
|
42
|
+
* sets an own undefined field; null removes it and an absent key is untouched.
|
|
43
|
+
* Older envelopes receive a structured
|
|
44
|
+
* unsupportedSchema refusal; no older deployed journal clients are supported.
|
|
45
|
+
* Version 6 extends PR6 schema 5 with numbering-instance creation, section-endpoint
|
|
46
|
+
* edits and JSON-safe exact section-map/view presence. Older envelopes receive an
|
|
47
|
+
* unsupportedSchema refusal; no older deployed journal clients are supported.
|
|
48
|
+
* Version 5 adds explicit section-boundary removal/restoration and separately
|
|
49
|
+
* rejectable paragraph-property reviews over an existing revision.
|
|
50
|
+
* Version 5 adds header/footer/note story addresses and exact lifecycle operations.
|
|
7
51
|
* Version 4 adds paragraph deletion through `deleteBlocks`, direct and tracked
|
|
8
52
|
* whole-table operations with their exact structural inverse, terminal insertion,
|
|
9
53
|
* and cell-ending paragraph marks on tracked row operations.
|
|
@@ -13,16 +57,24 @@ import { Result } from "better-result";
|
|
|
13
57
|
* and paragraph operations, and the review operations `setParagraphReview`,
|
|
14
58
|
* `replaceInline` and `resolveRevision`.
|
|
15
59
|
*/
|
|
16
|
-
declare const DOCUMENT_OP_SCHEMA_VERSION =
|
|
60
|
+
declare const DOCUMENT_OP_SCHEMA_VERSION = 9;
|
|
17
61
|
/**
|
|
18
|
-
* The
|
|
19
|
-
*
|
|
62
|
+
* The main story has a fixed address; other editable parts use their stable
|
|
63
|
+
* relationship id or note id. Comment bodies are not yet editable stories.
|
|
20
64
|
*/
|
|
21
65
|
declare const OP_STORIES: Readonly<{
|
|
22
66
|
readonly MAIN: "main";
|
|
23
67
|
}>;
|
|
24
|
-
/**
|
|
25
|
-
type
|
|
68
|
+
/** The stable identity of an independently editable package story. */
|
|
69
|
+
type HeaderFooterStory = {
|
|
70
|
+
kind: "header" | "footer";
|
|
71
|
+
rId: string;
|
|
72
|
+
};
|
|
73
|
+
type NoteStory = {
|
|
74
|
+
kind: "footnote" | "endnote";
|
|
75
|
+
id: number;
|
|
76
|
+
};
|
|
77
|
+
type OpStory = typeof OP_STORIES.MAIN | HeaderFooterStory | NoteStory;
|
|
26
78
|
/**
|
|
27
79
|
* A point in one paragraph's logical offset space.
|
|
28
80
|
*
|
|
@@ -43,10 +95,10 @@ type TextPosition = {
|
|
|
43
95
|
zeroWidthBefore?: number;
|
|
44
96
|
};
|
|
45
97
|
/**
|
|
46
|
-
* Per-key change
|
|
47
|
-
*
|
|
98
|
+
* Per-key change: a value, including explicit undefined, sets an owned key;
|
|
99
|
+
* null removes the key, and an omitted key is untouched.
|
|
48
100
|
*/
|
|
49
|
-
type FormattingPatch<Formatting> = { readonly [Key in keyof Formatting]?:
|
|
101
|
+
type FormattingPatch<Formatting> = { readonly [Key in keyof Formatting]?: Formatting[Key] | null | undefined; };
|
|
50
102
|
/** A change to a run property set (`w:rPr`). */
|
|
51
103
|
type RunPropsPatch = FormattingPatch<TextFormatting>;
|
|
52
104
|
/** A change to a paragraph property set (`w:pPr`). */
|
|
@@ -115,8 +167,19 @@ type RevisionStamp = {
|
|
|
115
167
|
};
|
|
116
168
|
/** The paragraph fields a split gives the new paragraph, besides its id, content and mark. */
|
|
117
169
|
type SplitParagraphFields = Omit<Paragraph, "type" | "paraId" | "content" | "sectionProperties" | "pPrMark">;
|
|
118
|
-
/**
|
|
170
|
+
/** Explicit structural and review policies for editor intent compilation. */
|
|
171
|
+
declare const SECTION_BOUNDARY_POLICIES: Readonly<{
|
|
172
|
+
readonly REMOVE: "remove";
|
|
173
|
+
readonly REPLACE: "replace";
|
|
174
|
+
}>;
|
|
175
|
+
/** The operation kinds of schema version 9. */
|
|
119
176
|
declare const DOCUMENT_OP_TYPES: Readonly<{
|
|
177
|
+
readonly CREATE_HEADER_FOOTER: "createHeaderFooter";
|
|
178
|
+
readonly REMOVE_HEADER_FOOTER: "removeHeaderFooter";
|
|
179
|
+
readonly ADD_NOTE: "addNote";
|
|
180
|
+
readonly REMOVE_NOTE: "removeNote";
|
|
181
|
+
readonly SET_SECTION_PROPS: "setSectionProps";
|
|
182
|
+
readonly RESTORE_STORY_PARTS: "restoreStoryParts";
|
|
120
183
|
readonly DELETE_BLOCKS: "deleteBlocks";
|
|
121
184
|
readonly INSERT_BLOCKS: "insertBlocks";
|
|
122
185
|
readonly INSERT_TEXT: "insertText";
|
|
@@ -138,6 +201,19 @@ declare const DOCUMENT_OP_TYPES: Readonly<{
|
|
|
138
201
|
readonly INSERT_ROW: "insertRow";
|
|
139
202
|
readonly DELETE_ROW: "deleteRow";
|
|
140
203
|
readonly SET_TABLE_ROWS: "setTableRows";
|
|
204
|
+
readonly INSERT_COLUMN: "insertColumn";
|
|
205
|
+
readonly DELETE_COLUMN: "deleteColumn";
|
|
206
|
+
readonly MERGE_CELLS: "mergeCells";
|
|
207
|
+
readonly SPLIT_CELL: "splitCell";
|
|
208
|
+
readonly SET_TABLE_GRID: "setTableGrid";
|
|
209
|
+
readonly SET_CELL_PROPS: "setCellProps";
|
|
210
|
+
readonly SET_ROW_PROPS: "setRowProps";
|
|
211
|
+
readonly SET_TABLE_PROPS: "setTableProps";
|
|
212
|
+
readonly SET_TABLE: "setTable";
|
|
213
|
+
readonly CREATE_NUMBERING_INSTANCE: "createNumberingInstance";
|
|
214
|
+
readonly DELETE_NUMBERING_INSTANCE: "deleteNumberingInstance";
|
|
215
|
+
readonly SET_SECTION_ENDPOINT: "setSectionEndpoint";
|
|
216
|
+
readonly SET_PACKAGE_RESOURCES: "setPackageResources";
|
|
141
217
|
}>;
|
|
142
218
|
/** One of {@link DOCUMENT_OP_TYPES}. */
|
|
143
219
|
type DocumentOpType = (typeof DOCUMENT_OP_TYPES)[keyof typeof DOCUMENT_OP_TYPES];
|
|
@@ -183,6 +259,7 @@ type InsertContentOp = {
|
|
|
183
259
|
type: typeof DOCUMENT_OP_TYPES.INSERT_CONTENT;
|
|
184
260
|
at: TextPosition;
|
|
185
261
|
slice: InlineSlice;
|
|
262
|
+
seamPolicy?: typeof INSERTION_SEAM_POLICIES.MERGE_PLAIN_RUNS;
|
|
186
263
|
newIds?: NewIds;
|
|
187
264
|
revision?: RevisionStamp;
|
|
188
265
|
};
|
|
@@ -239,6 +316,10 @@ type JoinInlineOp = {
|
|
|
239
316
|
at: TextPosition;
|
|
240
317
|
depth: number;
|
|
241
318
|
};
|
|
319
|
+
/** Whether a tracked run patch appends an independently rejectable review. */
|
|
320
|
+
declare const PROPERTY_REVIEW_POLICIES: Readonly<{
|
|
321
|
+
readonly APPEND: "append";
|
|
322
|
+
}>;
|
|
242
323
|
/**
|
|
243
324
|
* Patch the run properties of every run between two positions of one
|
|
244
325
|
* paragraph, splitting runs at the range ends. A run the patch does not change
|
|
@@ -256,6 +337,8 @@ type JoinInlineOp = {
|
|
|
256
337
|
* set before the patch. A run already carrying one keeps it, and with it the
|
|
257
338
|
* formatting it started from. A tracked patch joins nothing, so `joinStart`
|
|
258
339
|
* and `joinEnd` must be absent.
|
|
340
|
+
* `propertyReview: "append"` records a separately rejectable action over
|
|
341
|
+
* existing review, preserving the current formatting as that action's baseline.
|
|
259
342
|
*/
|
|
260
343
|
type SetRunPropsOp = {
|
|
261
344
|
type: typeof DOCUMENT_OP_TYPES.SET_RUN_PROPS;
|
|
@@ -268,6 +351,7 @@ type SetRunPropsOp = {
|
|
|
268
351
|
joinEnd?: number;
|
|
269
352
|
newIds?: NewIds;
|
|
270
353
|
revision?: RevisionStamp;
|
|
354
|
+
propertyReview?: typeof PROPERTY_REVIEW_POLICIES.APPEND;
|
|
271
355
|
};
|
|
272
356
|
/**
|
|
273
357
|
* Patch a paragraph's own property set. `expected` states the values the
|
|
@@ -276,7 +360,8 @@ type SetRunPropsOp = {
|
|
|
276
360
|
*
|
|
277
361
|
* With `revision`, the paragraph records a tracked property change
|
|
278
362
|
* (`w:pPrChange`) whose previous formatting is its own property set before
|
|
279
|
-
* the patch, or
|
|
363
|
+
* the patch, or folds into the one it already carries: its original baseline and
|
|
364
|
+
* id stay, and its author/date become the latest stamp. A property change holds
|
|
280
365
|
* paragraph properties only, not the paragraph mark's run properties, so a
|
|
281
366
|
* tracked patch of {@link PARAGRAPH_MARK_FORMATTING_KEYS} is refused.
|
|
282
367
|
*/
|
|
@@ -339,6 +424,9 @@ type SplitBlockOp = {
|
|
|
339
424
|
newHalf?: SplitHalf;
|
|
340
425
|
newParagraph?: SplitParagraphFields;
|
|
341
426
|
firstMark?: ParagraphMarkChange;
|
|
427
|
+
/** Exact inverse restoration of a removed section boundary on the first half. */
|
|
428
|
+
firstSectionProperties?: SectionProperties;
|
|
429
|
+
sectionView?: SectionViewChange;
|
|
342
430
|
newIds?: NewIds;
|
|
343
431
|
revision?: RevisionStamp;
|
|
344
432
|
};
|
|
@@ -349,8 +437,9 @@ type SplitBlockOp = {
|
|
|
349
437
|
* run properties, section break, tracked change and the pending property
|
|
350
438
|
* changes. It keeps the identity and own fields of the
|
|
351
439
|
* `survivor` half, by default the second, and the other's id is retired.
|
|
352
|
-
* `depth` merges
|
|
353
|
-
*
|
|
440
|
+
* An absent or zero `depth` merges the two plain runs at the seam when the
|
|
441
|
+
* parser would merge them. A positive `depth` merges that many levels of the
|
|
442
|
+
* records meeting at the join, as {@link JoinInlineOp} does.
|
|
354
443
|
*
|
|
355
444
|
* `expectedRetired` states the own fields of the paragraph the join retires,
|
|
356
445
|
* and `expectedSurvivor` the review fields of the one it keeps, which the
|
|
@@ -363,7 +452,8 @@ type SplitBlockOp = {
|
|
|
363
452
|
* the direct join would give it as a tracked property change. Accepting removes the mark, which
|
|
364
453
|
* leaves the second paragraph with the first's content before its own: what
|
|
365
454
|
* the direct join leaves. A tracked join always leaves the second, so
|
|
366
|
-
* `survivor` must then be absent or `second
|
|
455
|
+
* `survivor` must then be absent or `second`, and `depth` absent or zero: the
|
|
456
|
+
* paragraph mark cannot record an inline merge depth.
|
|
367
457
|
*/
|
|
368
458
|
type JoinBlocksOp = {
|
|
369
459
|
type: typeof DOCUMENT_OP_TYPES.JOIN_BLOCKS;
|
|
@@ -374,6 +464,9 @@ type JoinBlocksOp = {
|
|
|
374
464
|
survivor?: SplitHalf;
|
|
375
465
|
expectedRetired?: SplitParagraphFields;
|
|
376
466
|
expectedSurvivor?: ParagraphReviewFields;
|
|
467
|
+
/** Explicitly remove the first paragraph's section boundary with its mark. */
|
|
468
|
+
sectionBoundary?: typeof SECTION_BOUNDARY_POLICIES.REMOVE;
|
|
469
|
+
sectionView?: SectionViewChange;
|
|
377
470
|
newIds?: NewIds;
|
|
378
471
|
revision?: RevisionStamp;
|
|
379
472
|
};
|
|
@@ -436,6 +529,9 @@ type ReplaceBlocksOp = {
|
|
|
436
529
|
story: OpStory;
|
|
437
530
|
expected: readonly Paragraph[];
|
|
438
531
|
blocks: readonly Paragraph[];
|
|
532
|
+
/** Exact structural replacement may intentionally change section boundaries. */
|
|
533
|
+
sectionBoundaries?: typeof SECTION_BOUNDARY_POLICIES.REPLACE;
|
|
534
|
+
sectionView?: SectionViewChange;
|
|
439
535
|
};
|
|
440
536
|
/**
|
|
441
537
|
* A paragraph's review fields: its paragraph properties, their tracked change
|
|
@@ -557,6 +653,98 @@ type SetTableRowsOp = {
|
|
|
557
653
|
expected: readonly TableRow[];
|
|
558
654
|
rows: readonly TableRow[];
|
|
559
655
|
};
|
|
656
|
+
/** Whether the package numbering part was omitted, explicitly undefined, or present. */
|
|
657
|
+
type NumberingPartState = {
|
|
658
|
+
type: "omitted";
|
|
659
|
+
} | {
|
|
660
|
+
type: "undefined";
|
|
661
|
+
} | {
|
|
662
|
+
type: "definitions";
|
|
663
|
+
value: NumberingDefinitions;
|
|
664
|
+
};
|
|
665
|
+
/** Add a pre-allocated numbering instance and optional abstract definition. */
|
|
666
|
+
type CreateNumberingInstanceOp = {
|
|
667
|
+
type: typeof DOCUMENT_OP_TYPES.CREATE_NUMBERING_INSTANCE;
|
|
668
|
+
num: NumberingInstance;
|
|
669
|
+
abstractNum?: AbstractNumbering;
|
|
670
|
+
expected?: NumberingPartState;
|
|
671
|
+
restore?: NumberingPartState;
|
|
672
|
+
};
|
|
673
|
+
/** Remove the exact instance created by the paired operation. */
|
|
674
|
+
type DeleteNumberingInstanceOp = {
|
|
675
|
+
type: typeof DOCUMENT_OP_TYPES.DELETE_NUMBERING_INSTANCE;
|
|
676
|
+
num: NumberingInstance;
|
|
677
|
+
abstractNum?: AbstractNumbering;
|
|
678
|
+
expected?: NumberingPartState;
|
|
679
|
+
restore?: NumberingPartState;
|
|
680
|
+
};
|
|
681
|
+
/** Presence is explicit so inverses restore omitted and undefined package fields exactly. */
|
|
682
|
+
type PackageResourcePart<Value> = {
|
|
683
|
+
type: "omitted";
|
|
684
|
+
} | {
|
|
685
|
+
type: "undefined";
|
|
686
|
+
} | {
|
|
687
|
+
type: "present";
|
|
688
|
+
value: Value;
|
|
689
|
+
};
|
|
690
|
+
/** JSON-safe media bytes, rather than an ArrayBuffer that JSON discards. */
|
|
691
|
+
type PackageResourceMedia = Omit<MediaFile, "data"> & {
|
|
692
|
+
data: readonly number[];
|
|
693
|
+
};
|
|
694
|
+
/** Package definitions captured before and after an explicit clipboard import. */
|
|
695
|
+
type PackageResources = {
|
|
696
|
+
styles: PackageResourcePart<StyleDefinitions>;
|
|
697
|
+
numbering: PackageResourcePart<NumberingDefinitions>;
|
|
698
|
+
};
|
|
699
|
+
type PackageResourcePresence = PackageResourcePart<unknown>["type"];
|
|
700
|
+
type PackageResourceEntry<Value> = {
|
|
701
|
+
type: "absent";
|
|
702
|
+
} | {
|
|
703
|
+
type: "present";
|
|
704
|
+
value: Value;
|
|
705
|
+
};
|
|
706
|
+
type PackageResourceEntryChange<Value> = {
|
|
707
|
+
key: string;
|
|
708
|
+
expected: PackageResourceEntry<Value>;
|
|
709
|
+
next: PackageResourceEntry<Value>;
|
|
710
|
+
};
|
|
711
|
+
/** Keyed changes to a package map; entries the operation leaves alone are not carried. */
|
|
712
|
+
type PackageResourceMapChange<Value> = {
|
|
713
|
+
expected: PackageResourcePresence;
|
|
714
|
+
next: PackageResourcePresence;
|
|
715
|
+
entries: readonly PackageResourceEntryChange<Value>[];
|
|
716
|
+
};
|
|
717
|
+
/** Replace merged definitions and change keyed package entries, refusing stale package data. */
|
|
718
|
+
type SetPackageResourcesOp = {
|
|
719
|
+
type: typeof DOCUMENT_OP_TYPES.SET_PACKAGE_RESOURCES;
|
|
720
|
+
expected: PackageResources;
|
|
721
|
+
resources: PackageResources;
|
|
722
|
+
relationships: PackageResourceMapChange<Relationship>;
|
|
723
|
+
media: PackageResourceMapChange<PackageResourceMedia>;
|
|
724
|
+
};
|
|
725
|
+
/** A section endpoint is either a paragraph's sectPr or the body's final sectPr. */
|
|
726
|
+
type SectionEndpoint = {
|
|
727
|
+
type: "paragraph";
|
|
728
|
+
blockId: string;
|
|
729
|
+
} | {
|
|
730
|
+
type: "final";
|
|
731
|
+
};
|
|
732
|
+
type SectionPropertiesState = {
|
|
733
|
+
type: "omitted";
|
|
734
|
+
} | {
|
|
735
|
+
type: "undefined";
|
|
736
|
+
} | {
|
|
737
|
+
type: "present";
|
|
738
|
+
value: SectionProperties;
|
|
739
|
+
};
|
|
740
|
+
type SetSectionEndpointOp = {
|
|
741
|
+
type: typeof DOCUMENT_OP_TYPES.SET_SECTION_ENDPOINT;
|
|
742
|
+
endpoint: SectionEndpoint;
|
|
743
|
+
expected?: SectionPropertiesState;
|
|
744
|
+
properties: SectionPropertiesState;
|
|
745
|
+
expectedSectionMetadata?: SectionViewState;
|
|
746
|
+
sectionMetadata?: SectionViewState;
|
|
747
|
+
};
|
|
560
748
|
/**
|
|
561
749
|
* Insert a table before or after a paragraph. Tracking records each row,
|
|
562
750
|
* cell content and cell-ending paragraph mark. At a container's end,
|
|
@@ -600,8 +788,124 @@ type SetContainerBlocksOp = {
|
|
|
600
788
|
expected: readonly BlockContent[];
|
|
601
789
|
blocks: readonly BlockContent[];
|
|
602
790
|
};
|
|
603
|
-
/**
|
|
604
|
-
type
|
|
791
|
+
/** Create a deterministically identified part and bind it to one section variant. */
|
|
792
|
+
type CreateHeaderFooterOp = {
|
|
793
|
+
type: typeof DOCUMENT_OP_TYPES.CREATE_HEADER_FOOTER;
|
|
794
|
+
sectionIndex: number;
|
|
795
|
+
story: HeaderFooterStory;
|
|
796
|
+
referenceType: HeaderFooterType;
|
|
797
|
+
content: BlockContent[];
|
|
798
|
+
};
|
|
799
|
+
type RemoveHeaderFooterOp = {
|
|
800
|
+
type: typeof DOCUMENT_OP_TYPES.REMOVE_HEADER_FOOTER;
|
|
801
|
+
sectionIndex: number;
|
|
802
|
+
story: HeaderFooterStory;
|
|
803
|
+
referenceType: HeaderFooterType;
|
|
804
|
+
};
|
|
805
|
+
type AddNoteOp = {
|
|
806
|
+
type: typeof DOCUMENT_OP_TYPES.ADD_NOTE;
|
|
807
|
+
at: TextPosition;
|
|
808
|
+
note: Footnote | Endnote;
|
|
809
|
+
};
|
|
810
|
+
type RemoveNoteOp = {
|
|
811
|
+
type: typeof DOCUMENT_OP_TYPES.REMOVE_NOTE;
|
|
812
|
+
at: TextPosition;
|
|
813
|
+
story: NoteStory;
|
|
814
|
+
};
|
|
815
|
+
type SetSectionPropsOp = {
|
|
816
|
+
type: typeof DOCUMENT_OP_TYPES.SET_SECTION_PROPS;
|
|
817
|
+
sectionIndex: number;
|
|
818
|
+
patch: FormattingPatch<SectionProperties>;
|
|
819
|
+
};
|
|
820
|
+
/** JSON-safe lifecycle deltas: omitted fields are unowned, null restores absence. */
|
|
821
|
+
type StoryParts = {
|
|
822
|
+
body?: { [Key in keyof Omit<DocumentBody, "sections">]?: Key extends "content" ? DocumentBody[Key] : Exclude<DocumentBody[Key], undefined> | null; };
|
|
823
|
+
/** Section contents remain derived from the body's content and are never duplicated. */
|
|
824
|
+
sections?: readonly {
|
|
825
|
+
index: number;
|
|
826
|
+
properties?: Section["properties"];
|
|
827
|
+
headers?: readonly (readonly [HeaderFooterType, HeaderFooter])[] | null;
|
|
828
|
+
footers?: readonly (readonly [HeaderFooterType, HeaderFooter])[] | null;
|
|
829
|
+
}[];
|
|
830
|
+
headers?: readonly (readonly [string, HeaderFooter])[] | null;
|
|
831
|
+
footers?: readonly (readonly [string, HeaderFooter])[] | null;
|
|
832
|
+
footnotes?: readonly Footnote[] | null;
|
|
833
|
+
endnotes?: readonly Endnote[] | null;
|
|
834
|
+
settings?: DocumentSettings | null;
|
|
835
|
+
};
|
|
836
|
+
/** Exact stale-checked lifecycle inverse; unrelated package parts stay untouched. */
|
|
837
|
+
type RestoreStoryPartsOp = {
|
|
838
|
+
type: typeof DOCUMENT_OP_TYPES.RESTORE_STORY_PARTS;
|
|
839
|
+
expected: StoryParts;
|
|
840
|
+
parts: StoryParts;
|
|
841
|
+
};
|
|
842
|
+
/** A paragraph selects its innermost table; columns are logical grid slots. */
|
|
843
|
+
type TableEditTarget = {
|
|
844
|
+
story: OpStory;
|
|
845
|
+
blockId: string;
|
|
846
|
+
revision?: RevisionStamp;
|
|
847
|
+
newIds?: NewIds;
|
|
848
|
+
};
|
|
849
|
+
/** Insert before column (including the final boundary); fresh ids are in row order. */
|
|
850
|
+
type InsertColumnOp = TableEditTarget & {
|
|
851
|
+
type: typeof DOCUMENT_OP_TYPES.INSERT_COLUMN;
|
|
852
|
+
column: number;
|
|
853
|
+
width: number;
|
|
854
|
+
newBlockIds: readonly string[];
|
|
855
|
+
};
|
|
856
|
+
type DeleteColumnOp = TableEditTarget & {
|
|
857
|
+
type: typeof DOCUMENT_OP_TYPES.DELETE_COLUMN;
|
|
858
|
+
column: number;
|
|
859
|
+
};
|
|
860
|
+
/** Half-open logical rectangle; every touched span must be wholly contained. */
|
|
861
|
+
type MergeCellsOp = TableEditTarget & {
|
|
862
|
+
type: typeof DOCUMENT_OP_TYPES.MERGE_CELLS;
|
|
863
|
+
top: number;
|
|
864
|
+
bottom: number;
|
|
865
|
+
left: number;
|
|
866
|
+
right: number;
|
|
867
|
+
newBlockIds: readonly string[];
|
|
868
|
+
};
|
|
869
|
+
/** Split the addressed span into unit cells; the top-left cell keeps its content and identity. */
|
|
870
|
+
type SplitCellOp = TableEditTarget & {
|
|
871
|
+
type: typeof DOCUMENT_OP_TYPES.SPLIT_CELL;
|
|
872
|
+
newBlockIds: readonly string[];
|
|
873
|
+
};
|
|
874
|
+
/** Resize the existing logical grid without changing its topology. */
|
|
875
|
+
type SetTableGridOp = TableEditTarget & {
|
|
876
|
+
type: typeof DOCUMENT_OP_TYPES.SET_TABLE_GRID;
|
|
877
|
+
columnWidths: readonly number[];
|
|
878
|
+
};
|
|
879
|
+
type SetCellPropsOp = TableEditTarget & {
|
|
880
|
+
type: typeof DOCUMENT_OP_TYPES.SET_CELL_PROPS;
|
|
881
|
+
patch: FormattingPatch<TableCellFormatting>;
|
|
882
|
+
};
|
|
883
|
+
type SetRowPropsOp = TableEditTarget & {
|
|
884
|
+
type: typeof DOCUMENT_OP_TYPES.SET_ROW_PROPS;
|
|
885
|
+
patch: FormattingPatch<TableRowFormatting>;
|
|
886
|
+
};
|
|
887
|
+
type SetTablePropsOp = TableEditTarget & {
|
|
888
|
+
type: typeof DOCUMENT_OP_TYPES.SET_TABLE_PROPS;
|
|
889
|
+
patch: FormattingPatch<TableFormatting>;
|
|
890
|
+
};
|
|
891
|
+
/** Exact inverse/resolution primitive, including grid and captured markup. */
|
|
892
|
+
type SetTableOp = {
|
|
893
|
+
type: typeof DOCUMENT_OP_TYPES.SET_TABLE;
|
|
894
|
+
story: OpStory;
|
|
895
|
+
blockId: string;
|
|
896
|
+
expected: Table;
|
|
897
|
+
table: Table;
|
|
898
|
+
};
|
|
899
|
+
type TableEditOp = InsertColumnOp | DeleteColumnOp | MergeCellsOp | SplitCellOp | SetTableGridOp | SetCellPropsOp | SetRowPropsOp | SetTablePropsOp;
|
|
900
|
+
/** Table intent ids are derived from topology by the shared compiler. */
|
|
901
|
+
type TableIntentOperation = { [Kind in TableEditOp["type"]]: Omit<Extract<TableEditOp, {
|
|
902
|
+
type: Kind;
|
|
903
|
+
}>, "revision" | "newIds" | "newBlockIds">; }[TableEditOp["type"]];
|
|
904
|
+
/** A schema-version-9 document operation. */
|
|
905
|
+
type DocumentOp = (CreateHeaderFooterOp | RemoveHeaderFooterOp | AddNoteOp | RemoveNoteOp | SetSectionPropsOp | RestoreStoryPartsOp | DeleteBlocksOp | InsertTableOp | DeleteTableOp | SetContainerBlocksOp | InsertBlocksOp | InsertTextOp | InsertContentOp | DeleteRangeOp | SplitInlineOp | JoinInlineOp | SetRunPropsOp | SetParagraphPropsOp | SplitBlockOp | JoinBlocksOp | ReplaceBlocksOp | SetParagraphReviewOp | ReplaceInlineOp | ResolveRevisionOp | InsertRowOp | DeleteRowOp | SetTableRowsOp | TableEditOp | SetTableOp | CreateNumberingInstanceOp | DeleteNumberingInstanceOp | SetSectionEndpointOp | SetPackageResourcesOp) & {
|
|
906
|
+
/** Own undefined fields recorded by the operation capture boundary. */
|
|
907
|
+
undefinedFields?: readonly (readonly string[])[];
|
|
908
|
+
};
|
|
605
909
|
/**
|
|
606
910
|
* An operation as it is journaled and sent: the schema that reads it, and the
|
|
607
911
|
* operation. A reader refuses an envelope of a schema it does not know rather
|
|
@@ -620,14 +924,35 @@ type TouchedBlocks = {
|
|
|
620
924
|
removed: readonly string[];
|
|
621
925
|
};
|
|
622
926
|
//#endregion
|
|
927
|
+
//#region src/ops/edits.d.ts
|
|
928
|
+
/** What applying operations produced: the document, its inverse, and the blocks it changed. */
|
|
929
|
+
type DocumentEdit = {
|
|
930
|
+
document: Document;
|
|
931
|
+
/** Apply in order to restore the input document. */
|
|
932
|
+
inverse: readonly DocumentOp[];
|
|
933
|
+
touched: TouchedBlocks;
|
|
934
|
+
};
|
|
935
|
+
/** Edits made in turn, starting from `document`, as one edit. */
|
|
936
|
+
declare const combineEdits: (document: Document, edits: readonly DocumentEdit[]) => DocumentEdit;
|
|
937
|
+
//#endregion
|
|
623
938
|
//#region src/ops/refusal.d.ts
|
|
624
939
|
/**
|
|
625
940
|
* Why an operation was not applied. A refused operation changes nothing: the
|
|
626
941
|
* document it was applied to is returned as it was.
|
|
627
942
|
*/
|
|
628
943
|
declare const DOCUMENT_OP_REFUSAL_REASONS: Readonly<{
|
|
944
|
+
/** The journal envelope uses a schema this reader does not implement. */
|
|
945
|
+
readonly UNSUPPORTED_SCHEMA: "unsupportedSchema";
|
|
629
946
|
/** No paragraph in the story carries the id. */
|
|
630
947
|
readonly BLOCK_NOT_FOUND: "blockNotFound";
|
|
948
|
+
/** A raw operation is missing required fields or supplies their wrong shape. */
|
|
949
|
+
readonly INVALID_OPERATION: "invalidOperation";
|
|
950
|
+
/** Removing a column would leave a row with no active cells. */
|
|
951
|
+
readonly TABLE_ROW_EMPTY: "tableRowEmpty";
|
|
952
|
+
/** The requested topology edit changes nothing. */
|
|
953
|
+
readonly NO_CHANGE: "noChange";
|
|
954
|
+
/** Removed content carries anchors or review records that require coordinated resolution. */
|
|
955
|
+
readonly DEPENDENT_RECORDS: "dependentRecords";
|
|
631
956
|
/** An offset is not an integer from `0` to the paragraph's length, or a range runs backwards. */
|
|
632
957
|
readonly INVALID_OFFSET: "invalidOffset";
|
|
633
958
|
/** A range starts and ends in different paragraphs or stories. */
|
|
@@ -716,9 +1041,215 @@ declare const DocumentOpRefusal_base: import("better-result").TaggedErrorClass<"
|
|
|
716
1041
|
declare class DocumentOpRefusal extends DocumentOpRefusal_base<{
|
|
717
1042
|
message: string;
|
|
718
1043
|
reason: DocumentOpRefusalReason;
|
|
719
|
-
opType: DocumentOpType;
|
|
1044
|
+
opType: DocumentOpType | undefined;
|
|
720
1045
|
}> {}
|
|
721
1046
|
//#endregion
|
|
1047
|
+
//#region src/ops/storyLifecycle.d.ts
|
|
1048
|
+
declare const sectionPropertiesAt: (document: Document, sectionIndex: number) => SectionProperties | undefined;
|
|
1049
|
+
//#endregion
|
|
1050
|
+
//#region src/ops/stories.d.ts
|
|
1051
|
+
declare const sameStory: (left: OpStory, right: OpStory) => boolean;
|
|
1052
|
+
declare const findStoryBody: (document: Document, story: OpStory) => DocumentBody | undefined;
|
|
1053
|
+
declare const storyBody: (document: Document, story: OpStory) => DocumentBody;
|
|
1054
|
+
declare const documentStories: (document: Document) => OpStory[];
|
|
1055
|
+
//#endregion
|
|
1056
|
+
//#region src/ops/wire.d.ts
|
|
1057
|
+
/** Capture own undefined fields before an operation enters its JSON journal. */
|
|
1058
|
+
declare const captureDocumentOp: (op: DocumentOp) => DocumentOp;
|
|
1059
|
+
//#endregion
|
|
1060
|
+
//#region src/ops/leaves.d.ts
|
|
1061
|
+
/** A place between two leaves. */
|
|
1062
|
+
type Gap = {
|
|
1063
|
+
offset: number;
|
|
1064
|
+
zeroWidthBefore: number;
|
|
1065
|
+
};
|
|
1066
|
+
/** A node of a paragraph's content tree: a paragraph child or a run child. */
|
|
1067
|
+
type InlineNode = ParagraphContent | RunContent;
|
|
1068
|
+
/** The zero-width leaves at an offset, in document order. */
|
|
1069
|
+
declare const zeroWidthLeavesAt: (items: readonly InlineNode[], offset: number) => InlineNode[];
|
|
1070
|
+
/**
|
|
1071
|
+
* The gap an insertion defaults to: before the first zero-width leaf at the
|
|
1072
|
+
* offset that opens a range, so a marker opening there stays with what
|
|
1073
|
+
* follows it and every other one with what precedes it.
|
|
1074
|
+
*/
|
|
1075
|
+
declare const defaultInsertionGap: (items: readonly InlineNode[], offset: number) => Gap;
|
|
1076
|
+
/** Source leaf coordinates without the ancestry needed by edit planning. */
|
|
1077
|
+
declare const inlineLeafSpans: (items: readonly InlineNode[]) => {
|
|
1078
|
+
node: InlineNode;
|
|
1079
|
+
before: Gap;
|
|
1080
|
+
after: Gap;
|
|
1081
|
+
}[];
|
|
1082
|
+
/** Gaps in document order: by offset, then by the zero-width leaves before them. */
|
|
1083
|
+
declare const compareGaps: (left: Gap, right: Gap) => number;
|
|
1084
|
+
//#endregion
|
|
1085
|
+
//#region src/ops/hyperlinkIntent.d.ts
|
|
1086
|
+
type HyperlinkEditorIntent = {
|
|
1087
|
+
type: "setHyperlink";
|
|
1088
|
+
from: TextPosition;
|
|
1089
|
+
to: TextPosition;
|
|
1090
|
+
href: string;
|
|
1091
|
+
tooltip?: string;
|
|
1092
|
+
} | {
|
|
1093
|
+
type: "removeHyperlink";
|
|
1094
|
+
from: TextPosition;
|
|
1095
|
+
to: TextPosition;
|
|
1096
|
+
hyperlinkStyleId?: string;
|
|
1097
|
+
} | {
|
|
1098
|
+
type: "insertHyperlink";
|
|
1099
|
+
from: TextPosition;
|
|
1100
|
+
to: TextPosition;
|
|
1101
|
+
text: string;
|
|
1102
|
+
href: string;
|
|
1103
|
+
tooltip?: string;
|
|
1104
|
+
};
|
|
1105
|
+
//#endregion
|
|
1106
|
+
//#region src/ops/editorIntent.d.ts
|
|
1107
|
+
type SplitParagraphIntent = {
|
|
1108
|
+
type: "splitParagraph";
|
|
1109
|
+
at: TextPosition;
|
|
1110
|
+
to?: TextPosition;
|
|
1111
|
+
};
|
|
1112
|
+
/** Positions use canonical physical offsets, including retained deleted content. */
|
|
1113
|
+
type EditorIntent = HyperlinkEditorIntent | GenerateTOCIntent | {
|
|
1114
|
+
type: "table";
|
|
1115
|
+
operation: TableIntentOperation;
|
|
1116
|
+
} | {
|
|
1117
|
+
type: "replaceFragment";
|
|
1118
|
+
from: TextPosition;
|
|
1119
|
+
to: TextPosition;
|
|
1120
|
+
paragraphs: readonly Paragraph[];
|
|
1121
|
+
openStart: 0 | 1;
|
|
1122
|
+
openEnd: 0 | 1;
|
|
1123
|
+
} | {
|
|
1124
|
+
type: "moveFragment";
|
|
1125
|
+
from: TextPosition;
|
|
1126
|
+
to: TextPosition;
|
|
1127
|
+
target: TextPosition;
|
|
1128
|
+
paragraphs: readonly Paragraph[];
|
|
1129
|
+
openStart: 0 | 1;
|
|
1130
|
+
openEnd: 0 | 1;
|
|
1131
|
+
} | {
|
|
1132
|
+
type: "replaceText";
|
|
1133
|
+
from: TextPosition;
|
|
1134
|
+
to: TextPosition;
|
|
1135
|
+
text: string;
|
|
1136
|
+
runProps?: TextFormatting;
|
|
1137
|
+
runPropsPatch?: RunPropsPatch;
|
|
1138
|
+
} | {
|
|
1139
|
+
type: "formatRun";
|
|
1140
|
+
from: TextPosition;
|
|
1141
|
+
to: TextPosition;
|
|
1142
|
+
patch: RunPropsPatch;
|
|
1143
|
+
} | {
|
|
1144
|
+
type: "formatParagraph";
|
|
1145
|
+
at: TextPosition;
|
|
1146
|
+
patch: ParagraphPropsPatch;
|
|
1147
|
+
} | {
|
|
1148
|
+
type: "setList";
|
|
1149
|
+
items: readonly {
|
|
1150
|
+
at: TextPosition;
|
|
1151
|
+
ilvl: number;
|
|
1152
|
+
}[];
|
|
1153
|
+
target: {
|
|
1154
|
+
type: "existing";
|
|
1155
|
+
numId: number;
|
|
1156
|
+
} | {
|
|
1157
|
+
type: "new";
|
|
1158
|
+
num: NumberingInstance;
|
|
1159
|
+
abstractNum?: AbstractNumbering;
|
|
1160
|
+
};
|
|
1161
|
+
} | {
|
|
1162
|
+
type: "insertAtom";
|
|
1163
|
+
from: TextPosition;
|
|
1164
|
+
to: TextPosition;
|
|
1165
|
+
atom: TabContent | BreakContent;
|
|
1166
|
+
runProps?: TextFormatting;
|
|
1167
|
+
runPropsPatch?: RunPropsPatch;
|
|
1168
|
+
} | (SplitParagraphIntent & {
|
|
1169
|
+
newBlockId: string;
|
|
1170
|
+
}) | {
|
|
1171
|
+
type: "joinParagraphs";
|
|
1172
|
+
story: OpStory;
|
|
1173
|
+
blockId: string;
|
|
1174
|
+
nextBlockId: string;
|
|
1175
|
+
};
|
|
1176
|
+
/** Revision metadata and every fresh identity are supplied before compilation. */
|
|
1177
|
+
type EditorIntentMode = {
|
|
1178
|
+
/** Identities consumed during this editor lifetime, including undone insertions. */
|
|
1179
|
+
reservedBlockIds?: ReadonlySet<string>;
|
|
1180
|
+
} & ({
|
|
1181
|
+
type: "editing";
|
|
1182
|
+
newIds?: NewIds;
|
|
1183
|
+
} | {
|
|
1184
|
+
type: "suggesting";
|
|
1185
|
+
revision: RevisionStamp;
|
|
1186
|
+
newIds: NewIds;
|
|
1187
|
+
});
|
|
1188
|
+
type CompileEditorIntentOptions = {
|
|
1189
|
+
intent: EditorIntent;
|
|
1190
|
+
mode: EditorIntentMode;
|
|
1191
|
+
/** Lowest candidate for compiler-owned pasted block IDs, including retired session IDs. */
|
|
1192
|
+
firstBlockId?: number;
|
|
1193
|
+
};
|
|
1194
|
+
type CompiledEditorIntent = {
|
|
1195
|
+
ops: DocumentOp[];
|
|
1196
|
+
selection: TextPosition;
|
|
1197
|
+
};
|
|
1198
|
+
/** A split's paragraph identity is allocated with its other fresh identities. */
|
|
1199
|
+
type EditorIntentAllocation = EditorIntent | SplitParagraphIntent;
|
|
1200
|
+
/** Cache only immutable document versions; never retain a retired version strongly. */
|
|
1201
|
+
declare const createEditorIntentIdAllocator: () => (document: Document, intent: EditorIntentAllocation) => {
|
|
1202
|
+
revisionId: number;
|
|
1203
|
+
newBlockId: string;
|
|
1204
|
+
newIds: {
|
|
1205
|
+
revision: number[];
|
|
1206
|
+
control: number[];
|
|
1207
|
+
};
|
|
1208
|
+
};
|
|
1209
|
+
/** Accepted-view text without changing the canonical paragraph or its offset space. */
|
|
1210
|
+
declare const paragraphVisibleText: (paragraph: Paragraph) => string;
|
|
1211
|
+
/**
|
|
1212
|
+
* Right-affine translation: a visible gap follows retained deleted content at
|
|
1213
|
+
* that gap, so a new insertion never lands inside a deletion wrapper.
|
|
1214
|
+
* Invalid offsets remain invalid for the operation boundary to diagnose.
|
|
1215
|
+
*/
|
|
1216
|
+
declare const physicalOffsetAtVisibleOffset: (paragraph: Paragraph, offset: number) => number;
|
|
1217
|
+
/** Deleted paragraph marks concatenate physical paragraphs in the editing view. */
|
|
1218
|
+
declare const editorParagraphGroups: (document: Document, story: OpStory) => {
|
|
1219
|
+
blockId: string;
|
|
1220
|
+
paragraphs: Paragraph[];
|
|
1221
|
+
text: string;
|
|
1222
|
+
}[];
|
|
1223
|
+
/** Compile one batch; the caller applies it atomically and journals its exact inverse. */
|
|
1224
|
+
declare const compileEditorIntent: (document: Document, { intent, mode, firstBlockId }: CompileEditorIntentOptions) => Result<CompiledEditorIntent, DocumentOpRefusal>;
|
|
1225
|
+
//#endregion
|
|
1226
|
+
//#region src/ops/tocIntent.d.ts
|
|
1227
|
+
type TocHeading = {
|
|
1228
|
+
blockId: string;
|
|
1229
|
+
text: string;
|
|
1230
|
+
/** Zero-based OOXML outline level, from 0 through 8. */
|
|
1231
|
+
level: HeadingOutlineLevel;
|
|
1232
|
+
styleId?: string;
|
|
1233
|
+
};
|
|
1234
|
+
type GenerateTOCIntent = {
|
|
1235
|
+
type: "generateTOC";
|
|
1236
|
+
at: TextPosition;
|
|
1237
|
+
title: string;
|
|
1238
|
+
headings: readonly TocHeading[];
|
|
1239
|
+
titleStyleId?: string;
|
|
1240
|
+
tabPosition: number;
|
|
1241
|
+
};
|
|
1242
|
+
/** Map original endpoints through the bookmark wrappers emitted by TOC compilation. */
|
|
1243
|
+
declare const mapTocBookmarkPosition: (position: TextPosition, ops: readonly DocumentOp[]) => TextPosition;
|
|
1244
|
+
//#endregion
|
|
1245
|
+
//#region src/ops/packageResources.d.ts
|
|
1246
|
+
type PackageResourcesOpOptions = {
|
|
1247
|
+
before: Document;
|
|
1248
|
+
after: Document;
|
|
1249
|
+
};
|
|
1250
|
+
/** Describe the package resource difference as one operation carrying only changed entries. */
|
|
1251
|
+
declare const packageResourcesOpOf: ({ before, after }: PackageResourcesOpOptions) => SetPackageResourcesOp;
|
|
1252
|
+
//#endregion
|
|
722
1253
|
//#region src/ops/apply.d.ts
|
|
723
1254
|
/** A document an operation produced, the operations that undo it, and what it changed. */
|
|
724
1255
|
type AppliedDocumentOp = {
|
|
@@ -727,15 +1258,19 @@ type AppliedDocumentOp = {
|
|
|
727
1258
|
inverse: readonly DocumentOp[];
|
|
728
1259
|
touched: TouchedBlocks;
|
|
729
1260
|
/**
|
|
730
|
-
*
|
|
731
|
-
*
|
|
732
|
-
*
|
|
733
|
-
* change carrying the same stamp.
|
|
1261
|
+
* Newly allocated tracked revision ids, in document order: its stamp's
|
|
1262
|
+
* id and the new ids its other records took. Existing ids retained by a
|
|
1263
|
+
* folded or continued review are excluded; a direct operation reports none.
|
|
734
1264
|
*/
|
|
735
1265
|
revisions: readonly number[];
|
|
736
1266
|
};
|
|
737
1267
|
/** Apply one operation to a document that meets the seed contract. */
|
|
738
|
-
declare const applyDocumentOp: (document: Document,
|
|
1268
|
+
declare const applyDocumentOp: (document: Document, input: DocumentOp) => Result<AppliedDocumentOp, DocumentOpRefusal>;
|
|
1269
|
+
/** Apply a journal envelope only when its schema matches this reader. */
|
|
1270
|
+
declare const applyDocumentOpEnvelope: (document: Document, envelope: {
|
|
1271
|
+
schema: number;
|
|
1272
|
+
op: DocumentOp;
|
|
1273
|
+
}) => Result<AppliedDocumentOp, DocumentOpRefusal>;
|
|
739
1274
|
/**
|
|
740
1275
|
* Apply operations in order, atomically: the first refusal is returned and
|
|
741
1276
|
* the document is unchanged. The inverse undoes the whole list, and
|
|
@@ -743,6 +1278,64 @@ declare const applyDocumentOp: (document: Document, op: DocumentOp) => Result<Ap
|
|
|
743
1278
|
*/
|
|
744
1279
|
declare const applyDocumentOps: (document: Document, ops: readonly DocumentOp[]) => Result<AppliedDocumentOp, DocumentOpRefusal>;
|
|
745
1280
|
//#endregion
|
|
1281
|
+
//#region src/ops/runMerge.d.ts
|
|
1282
|
+
/**
|
|
1283
|
+
* Every `TextFormatting` field, named so the comparison below is total.
|
|
1284
|
+
*
|
|
1285
|
+
* A field this comparison forgets is a field one of two merged runs loses,
|
|
1286
|
+
* silently and at parse time. Naming them turns a field added to the model
|
|
1287
|
+
* without a comparison into a compile error rather than a fidelity defect.
|
|
1288
|
+
*/
|
|
1289
|
+
type ComparedTextFormattingField = "bold" | "boldCs" | "italic" | "italicCs" | "underline" | "strike" | "doubleStrike" | "vertAlign" | "smallCaps" | "allCaps" | "hidden" | "noProof" | "color" | "highlight" | "shading" | "fontSize" | "fontSizeCs" | "fontFamily" | "language" | "spacing" | "position" | "scale" | "kerning" | "effect" | "emphasisMark" | "emboss" | "imprint" | "outline" | "shadow" | "rtl" | "cs" | "styleId" | "preserved";
|
|
1290
|
+
type ComparedTextFormatting = ExhaustiveFields<TextFormatting, ComparedTextFormattingField>;
|
|
1291
|
+
/**
|
|
1292
|
+
* Check if two TextFormatting objects are equivalent
|
|
1293
|
+
*
|
|
1294
|
+
* Uses deep comparison of all properties to determine if runs
|
|
1295
|
+
* can be merged without losing formatting information.
|
|
1296
|
+
*/
|
|
1297
|
+
declare function formattingEquals(a: ComparedTextFormatting | undefined, b: ComparedTextFormatting | undefined): boolean;
|
|
1298
|
+
/**
|
|
1299
|
+
* Check if a run contains only text content
|
|
1300
|
+
* (runs with special content like images, fields, etc. should not be merged)
|
|
1301
|
+
*/
|
|
1302
|
+
declare function isTextOnlyRun(run: Run): boolean;
|
|
1303
|
+
/**
|
|
1304
|
+
* Every `Run` field, named by what a merge does with it.
|
|
1305
|
+
*
|
|
1306
|
+
* The merged run is the survivor spread whole, so a field added to the model
|
|
1307
|
+
* is carried over from one side by default. Naming each one here forces the
|
|
1308
|
+
* next field to state whether that default is right before it can compile.
|
|
1309
|
+
*/
|
|
1310
|
+
type MergeDecidedRunField =
|
|
1311
|
+
/** Identical for every run. */
|
|
1312
|
+
"type" |
|
|
1313
|
+
/** Concatenated; see {@link mergeRunContent}. */
|
|
1314
|
+
"content" |
|
|
1315
|
+
/** Must be equal, and the survivor keeps it. */
|
|
1316
|
+
"formatting" |
|
|
1317
|
+
/** Must be equal, and the survivor keeps it. */
|
|
1318
|
+
"preservedAttributes" |
|
|
1319
|
+
/** Refuses the merge outright; see {@link canMergeRun}. */
|
|
1320
|
+
"propertyChanges";
|
|
1321
|
+
type MergeDecidedRun = ExhaustiveFields<Run, MergeDecidedRunField>;
|
|
1322
|
+
/**
|
|
1323
|
+
* May two adjacent runs become one?
|
|
1324
|
+
*
|
|
1325
|
+
* Every consolidation site asks this one question, because a merge that any
|
|
1326
|
+
* one site decides differently is a merge the next parse undoes. A run holds
|
|
1327
|
+
* three records a merged run can hold only one of: its typed formatting, the
|
|
1328
|
+
* attributes `w:r` carried that the model has no field for, and the `w:rPr`
|
|
1329
|
+
* children no reader took a value from. Merging two runs that disagree on any
|
|
1330
|
+
* of them discards the loser's copy, which is how both runs' `w:rsid*` used to
|
|
1331
|
+
* vanish at parse time — before the editor, before any gate could see it.
|
|
1332
|
+
*/
|
|
1333
|
+
declare function runsMergeable(a: MergeDecidedRun, b: MergeDecidedRun): boolean;
|
|
1334
|
+
/**
|
|
1335
|
+
* Merge the content of two runs into a single content array
|
|
1336
|
+
*/
|
|
1337
|
+
declare function mergeRunContent(content1: RunContent[], content2: RunContent[]): RunContent[];
|
|
1338
|
+
//#endregion
|
|
746
1339
|
//#region src/ops/contract.d.ts
|
|
747
1340
|
declare const DocumentOpsContractError_base: import("better-result").TaggedErrorClass<"DocumentOpsContractError">;
|
|
748
1341
|
/** A document that does not meet the seed contract. */
|
|
@@ -753,7 +1346,7 @@ declare class DocumentOpsContractError extends DocumentOpsContractError_base<{
|
|
|
753
1346
|
/** Check a document against the seed contract. */
|
|
754
1347
|
declare const validateOpsDocument: (document: Document) => Result<Document, DocumentOpsContractError>;
|
|
755
1348
|
/**
|
|
756
|
-
* The document with every empty run and empty text node of
|
|
1349
|
+
* The document with every empty run and empty text node of each editable story
|
|
757
1350
|
* removed, and its section view derived again. Nothing else changes.
|
|
758
1351
|
*/
|
|
759
1352
|
declare const normalizeForOps: (document: Document) => Document;
|
|
@@ -770,6 +1363,16 @@ declare const OBJECT_REPLACEMENT_CHARACTER = "";
|
|
|
770
1363
|
*/
|
|
771
1364
|
declare const paragraphLogicalText: (paragraph: Paragraph) => string;
|
|
772
1365
|
//#endregion
|
|
1366
|
+
//#region src/ops/ids.d.ts
|
|
1367
|
+
/** Every paragraph id of a package, each story walked once. */
|
|
1368
|
+
declare const packageParagraphIds: (pkg: DocxPackage) => string[];
|
|
1369
|
+
/**
|
|
1370
|
+
* The key two spellings of one id share. `ST_LongHexNumber` is hex, so
|
|
1371
|
+
* `0000abcd` and `0000ABCD` are the same id; every lookup and comparison of
|
|
1372
|
+
* paragraph ids goes through this.
|
|
1373
|
+
*/
|
|
1374
|
+
declare const idKey: (id: string) => string;
|
|
1375
|
+
//#endregion
|
|
773
1376
|
//#region src/ops/plan.d.ts
|
|
774
1377
|
/**
|
|
775
1378
|
* How many `newIds.revision` entries an operation takes on a document,
|
|
@@ -800,10 +1403,15 @@ declare const planTrackedDeletion: (document: Document, options: PlanTrackedDele
|
|
|
800
1403
|
* paragraph, and the inline tail inserted into the retained original paragraph.
|
|
801
1404
|
* Each new paragraph's own fields apply to it, including when it takes the
|
|
802
1405
|
* source prefix. The last fragment keeps the original survivor's identity.
|
|
803
|
-
* Closed inline slices are required
|
|
804
|
-
*
|
|
1406
|
+
* Closed inline slices are required. Imported review and content-control ids
|
|
1407
|
+
* must already be distinct from destination identities; section-bearing
|
|
1408
|
+
* paragraphs require an explicit package import policy.
|
|
805
1409
|
*/
|
|
806
1410
|
type PlanTrackedReplaceOptions = PlanTrackedDeletionOptions & {
|
|
1411
|
+
sourceContainerPolicy: "join" | "separate";
|
|
1412
|
+
seamPolicy?: Extract<DocumentOp, {
|
|
1413
|
+
type: "insertContent";
|
|
1414
|
+
}>["seamPolicy"];
|
|
807
1415
|
replacement: {
|
|
808
1416
|
paragraphs: readonly Paragraph[];
|
|
809
1417
|
tail: InlineSlice;
|
|
@@ -816,4 +1424,109 @@ type PlanTrackedReplaceOptions = PlanTrackedDeletionOptions & {
|
|
|
816
1424
|
*/
|
|
817
1425
|
declare const planTrackedReplace: (document: Document, options: PlanTrackedReplaceOptions) => Result<DocumentOp[], DocumentOpRefusal>;
|
|
818
1426
|
//#endregion
|
|
819
|
-
|
|
1427
|
+
//#region src/ops/sequencing/envelope.d.ts
|
|
1428
|
+
/** A batch applies atomically, in array order, against its stated revision. */
|
|
1429
|
+
type DocumentBatch = {
|
|
1430
|
+
schema: typeof DOCUMENT_OP_SCHEMA_VERSION;
|
|
1431
|
+
opId: string;
|
|
1432
|
+
/** Opaque actor identity; authentication belongs to the caller. */
|
|
1433
|
+
actor: string;
|
|
1434
|
+
baseRev: number;
|
|
1435
|
+
ops: readonly DocumentOp[];
|
|
1436
|
+
revision?: number;
|
|
1437
|
+
};
|
|
1438
|
+
/** An operation with no position or structural effect. */
|
|
1439
|
+
declare const NO_SEQUENCED_EFFECT = "none";
|
|
1440
|
+
/** Document-dependent facts captured when an operation is sequenced. */
|
|
1441
|
+
type SequencedOpEffect = {
|
|
1442
|
+
type: "splitBlock";
|
|
1443
|
+
newHalf: SplitHalf;
|
|
1444
|
+
} | {
|
|
1445
|
+
type: "joinBlocks";
|
|
1446
|
+
firstLength: number;
|
|
1447
|
+
} | {
|
|
1448
|
+
type: "touchedBlocks";
|
|
1449
|
+
blockIds: readonly string[];
|
|
1450
|
+
} | {
|
|
1451
|
+
type: typeof NO_SEQUENCED_EFFECT;
|
|
1452
|
+
};
|
|
1453
|
+
type SequencedBatch = DocumentBatch & {
|
|
1454
|
+
revision: number;
|
|
1455
|
+
effects?: readonly SequencedOpEffect[];
|
|
1456
|
+
};
|
|
1457
|
+
declare const BATCH_REJECTION_REASONS: {
|
|
1458
|
+
readonly INVALID_BATCH: "invalidBatch";
|
|
1459
|
+
readonly UNSUPPORTED_SCHEMA: "unsupportedSchema";
|
|
1460
|
+
readonly UNSUPPORTED_PAIR: "unsupportedPair";
|
|
1461
|
+
readonly CONFLICT: "conflict";
|
|
1462
|
+
readonly STALE_BASE: "staleBase";
|
|
1463
|
+
readonly INVALID_OPERATION: "invalidOperation";
|
|
1464
|
+
readonly TABLE_REQUIRES_EXCLUSIVE_EDIT: "tableRequiresExclusiveEdit";
|
|
1465
|
+
};
|
|
1466
|
+
type BatchRejectionReason = (typeof BATCH_REJECTION_REASONS)[keyof typeof BATCH_REJECTION_REASONS];
|
|
1467
|
+
declare const BatchRejection_base: import("better-result").TaggedErrorClass<"BatchRejection">;
|
|
1468
|
+
declare class BatchRejection extends BatchRejection_base<{
|
|
1469
|
+
message: string;
|
|
1470
|
+
reason: BatchRejectionReason;
|
|
1471
|
+
opId?: string;
|
|
1472
|
+
opType?: DocumentOpType;
|
|
1473
|
+
overType?: DocumentOpType;
|
|
1474
|
+
}> {}
|
|
1475
|
+
declare const BATCH_WIRE_OP_TYPES: readonly string[];
|
|
1476
|
+
/** Bound recursion and refuse values except JSON data and absent object fields. */
|
|
1477
|
+
declare const MAX_BATCH_WIRE_BYTES: number;
|
|
1478
|
+
/** Decode a JSON-shaped batch, refusing unsupported payloads before apply. */
|
|
1479
|
+
declare const validateDocumentBatch: (value: unknown) => Result<DocumentBatch, BatchRejection>;
|
|
1480
|
+
/** Validate an assigned revision and any document-dependent effect metadata. */
|
|
1481
|
+
declare const validateSequencedBatch: (value: unknown) => Result<SequencedBatch, BatchRejection>;
|
|
1482
|
+
/** Parse the wire representation without propagating parser exceptions. */
|
|
1483
|
+
declare const parseDocumentBatch: (json: string) => Result<DocumentBatch, BatchRejection>;
|
|
1484
|
+
//#endregion
|
|
1485
|
+
//#region src/ops/sequencing/transform.d.ts
|
|
1486
|
+
type TransformOptions = {
|
|
1487
|
+
order?: "before" | "after";
|
|
1488
|
+
};
|
|
1489
|
+
/** Rebase an atomic batch over an ordered journal tail. */
|
|
1490
|
+
declare const transformBatch: (batch: DocumentBatch, over: readonly SequencedBatch[], options?: TransformOptions) => Result<DocumentBatch, BatchRejection>;
|
|
1491
|
+
//#endregion
|
|
1492
|
+
//#region src/ops/sequencing/sequencer.d.ts
|
|
1493
|
+
type BatchAck = {
|
|
1494
|
+
type: "ack";
|
|
1495
|
+
opId: string;
|
|
1496
|
+
rev: number;
|
|
1497
|
+
};
|
|
1498
|
+
type BatchReject = {
|
|
1499
|
+
type: "reject";
|
|
1500
|
+
opId: string;
|
|
1501
|
+
reason: BatchRejection;
|
|
1502
|
+
headRev: number;
|
|
1503
|
+
};
|
|
1504
|
+
type BatchSubmission = BatchAck | BatchReject;
|
|
1505
|
+
/** Deterministic append-only authority; the caller supplies delivery and storage. */
|
|
1506
|
+
declare const createSequencer: (document: Document) => {
|
|
1507
|
+
submit: (batch: DocumentBatch) => BatchSubmission;
|
|
1508
|
+
readonly document: Document;
|
|
1509
|
+
readonly headRev: number;
|
|
1510
|
+
readonly broadcasts: readonly SequencedBatch[];
|
|
1511
|
+
};
|
|
1512
|
+
//#endregion
|
|
1513
|
+
//#region src/ops/sequencing/client.d.ts
|
|
1514
|
+
type ClientNotice = {
|
|
1515
|
+
opId: string;
|
|
1516
|
+
reason: BatchRejection;
|
|
1517
|
+
ops: readonly DocumentOp[];
|
|
1518
|
+
};
|
|
1519
|
+
/** Optimistic state with ordered authoritative replay and one causal submission in flight. */
|
|
1520
|
+
declare const createClient: (document: Document) => {
|
|
1521
|
+
enqueue: (batch: DocumentBatch) => Result<DocumentBatch, BatchRejection>;
|
|
1522
|
+
nextSubmission: () => DocumentBatch | undefined;
|
|
1523
|
+
receiveAck: (ack: BatchAck) => void;
|
|
1524
|
+
receiveReject: (rejection: BatchReject) => void;
|
|
1525
|
+
receiveBroadcast: (batch: SequencedBatch) => Result<void, BatchRejection>;
|
|
1526
|
+
readonly document: Document;
|
|
1527
|
+
readonly headRev: number;
|
|
1528
|
+
readonly pending: readonly DocumentBatch[];
|
|
1529
|
+
readonly notices: readonly ClientNotice[];
|
|
1530
|
+
};
|
|
1531
|
+
//#endregion
|
|
1532
|
+
export { type AddNoteOp, type AppliedDocumentOp, BATCH_REJECTION_REASONS, BATCH_WIRE_OP_TYPES, BatchRejection, type BatchRejectionReason, type BlockInsertionPoint, type CreateHeaderFooterOp, type CreateNumberingInstanceOp, DOCUMENT_OP_REFUSAL_REASONS, DOCUMENT_OP_SCHEMA_VERSION, DOCUMENT_OP_TYPES, type DeleteBlocksOp, type DeleteColumnOp, type DeleteNumberingInstanceOp, type DeleteRangeOp, type DeleteRowOp, type DeleteTableOp, type DocumentBatch, type DocumentOp, type DocumentOpEnvelope, DocumentOpRefusal, type DocumentOpRefusalReason, type DocumentOpType, DocumentOpsContractError, EMPTY_PROPERTY_SETS, type EditorIntent, type EditorIntentMode, type EmptyPropertySet, type FormattingPatch, type HeaderFooterStory, INHERIT_RUN_PROPS, type InlineSlice, type InsertBlocksOp, type InsertColumnOp, type InsertContentOp, type InsertRowOp, type InsertTableOp, type InsertTextOp, type InsertedRunProps, type JoinBlocksOp, type JoinInlineOp, MAX_BATCH_WIRE_BYTES, type MergeCellsOp, type NewIds, type NoteStory, type NumberingPartState, OBJECT_REPLACEMENT_CHARACTER, OP_STORIES, type OpStory, PARAGRAPH_MARK_FORMATTING_KEYS, PROPERTY_REVIEW_POLICIES, type PackageResourceEntry, type PackageResourceEntryChange, type PackageResourceMapChange, type PackageResourceMedia, type PackageResourcePart, type PackageResources, type ParagraphPropsPatch, type ParagraphReviewFields, type PlanTrackedDeletionOptions, type PlanTrackedReplaceOptions, REVISION_DECISIONS, type RemoveHeaderFooterOp, type RemoveNoteOp, type ReplaceBlocksOp, type ReplaceInlineOp, type ResolveRevisionOp, type RestoreStoryPartsOp, type RevisionDecision, type RevisionStamp, type RunPropsPatch, SPLIT_HALVES, type SectionEndpoint, type SectionMapState, type SectionPropertiesState, type SectionViewEntry, type SectionViewState, type SequencedBatch, type SetCellPropsOp, type SetContainerBlocksOp, type SetPackageResourcesOp, type SetParagraphPropsOp, type SetParagraphReviewOp, type SetRowPropsOp, type SetRunPropsOp, type SetSectionEndpointOp, type SetSectionPropsOp, type SetTableGridOp, type SetTableOp, type SetTablePropsOp, type SetTableRowsOp, type SplitBlockOp, type SplitCellOp, type SplitHalf, type SplitInlineOp, type SplitParagraphFields, type TableEditOp, type TableIntentOperation, type TextPosition, type TouchedBlocks, applyDocumentOp, applyDocumentOpEnvelope, applyDocumentOps, captureDocumentOp, combineEdits, compareGaps, compileEditorIntent, createClient, createEditorIntentIdAllocator, createSequencer, defaultInsertionGap, documentStories, editorParagraphGroups, findStoryBody, formattingEquals, idKey, inlineLeafSpans, isTextOnlyRun, mapTocBookmarkPosition, mergeRunContent, normalizeForOps, noteUsesCustomMark, packageParagraphIds, packageResourcesOpOf, paragraphLength, paragraphLogicalText, paragraphVisibleText, parseDocumentBatch, physicalOffsetAtVisibleOffset, planTrackedDeletion, planTrackedReplace, revisionIdDemand, runsMergeable, sameStory, sectionPropertiesAt, storyBody, toOpEnvelope, transformBatch, validateDocumentBatch, validateOpsDocument, validateSequencedBatch, zeroWidthLeavesAt };
|