@stll/folio-core 0.75.0 → 0.77.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/dist/ai-edits/headless.d.ts +8 -5
- package/dist/ai-edits/headless.js +49 -26
- package/dist/ai-edits/pending-suggestions.d.ts +9 -0
- package/dist/ai-edits/pending-suggestions.js +13 -3
- package/dist/ai-edits/read.js +33 -4
- package/dist/ai-edits/table-geometry.js +12 -4
- package/dist/ai-edits/types.d.ts +9 -4
- package/dist/canonical/batchCommentReferences.js +2 -1
- package/dist/canonical/canonicalBatchReview.js +5 -8
- package/dist/canonical/canonicalComments.js +8 -2
- package/dist/canonical/canonicalCompilerRefusal.d.ts +2 -4
- package/dist/canonical/canonicalCompilerRefusal.js +20 -14
- package/dist/canonical/canonicalInlineProjection.d.ts +2 -2
- package/dist/canonical/canonicalInlineProjection.js +2 -2
- package/dist/canonical/canonicalProjectionBlocks.d.ts +10 -1
- package/dist/canonical/canonicalPublicOperations.js +214 -107
- package/dist/canonical/canonicalSeedContent.d.ts +18 -3
- package/dist/canonical/canonicalSeedContent.js +28 -15
- package/dist/canonical/canonicalSession.d.ts +22 -12
- package/dist/canonical/canonicalSession.js +181 -187
- package/dist/controller/canonicalClipboard.d.ts +3 -2
- package/dist/controller/canonicalClipboard.js +377 -58
- package/dist/controller/canonicalComposition.js +67 -14
- package/dist/controller/canonicalContentControlValue.js +7 -7
- package/dist/controller/canonicalReview.d.ts +21 -0
- package/dist/controller/canonicalReview.js +44 -9
- package/dist/controller/canonicalStoryEditor.js +2 -0
- package/dist/controller/canonicalStructure.d.ts +1 -2
- package/dist/controller/canonicalStructure.js +51 -24
- package/dist/controller/fontReadiness.js +50 -23
- package/dist/controller/hiddenEditorManager.js +7 -20
- package/dist/docx/bulletMarkers.d.ts +8 -0
- package/dist/docx/bulletMarkers.js +9 -1
- package/dist/docx/canonicalSessionInput.js +25 -11
- package/dist/docx/ensureParaIds.d.ts +31 -0
- package/dist/docx/ensureParaIds.js +57 -32
- package/dist/docx/ensureUniqueControlIds.d.ts +13 -0
- package/dist/docx/ensureUniqueControlIds.js +47 -29
- package/dist/docx/ensureUniqueRevisionIds.d.ts +13 -0
- package/dist/docx/ensureUniqueRevisionIds.js +52 -29
- package/dist/docx/importedIdCollisions.js +29 -4
- package/dist/docx/server/templatePlan/apply.js +108 -9
- package/dist/docx/server/templatePlan/blocks.d.ts +77 -5
- package/dist/docx/server/templatePlan/blocks.js +281 -14
- package/dist/docx/server/templatePlan/builders.d.ts +22 -1
- package/dist/docx/server/templatePlan/builders.js +37 -3
- package/dist/docx/server/templatePlan/effects.d.ts +27 -0
- package/dist/docx/server/templatePlan/effects.js +188 -0
- package/dist/docx/server/templatePlan/emit.d.ts +4 -1
- package/dist/docx/server/templatePlan/emit.js +152 -8
- package/dist/docx/server/templatePlan/inspect.js +21 -1
- package/dist/docx/server/templatePlan/labels.js +16 -1
- package/dist/docx/server/templatePlan/plan.d.ts +35 -3
- package/dist/docx/server/templatePlan/plan.js +197 -20
- package/dist/docx/server/templatePlan/planShape.js +58 -22
- package/dist/docx/server/templatePlan/revisions.d.ts +101 -0
- package/dist/docx/server/templatePlan/revisions.js +681 -0
- package/dist/docx/server/templatePlan/story.d.ts +61 -2
- package/dist/docx/server/templatePlan/story.js +175 -13
- package/dist/docx/server/templatePlan/types.d.ts +313 -1
- package/dist/docx/server/templatePlan/verify.js +175 -12
- package/dist/docx/server/templatePlan/xml.d.ts +3 -0
- package/dist/docx/server/templatePlan/xml.js +4 -1
- package/dist/docx/settingsHeaderFooterUpdate.d.ts +1 -1
- package/dist/docx/tableGridXml.d.ts +3 -7
- package/dist/docx/tableGridXml.js +5 -13
- package/dist/layout-bridge/convert/footnoteLayout.js +34 -8
- package/dist/prosemirror/canonicalMarkupDocument.d.ts +20 -0
- package/dist/prosemirror/canonicalMarkupDocument.js +73 -0
- package/dist/prosemirror/canonicalTableCommands.d.ts +1 -1
- package/dist/prosemirror/canonicalTableCommands.js +1 -3
- package/dist/prosemirror/commands/comments.d.ts +6 -234
- package/dist/prosemirror/commands/comments.js +5 -2464
- package/dist/prosemirror/commands/index.d.ts +4 -2
- package/dist/prosemirror/commands/index.js +4 -2
- package/dist/prosemirror/conversion/markupViewSource.d.ts +17 -0
- package/dist/prosemirror/conversion/markupViewSource.js +11 -0
- package/dist/prosemirror/conversion/toProseDoc.d.ts +3 -0
- package/dist/prosemirror/conversion/toProseDoc.js +31 -14
- package/dist/prosemirror/extensions/marks/HyperlinkExtension.js +6 -8
- package/dist/prosemirror/hyperlinkRemoval.d.ts +11 -8
- package/dist/prosemirror/hyperlinkRemoval.js +24 -15
- package/dist/prosemirror/independentMarkupProjection.d.ts +27 -0
- package/dist/prosemirror/independentMarkupProjection.js +147 -0
- package/dist/prosemirror/markupViewNotes.d.ts +1 -1
- package/dist/prosemirror/markupViewNotes.js +24 -27
- package/dist/prosemirror/markupViewPositionMap.d.ts +16 -0
- package/dist/prosemirror/markupViewPositionMap.js +316 -0
- package/dist/prosemirror/markupViewProjection.d.ts +3 -46
- package/dist/prosemirror/markupViewProjection.js +90 -17
- package/dist/prosemirror/paraIds.d.ts +1 -14
- package/dist/prosemirror/paraIds.js +1 -14
- package/dist/prosemirror/paragraphMarkJoin.d.ts +0 -16
- package/dist/prosemirror/paragraphMarkJoin.js +3 -46
- package/dist/prosemirror/projectionReview.d.ts +49 -0
- package/dist/prosemirror/projectionReview.js +292 -0
- package/dist/prosemirror/rebaseParagraphRunFormatting.d.ts +1 -13
- package/dist/prosemirror/rebaseParagraphRunFormatting.js +1 -16
- package/dist/prosemirror/replacedAnnotations.d.ts +6 -83
- package/dist/prosemirror/replacedAnnotations.js +11 -203
- package/dist/prosemirror/revisionCarriers.d.ts +9 -1
- package/dist/prosemirror/revisionCarriers.js +15 -1
- package/dist/prosemirror/revisionRangeQueries.d.ts +32 -0
- package/dist/prosemirror/revisionRangeQueries.js +76 -0
- package/dist/prosemirror/runFormattingMarkNames.d.ts +1 -1
- package/dist/prosemirror/runFormattingMarkNames.js +1 -1
- package/dist/prosemirror/styles/styleResolver.d.ts +1 -0
- package/dist/prosemirror/styles/styleResolver.js +4 -1
- package/dist/prosemirror/suggestionQueries.d.ts +114 -0
- package/dist/prosemirror/suggestionQueries.js +320 -0
- package/dist/prosemirror/tableGridMutation.d.ts +1 -16
- package/dist/prosemirror/tableGridMutation.js +1 -78
- package/dist/prosemirror/tableRowRevisionOwnership.d.ts +18 -0
- package/dist/prosemirror/tableRowRevisionOwnership.js +7 -0
- package/dist/prosemirror/utils/extractTrackedChanges.js +14 -4
- package/dist/server.d.ts +2 -2
- package/dist/types/canonicalCapabilities.d.ts +4 -35
- package/dist/types/canonicalCapabilities.js +4 -33
- package/package.json +2 -2
- package/dist/internal/headlessRevisionResolutionGuard.d.ts +0 -3
- package/dist/internal/headlessRevisionResolutionGuard.js +0 -18
- package/dist/internal/revisionResolutionEdits.d.ts +0 -11
- package/dist/internal/revisionResolutionEdits.js +0 -18
- package/dist/internal/revisionResolutionInline.d.ts +0 -24
- package/dist/internal/revisionResolutionInline.js +0 -302
- package/dist/internal/revisionResolutionStep.d.ts +0 -32
- package/dist/internal/revisionResolutionStep.js +0 -282
- package/dist/internal/revisionResolutionTracking.d.ts +0 -9
- package/dist/internal/revisionResolutionTracking.js +0 -124
- package/dist/internal/wholeStoryRevisionResolution.d.ts +0 -56
- package/dist/internal/wholeStoryRevisionResolution.js +0 -783
- package/dist/prosemirror/commands/resolveAllTableChanges.d.ts +0 -38
- package/dist/prosemirror/commands/resolveAllTableChanges.js +0 -642
- package/dist/prosemirror/commands/resolveNodePropertyChangeAttrs.d.ts +0 -13
- package/dist/prosemirror/commands/resolveNodePropertyChangeAttrs.js +0 -45
- package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +0 -18
- package/dist/prosemirror/commands/tableCellMergeResolution.js +0 -207
- package/dist/prosemirror/commands/tableMergeFoldDecisions.d.ts +0 -60
- package/dist/prosemirror/commands/tableMergeFoldDecisions.js +0 -78
- package/dist/prosemirror/rejoinRunCarriers.d.ts +0 -42
- package/dist/prosemirror/rejoinRunCarriers.js +0 -65
- package/dist/prosemirror/runPropertyChangeResolution.d.ts +0 -15
- package/dist/prosemirror/runPropertyChangeResolution.js +0 -34
|
@@ -5,8 +5,9 @@ import { bookmarkIdsOf, mintRefBookmarkName, refFieldInstruction } from "./build
|
|
|
5
5
|
import { emphasisDeviation, emphasisSignature, paragraphBaseline, readDirectEmphasis, withCharacterStyle, withOverride, withSignatureHighlight } from "./emphasis.js";
|
|
6
6
|
import { styleNumbering } from "./labels.js";
|
|
7
7
|
import { PLAN_HIGHLIGHT_COLORS, planShapeIssue } from "./planShape.js";
|
|
8
|
+
import "./revisions.js";
|
|
8
9
|
import { TemplatePlanError } from "./types.js";
|
|
9
|
-
import { isW, maxOf, wAttr, wChild, wChildVal, walkElements } from "./xml.js";
|
|
10
|
+
import { elementChildren, isW, maxOf, wAttr, wChild, wChildVal, wName, walkElements } from "./xml.js";
|
|
10
11
|
import { Result } from "better-result";
|
|
11
12
|
// src/docx/server/templatePlan/plan.ts
|
|
12
13
|
/**
|
|
@@ -15,6 +16,77 @@ import { Result } from "better-result";
|
|
|
15
16
|
* emphasis, derived from the source blocks alone. The writer emits it and the
|
|
16
17
|
* verifier compares the written package against it.
|
|
17
18
|
*/
|
|
19
|
+
const fieldCharOf = (run) => wName(run) === "r" ? wAttr(wChild(run, "fldChar"), "fldCharType") : null;
|
|
20
|
+
/**
|
|
21
|
+
* The run of a paragraph that holds the separator of the field the
|
|
22
|
+
* paragraph begins and leaves open: what follows it is the start of a result
|
|
23
|
+
* that goes on in later paragraphs. A field the paragraph both begins and
|
|
24
|
+
* ends (a page number in front of a table of contents) is not that field.
|
|
25
|
+
* Null when no one field is left open with its result begun, in runs of the
|
|
26
|
+
* paragraph itself.
|
|
27
|
+
*/
|
|
28
|
+
const fieldSeparatorRun = (paragraph) => {
|
|
29
|
+
const open = [];
|
|
30
|
+
for (const child of elementChildren(paragraph)) {
|
|
31
|
+
const mark = fieldCharOf(child);
|
|
32
|
+
if (mark === "begin") open.push({ separator: null });
|
|
33
|
+
else if (mark === "end") open.pop();
|
|
34
|
+
else if (mark === "separate") {
|
|
35
|
+
const top = open.at(-1);
|
|
36
|
+
if (top !== void 0 && top.separator === null) top.separator = child;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const [left, ...others] = open;
|
|
40
|
+
return left === void 0 || others.length > 0 ? null : left.separator;
|
|
41
|
+
};
|
|
42
|
+
const holdsText = (element) => {
|
|
43
|
+
let text = false;
|
|
44
|
+
walkElements(element, (inner) => {
|
|
45
|
+
text ||= wName(inner) === "t";
|
|
46
|
+
});
|
|
47
|
+
return text;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Whether a paragraph ends the field left open in front of it and holds no
|
|
51
|
+
* more behind that end: the end of the field's result and nothing else. The
|
|
52
|
+
* end is the field's own, the first one that closes no field the paragraph
|
|
53
|
+
* began; text behind it stays, whatever field follows that text.
|
|
54
|
+
*/
|
|
55
|
+
const endsOpenField = (paragraph) => {
|
|
56
|
+
const children = elementChildren(paragraph);
|
|
57
|
+
let depth = 0;
|
|
58
|
+
for (const [position, child] of children.entries()) {
|
|
59
|
+
const mark = fieldCharOf(child);
|
|
60
|
+
if (mark === "begin") depth += 1;
|
|
61
|
+
else if (mark === "end") {
|
|
62
|
+
if (depth === 0) return !children.slice(position + 1).some(holdsText);
|
|
63
|
+
depth -= 1;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return false;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* The kept tables of contents that show entries over several paragraphs:
|
|
70
|
+
* the paragraph each begins in, the length of the text that paragraph holds
|
|
71
|
+
* in front of the field's result, and the further paragraphs of its
|
|
72
|
+
* entries. A field that does not begin in runs of its own paragraph, that
|
|
73
|
+
* ends in a paragraph with text behind it, or whose paragraphs are not all
|
|
74
|
+
* kept top-level blocks, is not among them and stays as the template has it.
|
|
75
|
+
*/
|
|
76
|
+
const contentsWithEntries = (template, keptIds) => {
|
|
77
|
+
const found = [];
|
|
78
|
+
for (const field of template.story.state.fields) {
|
|
79
|
+
if (field.kind !== "TOC" || !field.closed || field.nestedInCode || field.endParagraphOrdinal <= field.paragraphOrdinal) continue;
|
|
80
|
+
const [first, ...rest] = template.story.paragraphs.slice(field.paragraphOrdinal, field.endParagraphOrdinal + 1);
|
|
81
|
+
const last = rest.at(-1);
|
|
82
|
+
if (first !== void 0 && last !== void 0 && [first, ...rest].every(({ block, parentId }) => parentId === null && keptIds.has(block.id)) && field.resultStart >= 0 && fieldSeparatorRun(first.element) !== null && endsOpenField(last.element)) found.push({
|
|
83
|
+
first,
|
|
84
|
+
textKept: field.resultStart,
|
|
85
|
+
rest
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return found;
|
|
89
|
+
};
|
|
18
90
|
const refuse = ({ code, message, blockId }) => new TemplatePlanError({
|
|
19
91
|
code,
|
|
20
92
|
message,
|
|
@@ -27,16 +99,19 @@ const ROMAN_NUMERAL = /^(?=.)M{0,3}(?:CM|CD|D?C{0,3})(?:XC|XL|L?X{0,3})(?:IX|IV|
|
|
|
27
99
|
const LABEL_WORD = /^(?:\p{L}[\p{L}\p{M}]*\.?|§{1,2}|№|#)$/u;
|
|
28
100
|
const LABEL_DESIGNATOR = /^[([]?(?<core>\d+(?:[.\-\u2013]\d+)*[a-z]?|\p{L}+)[)\]]?[.:)]*$/u;
|
|
29
101
|
const LABEL_BULLET = /^[-\u2013\u2014\u2022\u00B7\u25AA\u25E6*]$/u;
|
|
102
|
+
/** A number of several parts typed with blanks between them: `1. 1.`. */
|
|
103
|
+
const LABEL_SPACED_NUMBER = /^\d{1,3}\.(?:[ \u00A0]+\d{1,3}\.){1,3}$/u;
|
|
30
104
|
const MAX_LABEL_WORDS = 3;
|
|
31
105
|
/**
|
|
32
106
|
* Whether `label` reads as a manual list label: up to three leading words
|
|
33
107
|
* ("Article", "§", "Annex No.") and one designator, a number, a roman numeral
|
|
34
|
-
* or a letter with its brackets and punctuation; or a single bullet
|
|
35
|
-
*
|
|
108
|
+
* or a letter with its brackets and punctuation; or a single bullet; or a
|
|
109
|
+
* number whose parts stand apart (`1. 1.` for `1.1.`). This is the only text
|
|
110
|
+
* a plan may have removed.
|
|
36
111
|
*/
|
|
37
112
|
const isManualLabel = (label) => {
|
|
38
113
|
if (label === "" || label.length > MAX_LABEL_LENGTH) return false;
|
|
39
|
-
if (LABEL_BULLET.test(label)) return true;
|
|
114
|
+
if (LABEL_BULLET.test(label) || LABEL_SPACED_NUMBER.test(label)) return true;
|
|
40
115
|
const tokens = label.split(/[ \u00A0]/u);
|
|
41
116
|
const designator = tokens.at(-1) ?? "";
|
|
42
117
|
const words = tokens.slice(0, -1);
|
|
@@ -48,6 +123,8 @@ const NOTES_OF_REFERENCE = {
|
|
|
48
123
|
endnoteReference: "endnotes"
|
|
49
124
|
};
|
|
50
125
|
const LABEL_SPACE = /^[ \t ]+/u;
|
|
126
|
+
/** The blank behind a label when a line break behind it goes too. */
|
|
127
|
+
const LABEL_SPACE_AND_BREAK = /^[ \t ]*(?:\n[ \t ]*)?/u;
|
|
51
128
|
const LEADING_SPACE = /^[ \t ]*/u;
|
|
52
129
|
/** Whether a block holds no text and no object. */
|
|
53
130
|
const isBlankBlock = ({ block }) => block.text.trim() === "" && block.inlineObjects === 0;
|
|
@@ -69,6 +146,8 @@ const hyperlinkFieldLink = ({ instruction, kind }) => {
|
|
|
69
146
|
const NOTE_REFERENCE_KINDS = /* @__PURE__ */ new Set(["footnoteReference", "endnoteReference"]);
|
|
70
147
|
/** What a stripped label may consist of. */
|
|
71
148
|
const STRIPPABLE_KINDS = /* @__PURE__ */ new Set(["text", "tab"]);
|
|
149
|
+
/** The same when a line break behind the label goes with it. */
|
|
150
|
+
const STRIPPABLE_WITH_BREAK = /* @__PURE__ */ new Set([...STRIPPABLE_KINDS, "lineBreak"]);
|
|
72
151
|
/**
|
|
73
152
|
* Character styles that only give a link its look. The template supplies
|
|
74
153
|
* that look; any other character style inside a link is emphasis.
|
|
@@ -157,7 +236,8 @@ const spansOverlap = (spans) => {
|
|
|
157
236
|
return previous !== void 0 && span.start < previous.end;
|
|
158
237
|
});
|
|
159
238
|
};
|
|
160
|
-
const partSegments = ({ block, pieces, strippedLength, references, highlights }) => {
|
|
239
|
+
const partSegments = ({ block, pieces, strippedLength, strippedBreak, references, highlights }) => {
|
|
240
|
+
const strippable = strippedBreak ? STRIPPABLE_WITH_BREAK : STRIPPABLE_KINDS;
|
|
161
241
|
const blockId = block.block.id;
|
|
162
242
|
const length = block.block.text.length;
|
|
163
243
|
const badReference = (message) => Result.err(refuse({
|
|
@@ -188,11 +268,21 @@ const partSegments = ({ block, pieces, strippedLength, references, highlights })
|
|
|
188
268
|
}));
|
|
189
269
|
for (const { start, end } of references) if (!boundaries.has(start) || !boundaries.has(end)) return badReference(`Reference span ${start}-${end} in block ${blockId} cuts a character or mark.`);
|
|
190
270
|
for (const { start, end } of highlights) if (!boundaries.has(start) || !boundaries.has(end)) return badHighlight(`Highlight ${start}-${end} in block ${blockId} cuts a character or mark.`);
|
|
271
|
+
for (const { piece, start, end } of split) {
|
|
272
|
+
if (piece.atom?.revision === void 0) continue;
|
|
273
|
+
if (strippedLength > 0 && start < strippedLength) return Result.err(refuse({
|
|
274
|
+
code: "strip-label-mismatch",
|
|
275
|
+
message: `The label to strip from block ${blockId} holds a tracked change.`,
|
|
276
|
+
blockId
|
|
277
|
+
}));
|
|
278
|
+
const cited = references.find((reference) => start <= reference.end && end >= reference.start);
|
|
279
|
+
if (cited !== void 0) return badReference(`Reference span ${cited.start}-${cited.end} in block ${blockId} holds a tracked change.`);
|
|
280
|
+
}
|
|
191
281
|
const positioned = [];
|
|
192
282
|
for (const entry of split) {
|
|
193
283
|
const empty = entry.start === entry.end;
|
|
194
284
|
if (entry.end <= strippedLength && !empty) {
|
|
195
|
-
if (!
|
|
285
|
+
if (!strippable.has(entry.piece.kind)) return Result.err(refuse({
|
|
196
286
|
code: "strip-label-mismatch",
|
|
197
287
|
message: `The label to strip from block ${blockId} covers more than text.`,
|
|
198
288
|
blockId
|
|
@@ -360,7 +450,7 @@ const resolvePlan = (source, template, plan) => {
|
|
|
360
450
|
message: "The plan was made for another template."
|
|
361
451
|
}));
|
|
362
452
|
for (const [name, analyzed] of [["source", source], ["template", template]]) if (analyzed.document.root.namespaceUri !== TRANSITIONAL_WORDPROCESSINGML) return unsupported(`The ${name} is not a Transitional WordprocessingML package.`);
|
|
363
|
-
if (source.manifest.trackedChanges > 0) return Result.err(refuse({
|
|
453
|
+
if (source.manifest.trackedChanges > 0 && source.manifest.trackedChangesKept === void 0) return Result.err(refuse({
|
|
364
454
|
code: "tracked-changes",
|
|
365
455
|
message: `The source holds ${source.manifest.trackedChanges} tracked change(s); resolve them first.`
|
|
366
456
|
}));
|
|
@@ -461,7 +551,7 @@ const resolvePlan = (source, template, plan) => {
|
|
|
461
551
|
placed.add(id);
|
|
462
552
|
return Result.ok(void 0);
|
|
463
553
|
};
|
|
464
|
-
const resolveParagraph = ({ parts, separators, styleId, numbering, placement, ordinal, pageBreakBefore = false, endsSection }) => {
|
|
554
|
+
const resolveParagraph = ({ parts, separators, styleId, numbering, placement, ordinal, pageBreakBefore = false, keepNext = false, indent, tabStops, alignment, spacing, endsSection }) => {
|
|
465
555
|
const first = parts.at(0);
|
|
466
556
|
if (first === void 0) return invalid("A plan item names no source block.");
|
|
467
557
|
const firstId = first.block.block.id;
|
|
@@ -477,9 +567,16 @@ const resolvePlan = (source, template, plan) => {
|
|
|
477
567
|
const segments = [];
|
|
478
568
|
const resolvedParts = [];
|
|
479
569
|
for (const [index, planned] of parts.entries()) {
|
|
480
|
-
const { block, stripLabel } = planned;
|
|
570
|
+
const { block, stripLabel, stripLabelBreak } = planned;
|
|
481
571
|
const { id, text } = block.block;
|
|
482
572
|
if (block.read === null) return invalid(`Block ${id} is a table and cannot be joined or slotted.`);
|
|
573
|
+
const endsInInsertedMark = block.read.atoms.some(({ revision }) => revision?.mark === true);
|
|
574
|
+
const holdsDeletedMark = block.read.atoms.some(({ revision }) => revision?.deleted === "");
|
|
575
|
+
if (endsInInsertedMark && index < parts.length - 1 || placement === "slot" && (endsInInsertedMark || holdsDeletedMark)) return Result.err(refuse({
|
|
576
|
+
code: "merge-invalid",
|
|
577
|
+
message: placement === "slot" ? `Block ${id} holds a tracked paragraph mark and cannot fill a paragraph of the template.` : `Block ${id} ends in a tracked paragraph mark and cannot join the next block.`,
|
|
578
|
+
blockId: id
|
|
579
|
+
}));
|
|
483
580
|
const placedOnce = place(block);
|
|
484
581
|
if (Result.isError(placedOnce)) return placedOnce;
|
|
485
582
|
const unread = block.read.unsupported.at(0);
|
|
@@ -493,7 +590,23 @@ const resolvePlan = (source, template, plan) => {
|
|
|
493
590
|
message: `Block ${id} does not start with the label to strip.`,
|
|
494
591
|
blockId: id
|
|
495
592
|
}));
|
|
496
|
-
|
|
593
|
+
const blank = stripLabelBreak === true ? LABEL_SPACE_AND_BREAK : LABEL_SPACE;
|
|
594
|
+
strippedPrefix = text.slice(0, labelEnd + (blank.exec(text.slice(labelEnd))?.[0].length ?? 0));
|
|
595
|
+
}
|
|
596
|
+
let droppedLead = null;
|
|
597
|
+
if (planned.dropLead !== void 0) {
|
|
598
|
+
const lead = LEADING_SPACE.exec(text)?.[0] ?? "";
|
|
599
|
+
const leadEnd = lead.length + planned.dropLead.text.length;
|
|
600
|
+
const dropped = text.slice(0, leadEnd + (LABEL_SPACE.exec(text.slice(leadEnd))?.[0].length ?? 0));
|
|
601
|
+
if (planned.dropLead.text.trim() === "" || !text.startsWith(planned.dropLead.text, lead.length) || text.slice(dropped.length).trim() === "") return Result.err(refuse({
|
|
602
|
+
code: "strip-label-mismatch",
|
|
603
|
+
message: `Block ${id} does not start with the lead to drop, or holds nothing behind it.`,
|
|
604
|
+
blockId: id
|
|
605
|
+
}));
|
|
606
|
+
droppedLead = {
|
|
607
|
+
text: dropped,
|
|
608
|
+
shownByTemplateBlockId: planned.dropLead.shownByTemplateBlockId
|
|
609
|
+
};
|
|
497
610
|
}
|
|
498
611
|
const part = partSegments({
|
|
499
612
|
block,
|
|
@@ -503,7 +616,8 @@ const resolvePlan = (source, template, plan) => {
|
|
|
503
616
|
origin: "document",
|
|
504
617
|
fields: source.story.state.fields
|
|
505
618
|
}),
|
|
506
|
-
strippedLength: strippedPrefix.length,
|
|
619
|
+
strippedLength: droppedLead === null ? strippedPrefix.length : droppedLead.text.length,
|
|
620
|
+
strippedBreak: stripLabelBreak === true,
|
|
507
621
|
references: referencesByBlock.get(id) ?? [],
|
|
508
622
|
highlights: highlightsByBlock.get(id) ?? []
|
|
509
623
|
});
|
|
@@ -532,6 +646,7 @@ const resolvePlan = (source, template, plan) => {
|
|
|
532
646
|
resolvedParts.push({
|
|
533
647
|
block,
|
|
534
648
|
strippedPrefix,
|
|
649
|
+
droppedLead,
|
|
535
650
|
labelAsText: written?.label ?? null
|
|
536
651
|
});
|
|
537
652
|
}
|
|
@@ -554,6 +669,11 @@ const resolvePlan = (source, template, plan) => {
|
|
|
554
669
|
inlineObjects: pieces.filter(({ kind }) => kind === "object").length,
|
|
555
670
|
placement,
|
|
556
671
|
pageBreakBefore,
|
|
672
|
+
keepNext,
|
|
673
|
+
indent: indent ?? null,
|
|
674
|
+
tabStops: tabStops ?? null,
|
|
675
|
+
alignment: alignment ?? null,
|
|
676
|
+
spacing: spacing ?? null,
|
|
557
677
|
endsSection: endsSection ?? null
|
|
558
678
|
};
|
|
559
679
|
for (const { block } of resolvedParts) byBlockId.set(block.block.id, paragraph);
|
|
@@ -570,7 +690,7 @@ const resolvePlan = (source, template, plan) => {
|
|
|
570
690
|
};
|
|
571
691
|
const resolveTable = (block, item, tableOrdinal) => {
|
|
572
692
|
const { id } = block.block;
|
|
573
|
-
if (item.mergeNext !== void 0 || item.stripLabel !== void 0 || item.labelAsText !== void 0 || item.pageBreakBefore !== void 0 || item.endsSection !== void 0 || item.numbering !== void 0) return invalid(`Table ${id} takes a style and nested placements only.`);
|
|
693
|
+
if (item.mergeNext !== void 0 || item.stripLabel !== void 0 || item.stripLabelBreak !== void 0 || item.labelAsText !== void 0 || item.pageBreakBefore !== void 0 || item.keepNext !== void 0 || item.indent !== void 0 || item.tabStops !== void 0 || item.alignment !== void 0 || item.spacing !== void 0 || item.endsSection !== void 0 || item.numbering !== void 0) return invalid(`Table ${id} takes a style and nested placements only.`);
|
|
574
694
|
if (item.styleId !== void 0 && template.styles.get(item.styleId)?.type !== "table") return Result.err(refuse({
|
|
575
695
|
code: "style-unknown",
|
|
576
696
|
message: `The template has no table style ${item.styleId}.`,
|
|
@@ -599,7 +719,12 @@ const resolvePlan = (source, template, plan) => {
|
|
|
599
719
|
styleId: override?.styleId ?? item.cellStyleId,
|
|
600
720
|
numbering: override?.numbering,
|
|
601
721
|
placement: "nested",
|
|
602
|
-
ordinal: tableOrdinal * 1e6 + nested.block.index
|
|
722
|
+
ordinal: tableOrdinal * 1e6 + nested.block.index,
|
|
723
|
+
keepNext: override?.keepNext === true,
|
|
724
|
+
indent: override?.indent,
|
|
725
|
+
tabStops: override?.tabStops,
|
|
726
|
+
alignment: override?.alignment,
|
|
727
|
+
spacing: override?.spacing
|
|
603
728
|
});
|
|
604
729
|
if (Result.isError(paragraph)) return paragraph;
|
|
605
730
|
cells.set(nested.element, paragraph.value);
|
|
@@ -623,6 +748,8 @@ const resolvePlan = (source, template, plan) => {
|
|
|
623
748
|
const keptTemplateIds = /* @__PURE__ */ new Set();
|
|
624
749
|
const slottedTemplateIds = /* @__PURE__ */ new Set();
|
|
625
750
|
const pendingNestedSlots = [];
|
|
751
|
+
/** The template paragraphs slots name as showing a dropped lead's field. */
|
|
752
|
+
const leadShowers = [];
|
|
626
753
|
let ordinal = 0;
|
|
627
754
|
for (let index = 0; index < plan.body.length; index += 1) {
|
|
628
755
|
const item = plan.body[index];
|
|
@@ -667,6 +794,7 @@ const resolvePlan = (source, template, plan) => {
|
|
|
667
794
|
const parts = [{
|
|
668
795
|
block: block.value,
|
|
669
796
|
stripLabel: item.stripLabel,
|
|
797
|
+
stripLabelBreak: item.stripLabelBreak === true,
|
|
670
798
|
labelAsText: item.labelAsText === true
|
|
671
799
|
}];
|
|
672
800
|
const separators = [];
|
|
@@ -684,15 +812,16 @@ const resolvePlan = (source, template, plan) => {
|
|
|
684
812
|
message: `Block ${next.blockId} does not have the hash the plan pins.`,
|
|
685
813
|
blockId: next.blockId
|
|
686
814
|
}));
|
|
687
|
-
if (next.styleId !== void 0 || next.numbering !== void 0 || next.cellStyleId !== void 0 || next.nested !== void 0 || next.pageBreakBefore !== void 0 || next.endsSection !== void 0) return Result.err(refuse({
|
|
815
|
+
if (next.styleId !== void 0 || next.numbering !== void 0 || next.cellStyleId !== void 0 || next.nested !== void 0 || next.pageBreakBefore !== void 0 || next.keepNext !== void 0 || next.indent !== void 0 || next.tabStops !== void 0 || next.alignment !== void 0 || next.spacing !== void 0 || next.endsSection !== void 0) return Result.err(refuse({
|
|
688
816
|
code: "merge-invalid",
|
|
689
|
-
message: `Block ${next.blockId} joins the paragraph before it and cannot carry a style, a list, a page start or a section end of its own.`,
|
|
817
|
+
message: `Block ${next.blockId} joins the paragraph before it and cannot carry a style, a list, a page start, a format or a section end of its own.`,
|
|
690
818
|
blockId: next.blockId
|
|
691
819
|
}));
|
|
692
820
|
separators.push(merge);
|
|
693
821
|
parts.push({
|
|
694
822
|
block: nextBlock.value,
|
|
695
823
|
stripLabel: next.stripLabel,
|
|
824
|
+
stripLabelBreak: next.stripLabelBreak === true,
|
|
696
825
|
labelAsText: next.labelAsText === true
|
|
697
826
|
});
|
|
698
827
|
merge = next.mergeNext;
|
|
@@ -706,6 +835,11 @@ const resolvePlan = (source, template, plan) => {
|
|
|
706
835
|
placement: "body",
|
|
707
836
|
ordinal,
|
|
708
837
|
pageBreakBefore: item.pageBreakBefore === true,
|
|
838
|
+
keepNext: item.keepNext === true,
|
|
839
|
+
indent: item.indent,
|
|
840
|
+
tabStops: item.tabStops,
|
|
841
|
+
alignment: item.alignment,
|
|
842
|
+
spacing: item.spacing,
|
|
709
843
|
endsSection: item.endsSection
|
|
710
844
|
});
|
|
711
845
|
if (Result.isError(paragraph)) return paragraph;
|
|
@@ -728,16 +862,22 @@ const resolvePlan = (source, template, plan) => {
|
|
|
728
862
|
blockId: item.templateBlockId
|
|
729
863
|
}));
|
|
730
864
|
slottedTemplateIds.add(item.templateBlockId);
|
|
865
|
+
if (item.dropLead !== void 0 && (typeof item.dropLead.text !== "string" || typeof item.dropLead.shownByTemplateBlockId !== "string")) return invalid(`Slot ${item.templateBlockId} names a lead to drop without its text or the paragraph that shows it.`);
|
|
731
866
|
const parts = [];
|
|
732
|
-
for (const id of item.sourceBlockIds) {
|
|
867
|
+
for (const [position, id] of item.sourceBlockIds.entries()) {
|
|
733
868
|
const block = sourceTopLevel(id);
|
|
734
869
|
if (Result.isError(block)) return block;
|
|
735
870
|
parts.push({
|
|
736
871
|
block: block.value,
|
|
737
872
|
stripLabel: void 0,
|
|
738
|
-
labelAsText: false
|
|
873
|
+
labelAsText: false,
|
|
874
|
+
...position === 0 && item.dropLead !== void 0 ? { dropLead: item.dropLead } : {}
|
|
739
875
|
});
|
|
740
876
|
}
|
|
877
|
+
if (item.dropLead !== void 0) leadShowers.push({
|
|
878
|
+
templateBlockId: item.dropLead.shownByTemplateBlockId,
|
|
879
|
+
slotId: item.templateBlockId
|
|
880
|
+
});
|
|
741
881
|
const paragraph = resolveParagraph({
|
|
742
882
|
parts,
|
|
743
883
|
separators: parts.slice(1).map(() => "lineBreak"),
|
|
@@ -769,12 +909,34 @@ const resolvePlan = (source, template, plan) => {
|
|
|
769
909
|
}));
|
|
770
910
|
nestedSlots.push(slot);
|
|
771
911
|
}
|
|
912
|
+
const emptied = [];
|
|
913
|
+
for (const id of plan.emptyTemplateBlockIds ?? []) {
|
|
914
|
+
const block = template.story.byId.get(id);
|
|
915
|
+
if (block === void 0 || block.read === null || block.parentId === null || !keptTemplateIds.has(block.topLevelId) || slottedTemplateIds.has(id) || emptied.includes(block)) return Result.err(refuse({
|
|
916
|
+
code: "unknown-block",
|
|
917
|
+
message: `Template block ${id} is no paragraph of a kept template table that the plan may empty once.`,
|
|
918
|
+
blockId: id
|
|
919
|
+
}));
|
|
920
|
+
emptied.push(block);
|
|
921
|
+
}
|
|
922
|
+
for (const { templateBlockId, slotId } of leadShowers) {
|
|
923
|
+
const shower = template.story.byId.get(templateBlockId);
|
|
924
|
+
if (shower === void 0 || shower.read === null || shower.block.text.trim() === "" || !keptTemplateIds.has(shower.topLevelId) || slottedTemplateIds.has(templateBlockId) || emptied.includes(shower)) return Result.err(refuse({
|
|
925
|
+
code: "unknown-block",
|
|
926
|
+
message: `Template block ${templateBlockId} is no kept paragraph with text that could show the field of slot ${slotId}.`,
|
|
927
|
+
blockId: templateBlockId
|
|
928
|
+
}));
|
|
929
|
+
}
|
|
772
930
|
partTables(items);
|
|
773
931
|
if ((plan.lastSection !== void 0 || items.some((item) => item.kind === "paragraph" && item.paragraph.endsSection !== null)) && wChild(template.body, "sectPr") === null) return invalid("The template has no last section to build the plan's sections from.");
|
|
774
932
|
const keptPosition = /* @__PURE__ */ new Map();
|
|
775
933
|
for (const [position, item] of items.entries()) if (item.kind === "template") keptPosition.set(item.block.block.id, position);
|
|
776
934
|
const templateOrder = template.story.topLevel.map(({ block }) => block.id);
|
|
777
|
-
const slots = [
|
|
935
|
+
const slots = [
|
|
936
|
+
...nestedSlots,
|
|
937
|
+
...items.flatMap((item) => item.kind === "slot" ? [item] : []),
|
|
938
|
+
...emptied.map((templateBlock) => ({ templateBlock }))
|
|
939
|
+
];
|
|
778
940
|
for (const field of template.story.state.fields) {
|
|
779
941
|
const lastOrdinal = field.closed ? field.endParagraphOrdinal : Number.POSITIVE_INFINITY;
|
|
780
942
|
if (lastOrdinal === field.paragraphOrdinal) continue;
|
|
@@ -799,6 +961,19 @@ const resolvePlan = (source, template, plan) => {
|
|
|
799
961
|
blockId: span.at(0) ?? ""
|
|
800
962
|
}));
|
|
801
963
|
}
|
|
964
|
+
const emptiedContents = /* @__PURE__ */ new Map();
|
|
965
|
+
for (const { first, textKept, rest } of freezeKinds.includes("TOC") ? [] : contentsWithEntries(template, keptTemplateIds)) {
|
|
966
|
+
emptiedContents.set(first, textKept);
|
|
967
|
+
const gone = new Set(rest);
|
|
968
|
+
for (let position = items.length - 1; position >= 0; position -= 1) {
|
|
969
|
+
const item = items[position];
|
|
970
|
+
if (item?.kind === "template" && gone.has(item.block)) items.splice(position, 1);
|
|
971
|
+
}
|
|
972
|
+
for (let position = keptTemplateBlocks.length - 1; position >= 0; position -= 1) {
|
|
973
|
+
const block = keptTemplateBlocks[position];
|
|
974
|
+
if (block !== void 0 && gone.has(block)) keptTemplateBlocks.splice(position, 1);
|
|
975
|
+
}
|
|
976
|
+
}
|
|
802
977
|
const omitted = /* @__PURE__ */ new Map();
|
|
803
978
|
for (const entry of plan.omit) {
|
|
804
979
|
const block = sourceTopLevel(entry.blockId);
|
|
@@ -878,13 +1053,15 @@ const resolvePlan = (source, template, plan) => {
|
|
|
878
1053
|
return Result.ok({
|
|
879
1054
|
items,
|
|
880
1055
|
nestedSlots,
|
|
1056
|
+
emptied,
|
|
881
1057
|
byBlockId,
|
|
882
1058
|
omitted,
|
|
883
1059
|
mints: [...mints.values()],
|
|
884
1060
|
bookmarks,
|
|
885
1061
|
references: resolvedReferences,
|
|
886
1062
|
freezeKinds: new Set(freezeKinds),
|
|
887
|
-
keptTemplateBlocks
|
|
1063
|
+
keptTemplateBlocks,
|
|
1064
|
+
emptiedContents
|
|
888
1065
|
});
|
|
889
1066
|
};
|
|
890
|
-
export { hyperlinkFieldLink, isBlankBlock, isManualLabel, paragraphPieces, piecesContent, resolvePlan, segmentPieces };
|
|
1067
|
+
export { fieldSeparatorRun, hyperlinkFieldLink, isBlankBlock, isManualLabel, paragraphPieces, piecesContent, resolvePlan, segmentPieces };
|
|
@@ -53,6 +53,8 @@ const isPlainText = (text) => {
|
|
|
53
53
|
}
|
|
54
54
|
return true;
|
|
55
55
|
};
|
|
56
|
+
/** A font face as `w:rFonts` names one: plain text, not blank, of a sane length. */
|
|
57
|
+
const isFontName = (value) => isString(value) && value.trim() !== "" && value.length <= 64 && isPlainText(value);
|
|
56
58
|
const numberingIssue = (value, where) => {
|
|
57
59
|
if (value === void 0 || value === null) return null;
|
|
58
60
|
if (!isObject(value)) return `${where} names a malformed list.`;
|
|
@@ -87,6 +89,48 @@ const sectionIssue = (section, where) => {
|
|
|
87
89
|
"left"
|
|
88
90
|
].every((side) => isTwips(margins[side])) ? null : `${where} describes malformed page margins.`;
|
|
89
91
|
};
|
|
92
|
+
const INDENT_KEYS = /* @__PURE__ */ new Set([
|
|
93
|
+
"left",
|
|
94
|
+
"hanging",
|
|
95
|
+
"firstLine"
|
|
96
|
+
]);
|
|
97
|
+
/** The widest indent a plan may state: the widest page WordprocessingML allows. */
|
|
98
|
+
const MAX_INDENT = 31680;
|
|
99
|
+
/**
|
|
100
|
+
* Whether `value` is an indent a plan may state: at least one of
|
|
101
|
+
* `left`, `hanging` and `firstLine`, each a whole number of twentieths of a
|
|
102
|
+
* point, and not both a hanging and a first-line indent.
|
|
103
|
+
*/
|
|
104
|
+
const isIndent = (value) => {
|
|
105
|
+
if (!isObject(value)) return false;
|
|
106
|
+
const keys = Object.keys(value);
|
|
107
|
+
return keys.length > 0 && keys.every((key) => INDENT_KEYS.has(key) && isCount(value[key]) && value[key] <= MAX_INDENT) && !(value["hanging"] !== void 0 && value["firstLine"] !== void 0);
|
|
108
|
+
};
|
|
109
|
+
/** The most tab stops a plan may give one paragraph. */
|
|
110
|
+
const MAX_TAB_STOPS = 8;
|
|
111
|
+
/**
|
|
112
|
+
* Whether `value` is a list of tab stops a plan may state: one to eight
|
|
113
|
+
* whole numbers of twentieths of a point, above zero and ascending.
|
|
114
|
+
*/
|
|
115
|
+
const isTabStops = (value) => Array.isArray(value) && value.length > 0 && value.length <= MAX_TAB_STOPS && value.every((stop, index) => isCount(stop) && stop > 0 && stop <= MAX_INDENT && (index === 0 || stop > value[index - 1]));
|
|
116
|
+
const ALIGNMENTS = /* @__PURE__ */ new Set([
|
|
117
|
+
"left",
|
|
118
|
+
"center",
|
|
119
|
+
"right",
|
|
120
|
+
"both"
|
|
121
|
+
]);
|
|
122
|
+
/** Whether `value` is an alignment a plan may give a paragraph. */
|
|
123
|
+
const isAlignment = (value) => isString(value) && ALIGNMENTS.has(value);
|
|
124
|
+
const SPACING_KEYS = /* @__PURE__ */ new Set(["before", "after"]);
|
|
125
|
+
/**
|
|
126
|
+
* Whether `value` is a spacing a plan may state: `before`, `after` or
|
|
127
|
+
* both, each a whole number of twentieths of a point.
|
|
128
|
+
*/
|
|
129
|
+
const isSpacing = (value) => {
|
|
130
|
+
if (!isObject(value)) return false;
|
|
131
|
+
const keys = Object.keys(value);
|
|
132
|
+
return keys.length > 0 && keys.every((key) => SPACING_KEYS.has(key) && isCount(value[key]) && value[key] <= MAX_INDENT);
|
|
133
|
+
};
|
|
90
134
|
const sourceItemIssue = (item, where) => {
|
|
91
135
|
if (!isString(item["blockId"]) || !isString(item["hash"])) return `${where} names no source block and hash.`;
|
|
92
136
|
for (const key of [
|
|
@@ -94,7 +138,16 @@ const sourceItemIssue = (item, where) => {
|
|
|
94
138
|
"cellStyleId",
|
|
95
139
|
"stripLabel"
|
|
96
140
|
]) if (!isOptionalString(item[key])) return `${where} carries a malformed ${key}.`;
|
|
97
|
-
for (const key of [
|
|
141
|
+
for (const key of [
|
|
142
|
+
"labelAsText",
|
|
143
|
+
"pageBreakBefore",
|
|
144
|
+
"keepNext",
|
|
145
|
+
"stripLabelBreak"
|
|
146
|
+
]) if (!isOptionalBoolean(item[key])) return `${where} carries a malformed ${key}.`;
|
|
147
|
+
if (item["indent"] !== void 0 && !isIndent(item["indent"])) return `${where} carries a malformed indent.`;
|
|
148
|
+
if (item["tabStops"] !== void 0 && !isTabStops(item["tabStops"])) return `${where} carries malformed tab stops.`;
|
|
149
|
+
if (item["alignment"] !== void 0 && !isAlignment(item["alignment"])) return `${where} carries an unknown alignment.`;
|
|
150
|
+
if (item["spacing"] !== void 0 && !isSpacing(item["spacing"])) return `${where} carries a malformed spacing.`;
|
|
98
151
|
const merge = item["mergeNext"];
|
|
99
152
|
if (merge !== void 0 && !(isString(merge) && MERGES.has(merge))) return `${where} names an unknown merge.`;
|
|
100
153
|
const section = sectionIssue(item["endsSection"], where);
|
|
@@ -109,7 +162,7 @@ const sourceItemIssue = (item, where) => {
|
|
|
109
162
|
if (!isObject(entry) || !isString(entry["blockId"])) return `${where} carries a nested placement without a block.`;
|
|
110
163
|
if (seen.has(entry["blockId"])) return `${where} places nested block ${entry["blockId"]} twice.`;
|
|
111
164
|
seen.add(entry["blockId"]);
|
|
112
|
-
if (!isOptionalString(entry["styleId"]) || !isOptionalString(entry["stripLabel"]) || !isOptionalBoolean(entry["labelAsText"])) return `${where} carries a malformed nested placement.`;
|
|
165
|
+
if (!isOptionalString(entry["styleId"]) || !isOptionalString(entry["stripLabel"]) || !isOptionalBoolean(entry["labelAsText"]) || !isOptionalBoolean(entry["keepNext"]) || entry["indent"] !== void 0 && !isIndent(entry["indent"]) || entry["tabStops"] !== void 0 && !isTabStops(entry["tabStops"]) || entry["alignment"] !== void 0 && !isAlignment(entry["alignment"]) || entry["spacing"] !== void 0 && !isSpacing(entry["spacing"])) return `${where} carries a malformed nested placement.`;
|
|
113
166
|
const nestedNumbering = numberingIssue(entry["numbering"], where);
|
|
114
167
|
if (nestedNumbering !== null) return nestedNumbering;
|
|
115
168
|
}
|
|
@@ -142,23 +195,6 @@ const omitIssue = (omit) => {
|
|
|
142
195
|
for (const entry of omit) if (!isObject(entry) || !isString(entry["blockId"]) || !isString(entry["reason"]) || !OMIT_REASONS.has(entry["reason"])) return "The plan omits a block without an id or for an unknown reason.";
|
|
143
196
|
return null;
|
|
144
197
|
};
|
|
145
|
-
const INDENT_KEYS = /* @__PURE__ */ new Set([
|
|
146
|
-
"left",
|
|
147
|
-
"hanging",
|
|
148
|
-
"firstLine"
|
|
149
|
-
]);
|
|
150
|
-
/** The widest indent a patch may state: the widest page WordprocessingML allows. */
|
|
151
|
-
const MAX_INDENT = 31680;
|
|
152
|
-
/**
|
|
153
|
-
* Whether `value` is a level indent a patch may state: at least one of
|
|
154
|
-
* `left`, `hanging` and `firstLine`, each a whole number of twentieths of a
|
|
155
|
-
* point, and not both a hanging and a first-line indent.
|
|
156
|
-
*/
|
|
157
|
-
const isLevelIndent = (value) => {
|
|
158
|
-
if (!isObject(value)) return false;
|
|
159
|
-
const keys = Object.keys(value);
|
|
160
|
-
return keys.length > 0 && keys.every((key) => INDENT_KEYS.has(key) && isCount(value[key]) && value[key] <= MAX_INDENT) && !(value["hanging"] !== void 0 && value["firstLine"] !== void 0);
|
|
161
|
-
};
|
|
162
198
|
const patchesIssue = (patches) => {
|
|
163
199
|
if (patches === void 0) return null;
|
|
164
200
|
if (!Array.isArray(patches)) return "The plan's numbering patches are malformed.";
|
|
@@ -168,8 +204,8 @@ const patchesIssue = (patches) => {
|
|
|
168
204
|
const key = `${String(patch["abstractNumId"])}:${String(patch["ilvl"])}`;
|
|
169
205
|
if (seen.has(key)) return `Two numbering patches change level ${String(patch["ilvl"])} of list definition ${String(patch["abstractNumId"])}.`;
|
|
170
206
|
seen.add(key);
|
|
171
|
-
const { numFmt, lvlText, start, suff, indent } = patch;
|
|
172
|
-
if (numFmt !== void 0 && !(isString(numFmt) && NUMBER_FORMATS.has(numFmt)) || lvlText !== void 0 && !(isString(lvlText) && isPlainText(lvlText)) || start !== void 0 && !isCount(start) || suff !== void 0 && !(isString(suff) && SUFFIXES.has(suff)) || indent !== void 0 && !
|
|
207
|
+
const { numFmt, lvlText, start, suff, indent, font } = patch;
|
|
208
|
+
if (font !== void 0 && !isFontName(font) || numFmt !== void 0 && !(isString(numFmt) && NUMBER_FORMATS.has(numFmt)) || lvlText !== void 0 && !(isString(lvlText) && isPlainText(lvlText)) || start !== void 0 && !isCount(start) || suff !== void 0 && !(isString(suff) && SUFFIXES.has(suff)) || indent !== void 0 && !isIndent(indent)) return "A numbering patch carries a malformed value.";
|
|
173
209
|
}
|
|
174
210
|
return null;
|
|
175
211
|
};
|
|
@@ -204,6 +240,6 @@ const compatIssue = (compat) => {
|
|
|
204
240
|
/** Why `plan` is not a version 1 template plan, or null when it is one. */
|
|
205
241
|
const planShapeIssue = (plan) => {
|
|
206
242
|
if (!isObject(plan) || plan["version"] !== 1 || !isString(plan["sourceSha256"]) || !isString(plan["templateSha256"])) return "The plan is not a version 1 template plan.";
|
|
207
|
-
return bodyIssue(plan["body"]) ?? omitIssue(plan["omit"]) ?? patchesIssue(plan["numberingPatches"]) ?? spansIssue(plan) ?? fieldsIssue(plan["fields"]) ?? compatIssue(plan["compat"]) ?? sectionIssue(plan["lastSection"], "The plan's last section");
|
|
243
|
+
return bodyIssue(plan["body"]) ?? omitIssue(plan["omit"]) ?? patchesIssue(plan["numberingPatches"]) ?? spansIssue(plan) ?? fieldsIssue(plan["fields"]) ?? compatIssue(plan["compat"]) ?? (plan["trackedChanges"] === void 0 || plan["trackedChanges"] === "accept" || plan["trackedChanges"] === "reject" || plan["trackedChanges"] === "keep" ? null : "The plan names an unknown view of tracked changes.") ?? sectionIssue(plan["lastSection"], "The plan's last section") ?? (plan["emptyTemplateBlockIds"] === void 0 || Array.isArray(plan["emptyTemplateBlockIds"]) && plan["emptyTemplateBlockIds"].every(isString) ? null : "The plan's emptied template blocks are no list of block ids.") ?? (plan["textEffects"] === void 0 || plan["textEffects"] === "normalize" || plan["textEffects"] === "keep" ? null : "The plan's choice for text effects is unknown.");
|
|
208
244
|
};
|
|
209
245
|
export { OMIT_REASONS, PLAN_HIGHLIGHT_COLORS, isPlainText, planShapeIssue };
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tracked changes resolved to one view.
|
|
3
|
+
*
|
|
4
|
+
* A document with tracked changes is two texts at once: what it reads with
|
|
5
|
+
* every change accepted, and what it reads with every change rejected. A
|
|
6
|
+
* plan is made for one of them. This module rewrites the story parts of a
|
|
7
|
+
* package into the chosen view: no insertion, deletion, move or recorded
|
|
8
|
+
* formatting change is left, and nothing else of the parts changes.
|
|
9
|
+
*
|
|
10
|
+
* - Accepted: inserted content stays and loses its wrapper, deleted content
|
|
11
|
+
* goes. Rejected: the reverse, and deleted text is ordinary text again.
|
|
12
|
+
* - A paragraph mark that the view removes (deleted and accepted, inserted
|
|
13
|
+
* and rejected) joins its paragraph to the next one of the same container,
|
|
14
|
+
* whose mark, and with it whose properties, the joined paragraph keeps.
|
|
15
|
+
* - A table row that the view removes goes whole; so does a cell.
|
|
16
|
+
* - A recorded formatting change is dropped when accepted. Rejected, the
|
|
17
|
+
* properties it recorded come back.
|
|
18
|
+
*/
|
|
19
|
+
import { XmlElement } from "../../xmlParser.js";
|
|
20
|
+
import { DocxTrackedChanges, TemplatePlanError, TemplatePlanTrackedView } from "./types.js";
|
|
21
|
+
import { Result } from "better-result";
|
|
22
|
+
type Tally = {
|
|
23
|
+
insertions: number;
|
|
24
|
+
deletions: number;
|
|
25
|
+
moves: number;
|
|
26
|
+
paragraphMarks: number;
|
|
27
|
+
tableRows: number;
|
|
28
|
+
formattingChanges: number;
|
|
29
|
+
authors: Set<string>;
|
|
30
|
+
first: string | null;
|
|
31
|
+
last: string | null;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* The text a deleted paragraph mark is carried as, inside a deletion of
|
|
35
|
+
* its own, by a reading that keeps tracked changes: a private-use character
|
|
36
|
+
* no document's text holds.
|
|
37
|
+
*/
|
|
38
|
+
export declare const DELETED_PARAGRAPH_MARK = "";
|
|
39
|
+
/**
|
|
40
|
+
* The element a deleted table row is kept in by a reading that keeps
|
|
41
|
+
* tracked changes. The accepted view has no such row, so it may be no row
|
|
42
|
+
* of the table to the readers of blocks; in a namespace of its own it is
|
|
43
|
+
* none, and the writer and verification find it by this name.
|
|
44
|
+
*/
|
|
45
|
+
export declare const KEPT_DELETED_ROW_NAMESPACE = "urn:stll:folio:kept-deleted-row";
|
|
46
|
+
/** The row a kept-deleted-row element holds, or null for any other element. */
|
|
47
|
+
export declare const keptDeletedRowOf: (element: XmlElement) => XmlElement | null;
|
|
48
|
+
/** The deletion a row's properties record, or null. */
|
|
49
|
+
export declare const deletedRowMarkOf: (row: XmlElement) => XmlElement | null;
|
|
50
|
+
/** The insertion a row's properties record, or null. */
|
|
51
|
+
export declare const insertedRowMarkOf: (row: XmlElement) => XmlElement | null;
|
|
52
|
+
/** What a deleted row held: its cells' text, deleted text included, a tab
|
|
53
|
+
* between cells and a line break between paragraphs. */
|
|
54
|
+
export declare const rowTextOf: (row: XmlElement) => string;
|
|
55
|
+
/**
|
|
56
|
+
* The row revisions a table carries in the kept form, in order: an inserted
|
|
57
|
+
* row by the place it has among the table's rows, a deleted one by the
|
|
58
|
+
* place it was taken from and by its text; each with who made the change.
|
|
59
|
+
* Rows of a table nested in a cell are that table's.
|
|
60
|
+
*/
|
|
61
|
+
export declare const tableRowRevisions: (table: XmlElement) => string[];
|
|
62
|
+
/** One part with its deleted paragraph marks carried as deletions; null
|
|
63
|
+
* when it cannot be read whole. */
|
|
64
|
+
export declare const joinDeletedMarksInPart: (path: string, xml: string) => string | null;
|
|
65
|
+
/**
|
|
66
|
+
* A package in the form a reading that keeps tracked changes takes it in:
|
|
67
|
+
* the main document and the notes with their deleted paragraph marks
|
|
68
|
+
* carried as deletions. The bytes are the document's own when it has none.
|
|
69
|
+
*/
|
|
70
|
+
export declare const withDeletedMarksJoined: (docx: Uint8Array) => Promise<Result<Uint8Array, TemplatePlanError>>;
|
|
71
|
+
/** Changes a plan that keeps tracked changes cannot carry yet, counted. */
|
|
72
|
+
export type KeptRevisionObstacles = {
|
|
73
|
+
paragraphMarks: number;
|
|
74
|
+
tableRows: number;
|
|
75
|
+
tableCells: number;
|
|
76
|
+
moves: number;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* What a document tracks, and which of it a plan that keeps tracked changes
|
|
80
|
+
* cannot carry: a change that makes the paragraphs of the accepted and the
|
|
81
|
+
* rejected view differ.
|
|
82
|
+
*/
|
|
83
|
+
export declare const keptRevisionObstacles: (docx: Uint8Array) => Promise<Result<{
|
|
84
|
+
tracked: DocxTrackedChanges;
|
|
85
|
+
obstacles: KeptRevisionObstacles;
|
|
86
|
+
}, TemplatePlanError>>;
|
|
87
|
+
/** One part in the chosen view, or null when it cannot be read whole. */
|
|
88
|
+
export declare const resolvePartRevisions: (path: string, xml: string, view: TemplatePlanTrackedView) => {
|
|
89
|
+
xml: string;
|
|
90
|
+
tally: Tally;
|
|
91
|
+
} | null;
|
|
92
|
+
/**
|
|
93
|
+
* A package with the tracked changes of its main document and its notes
|
|
94
|
+
* resolved to `view`, and what was resolved. The bytes are the source's own
|
|
95
|
+
* when it tracks nothing.
|
|
96
|
+
*/
|
|
97
|
+
export declare const resolveTrackedChanges: (docx: Uint8Array, view: TemplatePlanTrackedView) => Promise<Result<{
|
|
98
|
+
docx: Uint8Array;
|
|
99
|
+
resolved: DocxTrackedChanges;
|
|
100
|
+
}, TemplatePlanError>>;
|
|
101
|
+
export {};
|