@stll/docx-core 0.27.0 → 0.28.1
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 +7 -0
- package/dist/{document-Bz9rYlJI.js → document-DdWrTPQY.js} +7 -1
- package/dist/{document-BtGS_I3E.d.ts → document-DrtmJ_hz.d.ts} +48 -3
- package/dist/docx_kernel_bg.wasm +0 -0
- package/dist/index.d.ts +7 -1
- package/dist/index.js +44 -107
- package/dist/model/document.d.ts +2 -2
- package/dist/model/document.js +1 -1
- package/dist/ops/documentOps.d.ts +421 -0
- package/dist/ops/documentOps.js +2698 -0
- package/dist/xmlEscape-T-2DeGlS.js +92 -0
- package/package.json +5 -1
|
@@ -0,0 +1,421 @@
|
|
|
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";
|
|
2
|
+
import { Result } from "better-result";
|
|
3
|
+
//#region src/ops/types.d.ts
|
|
4
|
+
/** The operation schema this module reads and writes. */
|
|
5
|
+
declare const DOCUMENT_OP_SCHEMA_VERSION = 1;
|
|
6
|
+
/**
|
|
7
|
+
* The stories an operation can address. Headers, footers, notes and comment
|
|
8
|
+
* bodies are stories too; version 1 addresses the main story only.
|
|
9
|
+
*/
|
|
10
|
+
declare const OP_STORIES: Readonly<{
|
|
11
|
+
readonly MAIN: "main";
|
|
12
|
+
}>;
|
|
13
|
+
/** One of {@link OP_STORIES}. */
|
|
14
|
+
type OpStory = (typeof OP_STORIES)[keyof typeof OP_STORIES];
|
|
15
|
+
/**
|
|
16
|
+
* A point in one paragraph's logical offset space.
|
|
17
|
+
*
|
|
18
|
+
* Several zero-width children (range markers, captured markup that shows
|
|
19
|
+
* nothing, empty containers) can sit at one offset. `zeroWidthBefore` says how
|
|
20
|
+
* many of them, in document order, come before the point; each operation
|
|
21
|
+
* states what it assumes when the field is absent. It is a second coordinate
|
|
22
|
+
* of the position: a step that rebases an operation over one that inserted or
|
|
23
|
+
* removed zero-width children at the same offset shifts it as it shifts
|
|
24
|
+
* `offset` over inserted or removed units.
|
|
25
|
+
*/
|
|
26
|
+
type TextPosition = {
|
|
27
|
+
story: OpStory;
|
|
28
|
+
/** The paragraph's `w14:paraId`. */
|
|
29
|
+
blockId: string;
|
|
30
|
+
/** Logical units from the start of the paragraph, `0` to its length. */
|
|
31
|
+
offset: number;
|
|
32
|
+
zeroWidthBefore?: number;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Per-key change to a property set: a value sets the key, `null` clears it,
|
|
36
|
+
* and a key the patch leaves out is untouched.
|
|
37
|
+
*/
|
|
38
|
+
type FormattingPatch<Formatting> = { readonly [Key in keyof Formatting]?: Exclude<Formatting[Key], undefined> | null; };
|
|
39
|
+
/** A change to a run property set (`w:rPr`). */
|
|
40
|
+
type RunPropsPatch = FormattingPatch<TextFormatting>;
|
|
41
|
+
/** A change to a paragraph property set (`w:pPr`). */
|
|
42
|
+
type ParagraphPropsPatch = FormattingPatch<ParagraphFormatting>;
|
|
43
|
+
/**
|
|
44
|
+
* What a property set a patch leaves without keys becomes: absent, or an
|
|
45
|
+
* empty set. The two state the same thing; the choice is how an inverse
|
|
46
|
+
* gives back a record in the spelling it had.
|
|
47
|
+
*/
|
|
48
|
+
declare const EMPTY_PROPERTY_SETS: Readonly<{
|
|
49
|
+
readonly OMIT: "omit";
|
|
50
|
+
readonly KEEP: "keep";
|
|
51
|
+
}>;
|
|
52
|
+
/** One of {@link EMPTY_PROPERTY_SETS}. */
|
|
53
|
+
type EmptyPropertySet = (typeof EMPTY_PROPERTY_SETS)[keyof typeof EMPTY_PROPERTY_SETS];
|
|
54
|
+
/**
|
|
55
|
+
* Inserted text takes the properties of the run it joins: the run holding the
|
|
56
|
+
* unit before the position, or the one after it at the start of a paragraph.
|
|
57
|
+
*/
|
|
58
|
+
declare const INHERIT_RUN_PROPS = "inherit";
|
|
59
|
+
/** The run properties inserted text carries. */
|
|
60
|
+
type InsertedRunProps = typeof INHERIT_RUN_PROPS | TextFormatting;
|
|
61
|
+
/**
|
|
62
|
+
* Paragraph content with its cut ends marked.
|
|
63
|
+
*
|
|
64
|
+
* `openStart` counts the levels of the first item's left edge that continue
|
|
65
|
+
* content before the insertion point: `0` puts the items in as they are, `1`
|
|
66
|
+
* merges the first item with the one ending at the point, `2` also merges
|
|
67
|
+
* their first and last children, and so on. `openEnd` is the same for the
|
|
68
|
+
* last item and the content after the point. It is the shape a deletion
|
|
69
|
+
* removes, and the shape that puts it back.
|
|
70
|
+
*/
|
|
71
|
+
type InlineSlice = {
|
|
72
|
+
content: readonly ParagraphContent[];
|
|
73
|
+
openStart: number;
|
|
74
|
+
openEnd: number;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Revision and content-control ids an operation gives the records it creates
|
|
78
|
+
* by cutting an identified record in two (see `identity.ts`), each space's
|
|
79
|
+
* taken in document order. The half holding the start keeps the record's id.
|
|
80
|
+
*/
|
|
81
|
+
type NewIds = {
|
|
82
|
+
/** For tracked changes and tracked property changes (`w:id`). */
|
|
83
|
+
revision?: readonly number[];
|
|
84
|
+
/** For content controls (`w:sdtPr/w:id`). */
|
|
85
|
+
control?: readonly number[];
|
|
86
|
+
};
|
|
87
|
+
/** The paragraph fields a split gives the new paragraph, besides its id, content and mark. */
|
|
88
|
+
type SplitParagraphFields = Omit<Paragraph, "type" | "paraId" | "content" | "sectionProperties" | "pPrMark">;
|
|
89
|
+
/** The operation kinds of schema version 1. */
|
|
90
|
+
declare const DOCUMENT_OP_TYPES: Readonly<{
|
|
91
|
+
readonly INSERT_TEXT: "insertText";
|
|
92
|
+
readonly INSERT_CONTENT: "insertContent";
|
|
93
|
+
readonly DELETE_RANGE: "deleteRange";
|
|
94
|
+
readonly SPLIT_INLINE: "splitInline";
|
|
95
|
+
readonly JOIN_INLINE: "joinInline";
|
|
96
|
+
readonly SET_RUN_PROPS: "setRunProps";
|
|
97
|
+
readonly SET_PARAGRAPH_PROPS: "setParagraphProps";
|
|
98
|
+
readonly SPLIT_BLOCK: "splitBlock";
|
|
99
|
+
readonly JOIN_BLOCKS: "joinBlocks";
|
|
100
|
+
readonly REPLACE_BLOCKS: "replaceBlocks";
|
|
101
|
+
}>;
|
|
102
|
+
/** One of {@link DOCUMENT_OP_TYPES}. */
|
|
103
|
+
type DocumentOpType = (typeof DOCUMENT_OP_TYPES)[keyof typeof DOCUMENT_OP_TYPES];
|
|
104
|
+
/**
|
|
105
|
+
* Insert text at a position.
|
|
106
|
+
*
|
|
107
|
+
* `runProps` is either {@link INHERIT_RUN_PROPS} or the exact property set the
|
|
108
|
+
* text carries. When the set differs from the run at the position, the text
|
|
109
|
+
* becomes a run of its own and that run is split around it; `newIds` names
|
|
110
|
+
* the ids of the second half when the run carries some. The run decides where
|
|
111
|
+
* the text goes, so `at.zeroWidthBefore` is not read.
|
|
112
|
+
*/
|
|
113
|
+
type InsertTextOp = {
|
|
114
|
+
type: typeof DOCUMENT_OP_TYPES.INSERT_TEXT;
|
|
115
|
+
at: TextPosition;
|
|
116
|
+
/** Characters only: tabs, breaks and other inline atoms are not text. */
|
|
117
|
+
text: string;
|
|
118
|
+
runProps: InsertedRunProps;
|
|
119
|
+
newIds?: NewIds;
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Insert paragraph content at a position: runs, fields, markers, anything a
|
|
123
|
+
* paragraph holds.
|
|
124
|
+
*
|
|
125
|
+
* The content is cut in at the point, splitting the runs and containers the
|
|
126
|
+
* point falls inside; the slice's open ends then merge with the halves. A
|
|
127
|
+
* slice that would merge two records that were separate is refused.
|
|
128
|
+
* Absent `zeroWidthBefore` puts the point before the first zero-width child
|
|
129
|
+
* at the offset that opens a range, after the others.
|
|
130
|
+
*/
|
|
131
|
+
type InsertContentOp = {
|
|
132
|
+
type: typeof DOCUMENT_OP_TYPES.INSERT_CONTENT;
|
|
133
|
+
at: TextPosition;
|
|
134
|
+
slice: InlineSlice;
|
|
135
|
+
newIds?: NewIds;
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* Remove what lies between two positions of one paragraph: its units and the
|
|
139
|
+
* zero-width children strictly inside. Absent `zeroWidthBefore` keeps the
|
|
140
|
+
* zero-width children at both ends. A run or container left with nothing is
|
|
141
|
+
* removed; one the range passes through keeps its two ends as one record.
|
|
142
|
+
*
|
|
143
|
+
* `join` then merges the records meeting where the range was, that many
|
|
144
|
+
* levels below the ones running across it, as {@link JoinInlineOp} does: the
|
|
145
|
+
* inverse of an insertion that cut records is one deletion.
|
|
146
|
+
*
|
|
147
|
+
* `expected` is the slice the deletion must remove, compared without the
|
|
148
|
+
* fields a relayout recomputes. It is how an inverse refuses to apply to
|
|
149
|
+
* content that has changed since.
|
|
150
|
+
*/
|
|
151
|
+
type DeleteRangeOp = {
|
|
152
|
+
type: typeof DOCUMENT_OP_TYPES.DELETE_RANGE;
|
|
153
|
+
from: TextPosition;
|
|
154
|
+
to: TextPosition;
|
|
155
|
+
join?: number;
|
|
156
|
+
expected?: InlineSlice;
|
|
157
|
+
};
|
|
158
|
+
/**
|
|
159
|
+
* Cut the innermost `depth` records that run across a position in two,
|
|
160
|
+
* leaving the ones around them whole. Absent `zeroWidthBefore` is `0`.
|
|
161
|
+
*/
|
|
162
|
+
type SplitInlineOp = {
|
|
163
|
+
type: typeof DOCUMENT_OP_TYPES.SPLIT_INLINE;
|
|
164
|
+
at: TextPosition;
|
|
165
|
+
depth: number;
|
|
166
|
+
newIds?: NewIds;
|
|
167
|
+
};
|
|
168
|
+
/**
|
|
169
|
+
* Merge the records meeting at a position, `depth` levels below the ones that
|
|
170
|
+
* already run across it. Merged records must be alike in everything but
|
|
171
|
+
* their content and ids; the first's ids stand for both. Absent
|
|
172
|
+
* `zeroWidthBefore` is `0`.
|
|
173
|
+
*/
|
|
174
|
+
type JoinInlineOp = {
|
|
175
|
+
type: typeof DOCUMENT_OP_TYPES.JOIN_INLINE;
|
|
176
|
+
at: TextPosition;
|
|
177
|
+
depth: number;
|
|
178
|
+
};
|
|
179
|
+
/**
|
|
180
|
+
* Patch the run properties of every run between two positions of one
|
|
181
|
+
* paragraph, splitting runs at the range ends. A run the patch does not change
|
|
182
|
+
* is kept whole. Absent `zeroWidthBefore` keeps zero-width children at both
|
|
183
|
+
* ends out of the range.
|
|
184
|
+
*
|
|
185
|
+
* `expected` states the values the patched keys must have on every run in the
|
|
186
|
+
* range (`null` for absent) and refuses the patch as stale otherwise.
|
|
187
|
+
* `joinStart` and `joinEnd` merge the runs meeting at the range ends that many
|
|
188
|
+
* levels once the patch is applied, as {@link JoinInlineOp} does; the inverse
|
|
189
|
+
* of a patch that cut runs uses them.
|
|
190
|
+
*/
|
|
191
|
+
type SetRunPropsOp = {
|
|
192
|
+
type: typeof DOCUMENT_OP_TYPES.SET_RUN_PROPS;
|
|
193
|
+
from: TextPosition;
|
|
194
|
+
to: TextPosition;
|
|
195
|
+
patch: RunPropsPatch;
|
|
196
|
+
whenEmpty?: EmptyPropertySet;
|
|
197
|
+
expected?: RunPropsPatch;
|
|
198
|
+
joinStart?: number;
|
|
199
|
+
joinEnd?: number;
|
|
200
|
+
newIds?: NewIds;
|
|
201
|
+
};
|
|
202
|
+
/**
|
|
203
|
+
* Patch a paragraph's own property set. `expected` states the values the
|
|
204
|
+
* patched keys must have (`null` for absent) and refuses the patch as stale
|
|
205
|
+
* otherwise.
|
|
206
|
+
*/
|
|
207
|
+
type SetParagraphPropsOp = {
|
|
208
|
+
type: typeof DOCUMENT_OP_TYPES.SET_PARAGRAPH_PROPS;
|
|
209
|
+
story: OpStory;
|
|
210
|
+
blockId: string;
|
|
211
|
+
patch: ParagraphPropsPatch;
|
|
212
|
+
whenEmpty?: EmptyPropertySet;
|
|
213
|
+
expected?: ParagraphPropsPatch;
|
|
214
|
+
};
|
|
215
|
+
/**
|
|
216
|
+
* Split a paragraph in two at a position.
|
|
217
|
+
*
|
|
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.
|
|
226
|
+
*
|
|
227
|
+
* 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:
|
|
229
|
+
* `newIds` names its ids, outermost record first.
|
|
230
|
+
*/
|
|
231
|
+
type SplitBlockOp = {
|
|
232
|
+
type: typeof DOCUMENT_OP_TYPES.SPLIT_BLOCK;
|
|
233
|
+
at: TextPosition;
|
|
234
|
+
/** `w14:paraId` of the new paragraph: eight hex digits, unused in the document. */
|
|
235
|
+
newBlockId: string;
|
|
236
|
+
newParagraph?: SplitParagraphFields;
|
|
237
|
+
firstMark?: ParagraphMarkChange;
|
|
238
|
+
newIds?: NewIds;
|
|
239
|
+
};
|
|
240
|
+
/**
|
|
241
|
+
* 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.
|
|
246
|
+
*
|
|
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).
|
|
250
|
+
*/
|
|
251
|
+
type JoinBlocksOp = {
|
|
252
|
+
type: typeof DOCUMENT_OP_TYPES.JOIN_BLOCKS;
|
|
253
|
+
story: OpStory;
|
|
254
|
+
blockId: string;
|
|
255
|
+
nextBlockId: string;
|
|
256
|
+
depth?: number;
|
|
257
|
+
expectedSecond?: SplitParagraphFields;
|
|
258
|
+
};
|
|
259
|
+
/**
|
|
260
|
+
* Replace a run of adjacent paragraphs with other paragraphs.
|
|
261
|
+
*
|
|
262
|
+
* `expected` is the paragraphs as they stand: they are found by `paraId` and
|
|
263
|
+
* compared structurally (without the fields a relayout recomputes), so a
|
|
264
|
+
* replacement authored against another state is refused rather than applied
|
|
265
|
+
* over it. No other operation's inverse is a replacement.
|
|
266
|
+
*/
|
|
267
|
+
type ReplaceBlocksOp = {
|
|
268
|
+
type: typeof DOCUMENT_OP_TYPES.REPLACE_BLOCKS;
|
|
269
|
+
story: OpStory;
|
|
270
|
+
expected: readonly Paragraph[];
|
|
271
|
+
blocks: readonly Paragraph[];
|
|
272
|
+
};
|
|
273
|
+
/** A schema-version-1 document operation. */
|
|
274
|
+
type DocumentOp = InsertTextOp | InsertContentOp | DeleteRangeOp | SplitInlineOp | JoinInlineOp | SetRunPropsOp | SetParagraphPropsOp | SplitBlockOp | JoinBlocksOp | ReplaceBlocksOp;
|
|
275
|
+
/**
|
|
276
|
+
* An operation as it is journaled and sent: the schema that reads it, and the
|
|
277
|
+
* operation. A reader refuses an envelope of a schema it does not know rather
|
|
278
|
+
* than guess what its fields mean.
|
|
279
|
+
*/
|
|
280
|
+
type DocumentOpEnvelope = {
|
|
281
|
+
schema: typeof DOCUMENT_OP_SCHEMA_VERSION;
|
|
282
|
+
op: DocumentOp;
|
|
283
|
+
};
|
|
284
|
+
/** An operation in the envelope it is journaled and sent in. */
|
|
285
|
+
declare const toOpEnvelope: (op: DocumentOp) => DocumentOpEnvelope;
|
|
286
|
+
/** The blocks an operation changed, by id. */
|
|
287
|
+
type TouchedBlocks = {
|
|
288
|
+
modified: readonly string[];
|
|
289
|
+
inserted: readonly string[];
|
|
290
|
+
removed: readonly string[];
|
|
291
|
+
};
|
|
292
|
+
//#endregion
|
|
293
|
+
//#region src/ops/refusal.d.ts
|
|
294
|
+
/**
|
|
295
|
+
* Why an operation was not applied. A refused operation changes nothing: the
|
|
296
|
+
* document it was applied to is returned as it was.
|
|
297
|
+
*/
|
|
298
|
+
declare const DOCUMENT_OP_REFUSAL_REASONS: Readonly<{
|
|
299
|
+
/** No paragraph in the story carries the id. */
|
|
300
|
+
readonly BLOCK_NOT_FOUND: "blockNotFound";
|
|
301
|
+
/** An offset is not an integer from `0` to the paragraph's length, or a range runs backwards. */
|
|
302
|
+
readonly INVALID_OFFSET: "invalidOffset";
|
|
303
|
+
/** A range starts and ends in different paragraphs or stories. */
|
|
304
|
+
readonly CROSS_BLOCK_RANGE: "crossBlockRange";
|
|
305
|
+
/** A position falls between the two halves of a surrogate pair. */
|
|
306
|
+
readonly SPLITS_SURROGATE_PAIR: "splitsSurrogatePair";
|
|
307
|
+
/** Inserted text is empty, holds a tab or line-break character, or cannot be written to XML. */
|
|
308
|
+
readonly INVALID_TEXT: "invalidText";
|
|
309
|
+
/**
|
|
310
|
+
* A paragraph id the operation (or its inverse) creates is not eight hex
|
|
311
|
+
* digits below `0x80000000`, or is the reserved `00000000`.
|
|
312
|
+
*/
|
|
313
|
+
readonly INVALID_BLOCK_ID: "invalidBlockId";
|
|
314
|
+
/**
|
|
315
|
+
* An id the operation brings in (a paragraph id, or a revision or
|
|
316
|
+
* content-control id a replacement carries) is already used in the package.
|
|
317
|
+
*/
|
|
318
|
+
readonly ID_COLLISION: "idCollision";
|
|
319
|
+
/** The paragraphs to join or replace are not adjacent siblings of one container. */
|
|
320
|
+
readonly NOT_ADJACENT: "notAdjacent";
|
|
321
|
+
/**
|
|
322
|
+
* The operation would move or remove a section break (joining a paragraph
|
|
323
|
+
* that ends a section, replacing paragraphs across or at one); that is a
|
|
324
|
+
* section operation.
|
|
325
|
+
*/
|
|
326
|
+
readonly SECTION_BOUNDARY: "sectionBoundary";
|
|
327
|
+
/** Direct text would land inside tracked-deleted or moved-away content. */
|
|
328
|
+
readonly INSIDE_TRACKED_DELETION: "insideTrackedDeletion";
|
|
329
|
+
/**
|
|
330
|
+
* The operation cuts a record carrying a revision or content-control id in
|
|
331
|
+
* two and names too few `newIds` for the halves after the first.
|
|
332
|
+
*/
|
|
333
|
+
readonly NEEDS_NEW_IDS: "needsNewIds";
|
|
334
|
+
/** A new revision or content-control id is not an integer from 0 to 2^31 - 1. */
|
|
335
|
+
readonly INVALID_NEW_ID: "invalidNewId";
|
|
336
|
+
/**
|
|
337
|
+
* The operation would merge two records carrying the same revision or
|
|
338
|
+
* content-control id: nothing could tell them apart again to undo it.
|
|
339
|
+
*/
|
|
340
|
+
readonly SHARED_ID: "sharedId";
|
|
341
|
+
/**
|
|
342
|
+
* What the operation expects (paragraphs to replace, a slice to delete,
|
|
343
|
+
* the values a patch replaced) is not what is there.
|
|
344
|
+
*/
|
|
345
|
+
readonly STALE: "stale";
|
|
346
|
+
/**
|
|
347
|
+
* The records at a position are not the shape the operation needs: an open
|
|
348
|
+
* end meets a record it cannot merge with, records to join differ, a slice
|
|
349
|
+
* would merge records that were separate, or there are fewer records to cut
|
|
350
|
+
* than the operation names.
|
|
351
|
+
*/
|
|
352
|
+
readonly STRUCTURE_MISMATCH: "structureMismatch";
|
|
353
|
+
/** Inserted content is empty, or holds an empty run or text node. */
|
|
354
|
+
readonly EMPTY_CONTENT: "emptyContent";
|
|
355
|
+
/** A replacement names no paragraph to replace, or none to put in its place. */
|
|
356
|
+
readonly EMPTY_BLOCK_LIST: "emptyBlockList";
|
|
357
|
+
/** Seed contract: a main-story paragraph has no `paraId`. */
|
|
358
|
+
readonly MISSING_BLOCK_ID: "missingBlockId";
|
|
359
|
+
/** Seed contract: two paragraphs in the package carry one id. */
|
|
360
|
+
readonly DUPLICATE_BLOCK_ID: "duplicateBlockId";
|
|
361
|
+
/** Seed contract: two records in the package carry one revision or content-control id. */
|
|
362
|
+
readonly DUPLICATE_RECORD_ID: "duplicateRecordId";
|
|
363
|
+
/** Seed contract: the body's section view does not match its blocks. */
|
|
364
|
+
readonly SECTIONS_OUT_OF_STEP: "sectionsOutOfStep";
|
|
365
|
+
/** Seed contract: the main story holds an empty run or empty text node. */
|
|
366
|
+
readonly EMPTY_RECORD: "emptyRecord";
|
|
367
|
+
}>;
|
|
368
|
+
/** One of {@link DOCUMENT_OP_REFUSAL_REASONS}. */
|
|
369
|
+
type DocumentOpRefusalReason = (typeof DOCUMENT_OP_REFUSAL_REASONS)[keyof typeof DOCUMENT_OP_REFUSAL_REASONS];
|
|
370
|
+
declare const DocumentOpRefusal_base: import("better-result").TaggedErrorClass<"DocumentOpRefusal">;
|
|
371
|
+
/** An operation the document cannot take as stated. */
|
|
372
|
+
declare class DocumentOpRefusal extends DocumentOpRefusal_base<{
|
|
373
|
+
message: string;
|
|
374
|
+
reason: DocumentOpRefusalReason;
|
|
375
|
+
opType: DocumentOpType;
|
|
376
|
+
}> {}
|
|
377
|
+
//#endregion
|
|
378
|
+
//#region src/ops/apply.d.ts
|
|
379
|
+
/** A document an operation produced, the operations that undo it, and what it changed. */
|
|
380
|
+
type AppliedDocumentOp = {
|
|
381
|
+
document: Document;
|
|
382
|
+
/** Apply in order to restore the input document. */
|
|
383
|
+
inverse: readonly DocumentOp[];
|
|
384
|
+
touched: TouchedBlocks;
|
|
385
|
+
};
|
|
386
|
+
/** Apply one operation to a document that meets the seed contract. */
|
|
387
|
+
declare const applyDocumentOp: (document: Document, op: DocumentOp) => Result<AppliedDocumentOp, DocumentOpRefusal>;
|
|
388
|
+
/**
|
|
389
|
+
* Apply operations in order, atomically: the first refusal is returned and
|
|
390
|
+
* the document is unchanged. The inverse undoes the whole list.
|
|
391
|
+
*/
|
|
392
|
+
declare const applyDocumentOps: (document: Document, ops: readonly DocumentOp[]) => Result<AppliedDocumentOp, DocumentOpRefusal>;
|
|
393
|
+
//#endregion
|
|
394
|
+
//#region src/ops/contract.d.ts
|
|
395
|
+
declare const DocumentOpsContractError_base: import("better-result").TaggedErrorClass<"DocumentOpsContractError">;
|
|
396
|
+
/** A document that does not meet the seed contract. */
|
|
397
|
+
declare class DocumentOpsContractError extends DocumentOpsContractError_base<{
|
|
398
|
+
message: string;
|
|
399
|
+
reason: DocumentOpRefusalReason;
|
|
400
|
+
}> {}
|
|
401
|
+
/** Check a document against the seed contract. */
|
|
402
|
+
declare const validateOpsDocument: (document: Document) => Result<Document, DocumentOpsContractError>;
|
|
403
|
+
/**
|
|
404
|
+
* The document with every empty run and empty text node of the main story
|
|
405
|
+
* removed, and its section view derived again. Nothing else changes.
|
|
406
|
+
*/
|
|
407
|
+
declare const normalizeForOps: (document: Document) => Document;
|
|
408
|
+
//#endregion
|
|
409
|
+
//#region src/ops/offsets.d.ts
|
|
410
|
+
/** The number of logical units in a paragraph: its largest valid offset. */
|
|
411
|
+
declare const paragraphLength: (paragraph: Paragraph) => number;
|
|
412
|
+
/** The character a unit that is not run text stands for in {@link paragraphLogicalText}. */
|
|
413
|
+
declare const OBJECT_REPLACEMENT_CHARACTER = "";
|
|
414
|
+
/**
|
|
415
|
+
* The paragraph's offset space as a string: run text as it stands and
|
|
416
|
+
* {@link OBJECT_REPLACEMENT_CHARACTER} for every other unit, so index `i` of
|
|
417
|
+
* the string is unit `i` of the paragraph.
|
|
418
|
+
*/
|
|
419
|
+
declare const paragraphLogicalText: (paragraph: Paragraph) => string;
|
|
420
|
+
//#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 };
|