@stll/folio-core 0.76.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 +6 -4
- package/dist/ai-edits/headless.js +32 -15
- package/dist/ai-edits/pending-suggestions.d.ts +9 -0
- package/dist/ai-edits/pending-suggestions.js +11 -0
- package/dist/ai-edits/read.js +24 -1
- package/dist/ai-edits/table-geometry.js +12 -4
- 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 +13 -38
- 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 +178 -186
- package/dist/controller/canonicalClipboard.d.ts +2 -1
- package/dist/controller/canonicalClipboard.js +312 -47
- package/dist/controller/canonicalComposition.js +67 -14
- package/dist/controller/canonicalStoryEditor.js +2 -0
- package/dist/controller/hiddenEditorManager.js +2 -0
- package/dist/docx/importedIdCollisions.js +29 -4
- package/dist/docx/server/templatePlan/apply.js +47 -2
- package/dist/docx/server/templatePlan/blocks.d.ts +27 -7
- package/dist/docx/server/templatePlan/blocks.js +103 -12
- package/dist/docx/server/templatePlan/builders.d.ts +6 -0
- package/dist/docx/server/templatePlan/builders.js +7 -1
- package/dist/docx/server/templatePlan/emit.d.ts +2 -0
- package/dist/docx/server/templatePlan/emit.js +108 -6
- package/dist/docx/server/templatePlan/plan.d.ts +24 -1
- package/dist/docx/server/templatePlan/plan.js +165 -12
- package/dist/docx/server/templatePlan/planShape.js +13 -2
- package/dist/docx/server/templatePlan/revisions.d.ts +55 -0
- package/dist/docx/server/templatePlan/revisions.js +276 -2
- package/dist/docx/server/templatePlan/story.d.ts +46 -1
- package/dist/docx/server/templatePlan/story.js +125 -11
- package/dist/docx/server/templatePlan/types.d.ts +97 -1
- package/dist/docx/server/templatePlan/verify.js +63 -9
- 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/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/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/replacedAnnotations.d.ts +4 -78
- package/dist/prosemirror/replacedAnnotations.js +11 -194
- package/dist/prosemirror/styles/styleResolver.d.ts +1 -0
- package/dist/prosemirror/styles/styleResolver.js +4 -1
- package/dist/server.d.ts +2 -2
- package/dist/types/canonicalCapabilities.d.ts +3 -10
- package/dist/types/canonicalCapabilities.js +3 -10
- package/package.json +2 -2
- 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 -3
- package/dist/internal/revisionResolutionStep.js +0 -113
- 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 -8
- package/dist/prosemirror/commands/tableCellMergeResolution.js +0 -56
- 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
|
@@ -9,7 +9,7 @@ import { AnalyzedBlock, AnalyzedDocument } from "./blocks.js";
|
|
|
9
9
|
import { BookmarkWrap } from "./builders.js";
|
|
10
10
|
import { StoryOrigin } from "./resources.js";
|
|
11
11
|
import { AtomKind, AtomLink, InlineAtom, ParagraphRead, StoryField } from "./story.js";
|
|
12
|
-
import { TemplatePlan, TemplatePlanAlignment, TemplatePlanError, TemplatePlanIndent, TemplatePlanOmitReason, TemplatePlanReference, TemplatePlanSection } from "./types.js";
|
|
12
|
+
import { TemplatePlan, TemplatePlanAlignment, TemplatePlanError, TemplatePlanIndent, TemplatePlanOmitReason, TemplatePlanReference, TemplatePlanSection, TemplatePlanSpacing } from "./types.js";
|
|
13
13
|
import { Result } from "better-result";
|
|
14
14
|
export type ExpectedPiece = {
|
|
15
15
|
kind: AtomKind;
|
|
@@ -53,6 +53,12 @@ export type ResolvedNumbering = {
|
|
|
53
53
|
export type ResolvedPart = {
|
|
54
54
|
block: AnalyzedBlock;
|
|
55
55
|
strippedPrefix: string;
|
|
56
|
+
/** The lead a slot dropped off the part and the template paragraph that
|
|
57
|
+
* shows the field, or null. */
|
|
58
|
+
droppedLead: {
|
|
59
|
+
text: string;
|
|
60
|
+
shownByTemplateBlockId: string;
|
|
61
|
+
} | null;
|
|
56
62
|
/** The automatic label written as text before the part, or null. */
|
|
57
63
|
labelAsText: string | null;
|
|
58
64
|
};
|
|
@@ -77,6 +83,8 @@ export type ResolvedParagraph = {
|
|
|
77
83
|
tabStops: readonly number[] | null;
|
|
78
84
|
/** The paragraph's own alignment, or null. */
|
|
79
85
|
alignment: TemplatePlanAlignment | null;
|
|
86
|
+
/** The paragraph's own space in front and behind, or null. */
|
|
87
|
+
spacing: TemplatePlanSpacing | null;
|
|
80
88
|
/** The section the paragraph is the last of, or null. */
|
|
81
89
|
endsSection: TemplatePlanSection | null;
|
|
82
90
|
};
|
|
@@ -109,10 +117,21 @@ export type ResolvedSlot = {
|
|
|
109
117
|
templateBlock: AnalyzedBlock;
|
|
110
118
|
paragraph: ResolvedParagraph;
|
|
111
119
|
};
|
|
120
|
+
/**
|
|
121
|
+
* The run of a paragraph that holds the separator of the field the
|
|
122
|
+
* paragraph begins and leaves open: what follows it is the start of a result
|
|
123
|
+
* that goes on in later paragraphs. A field the paragraph both begins and
|
|
124
|
+
* ends (a page number in front of a table of contents) is not that field.
|
|
125
|
+
* Null when no one field is left open with its result begun, in runs of the
|
|
126
|
+
* paragraph itself.
|
|
127
|
+
*/
|
|
128
|
+
export declare const fieldSeparatorRun: (paragraph: XmlElement) => XmlElement | null;
|
|
112
129
|
export type ResolvedPlan = {
|
|
113
130
|
items: ResolvedItem[];
|
|
114
131
|
/** Slots that sit inside a kept template table. */
|
|
115
132
|
nestedSlots: ResolvedSlot[];
|
|
133
|
+
/** Paragraphs of kept template tables written without their text. */
|
|
134
|
+
emptied: AnalyzedBlock[];
|
|
116
135
|
/** The output paragraph each placed source block ends up in. */
|
|
117
136
|
byBlockId: Map<string, ResolvedParagraph>;
|
|
118
137
|
omitted: Map<string, TemplatePlanOmitReason>;
|
|
@@ -128,6 +147,10 @@ export type ResolvedPlan = {
|
|
|
128
147
|
}[];
|
|
129
148
|
freezeKinds: ReadonlySet<string>;
|
|
130
149
|
keptTemplateBlocks: AnalyzedBlock[];
|
|
150
|
+
/** The paragraphs kept tables of contents begin in, written without the
|
|
151
|
+
* entries they cache: each with the length of the text it keeps in front
|
|
152
|
+
* of the field's result. */
|
|
153
|
+
emptiedContents: Map<AnalyzedBlock, number>;
|
|
131
154
|
};
|
|
132
155
|
/**
|
|
133
156
|
* Whether `label` reads as a manual list label: up to three leading words
|
|
@@ -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,
|
|
@@ -196,6 +268,16 @@ const partSegments = ({ block, pieces, strippedLength, strippedBreak, references
|
|
|
196
268
|
}));
|
|
197
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.`);
|
|
198
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
|
+
}
|
|
199
281
|
const positioned = [];
|
|
200
282
|
for (const entry of split) {
|
|
201
283
|
const empty = entry.start === entry.end;
|
|
@@ -368,7 +450,7 @@ const resolvePlan = (source, template, plan) => {
|
|
|
368
450
|
message: "The plan was made for another template."
|
|
369
451
|
}));
|
|
370
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.`);
|
|
371
|
-
if (source.manifest.trackedChanges > 0) return Result.err(refuse({
|
|
453
|
+
if (source.manifest.trackedChanges > 0 && source.manifest.trackedChangesKept === void 0) return Result.err(refuse({
|
|
372
454
|
code: "tracked-changes",
|
|
373
455
|
message: `The source holds ${source.manifest.trackedChanges} tracked change(s); resolve them first.`
|
|
374
456
|
}));
|
|
@@ -469,7 +551,7 @@ const resolvePlan = (source, template, plan) => {
|
|
|
469
551
|
placed.add(id);
|
|
470
552
|
return Result.ok(void 0);
|
|
471
553
|
};
|
|
472
|
-
const resolveParagraph = ({ parts, separators, styleId, numbering, placement, ordinal, pageBreakBefore = false, keepNext = false, indent, tabStops, alignment, endsSection }) => {
|
|
554
|
+
const resolveParagraph = ({ parts, separators, styleId, numbering, placement, ordinal, pageBreakBefore = false, keepNext = false, indent, tabStops, alignment, spacing, endsSection }) => {
|
|
473
555
|
const first = parts.at(0);
|
|
474
556
|
if (first === void 0) return invalid("A plan item names no source block.");
|
|
475
557
|
const firstId = first.block.block.id;
|
|
@@ -488,6 +570,13 @@ const resolvePlan = (source, template, plan) => {
|
|
|
488
570
|
const { block, stripLabel, stripLabelBreak } = planned;
|
|
489
571
|
const { id, text } = block.block;
|
|
490
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
|
+
}));
|
|
491
580
|
const placedOnce = place(block);
|
|
492
581
|
if (Result.isError(placedOnce)) return placedOnce;
|
|
493
582
|
const unread = block.read.unsupported.at(0);
|
|
@@ -504,6 +593,21 @@ const resolvePlan = (source, template, plan) => {
|
|
|
504
593
|
const blank = stripLabelBreak === true ? LABEL_SPACE_AND_BREAK : LABEL_SPACE;
|
|
505
594
|
strippedPrefix = text.slice(0, labelEnd + (blank.exec(text.slice(labelEnd))?.[0].length ?? 0));
|
|
506
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
|
+
};
|
|
610
|
+
}
|
|
507
611
|
const part = partSegments({
|
|
508
612
|
block,
|
|
509
613
|
pieces: paragraphPieces({
|
|
@@ -512,7 +616,7 @@ const resolvePlan = (source, template, plan) => {
|
|
|
512
616
|
origin: "document",
|
|
513
617
|
fields: source.story.state.fields
|
|
514
618
|
}),
|
|
515
|
-
strippedLength: strippedPrefix.length,
|
|
619
|
+
strippedLength: droppedLead === null ? strippedPrefix.length : droppedLead.text.length,
|
|
516
620
|
strippedBreak: stripLabelBreak === true,
|
|
517
621
|
references: referencesByBlock.get(id) ?? [],
|
|
518
622
|
highlights: highlightsByBlock.get(id) ?? []
|
|
@@ -542,6 +646,7 @@ const resolvePlan = (source, template, plan) => {
|
|
|
542
646
|
resolvedParts.push({
|
|
543
647
|
block,
|
|
544
648
|
strippedPrefix,
|
|
649
|
+
droppedLead,
|
|
545
650
|
labelAsText: written?.label ?? null
|
|
546
651
|
});
|
|
547
652
|
}
|
|
@@ -568,6 +673,7 @@ const resolvePlan = (source, template, plan) => {
|
|
|
568
673
|
indent: indent ?? null,
|
|
569
674
|
tabStops: tabStops ?? null,
|
|
570
675
|
alignment: alignment ?? null,
|
|
676
|
+
spacing: spacing ?? null,
|
|
571
677
|
endsSection: endsSection ?? null
|
|
572
678
|
};
|
|
573
679
|
for (const { block } of resolvedParts) byBlockId.set(block.block.id, paragraph);
|
|
@@ -584,7 +690,7 @@ const resolvePlan = (source, template, plan) => {
|
|
|
584
690
|
};
|
|
585
691
|
const resolveTable = (block, item, tableOrdinal) => {
|
|
586
692
|
const { id } = block.block;
|
|
587
|
-
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.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.`);
|
|
588
694
|
if (item.styleId !== void 0 && template.styles.get(item.styleId)?.type !== "table") return Result.err(refuse({
|
|
589
695
|
code: "style-unknown",
|
|
590
696
|
message: `The template has no table style ${item.styleId}.`,
|
|
@@ -617,7 +723,8 @@ const resolvePlan = (source, template, plan) => {
|
|
|
617
723
|
keepNext: override?.keepNext === true,
|
|
618
724
|
indent: override?.indent,
|
|
619
725
|
tabStops: override?.tabStops,
|
|
620
|
-
alignment: override?.alignment
|
|
726
|
+
alignment: override?.alignment,
|
|
727
|
+
spacing: override?.spacing
|
|
621
728
|
});
|
|
622
729
|
if (Result.isError(paragraph)) return paragraph;
|
|
623
730
|
cells.set(nested.element, paragraph.value);
|
|
@@ -641,6 +748,8 @@ const resolvePlan = (source, template, plan) => {
|
|
|
641
748
|
const keptTemplateIds = /* @__PURE__ */ new Set();
|
|
642
749
|
const slottedTemplateIds = /* @__PURE__ */ new Set();
|
|
643
750
|
const pendingNestedSlots = [];
|
|
751
|
+
/** The template paragraphs slots name as showing a dropped lead's field. */
|
|
752
|
+
const leadShowers = [];
|
|
644
753
|
let ordinal = 0;
|
|
645
754
|
for (let index = 0; index < plan.body.length; index += 1) {
|
|
646
755
|
const item = plan.body[index];
|
|
@@ -703,7 +812,7 @@ const resolvePlan = (source, template, plan) => {
|
|
|
703
812
|
message: `Block ${next.blockId} does not have the hash the plan pins.`,
|
|
704
813
|
blockId: next.blockId
|
|
705
814
|
}));
|
|
706
|
-
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.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({
|
|
707
816
|
code: "merge-invalid",
|
|
708
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.`,
|
|
709
818
|
blockId: next.blockId
|
|
@@ -730,6 +839,7 @@ const resolvePlan = (source, template, plan) => {
|
|
|
730
839
|
indent: item.indent,
|
|
731
840
|
tabStops: item.tabStops,
|
|
732
841
|
alignment: item.alignment,
|
|
842
|
+
spacing: item.spacing,
|
|
733
843
|
endsSection: item.endsSection
|
|
734
844
|
});
|
|
735
845
|
if (Result.isError(paragraph)) return paragraph;
|
|
@@ -752,16 +862,22 @@ const resolvePlan = (source, template, plan) => {
|
|
|
752
862
|
blockId: item.templateBlockId
|
|
753
863
|
}));
|
|
754
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.`);
|
|
755
866
|
const parts = [];
|
|
756
|
-
for (const id of item.sourceBlockIds) {
|
|
867
|
+
for (const [position, id] of item.sourceBlockIds.entries()) {
|
|
757
868
|
const block = sourceTopLevel(id);
|
|
758
869
|
if (Result.isError(block)) return block;
|
|
759
870
|
parts.push({
|
|
760
871
|
block: block.value,
|
|
761
872
|
stripLabel: void 0,
|
|
762
|
-
labelAsText: false
|
|
873
|
+
labelAsText: false,
|
|
874
|
+
...position === 0 && item.dropLead !== void 0 ? { dropLead: item.dropLead } : {}
|
|
763
875
|
});
|
|
764
876
|
}
|
|
877
|
+
if (item.dropLead !== void 0) leadShowers.push({
|
|
878
|
+
templateBlockId: item.dropLead.shownByTemplateBlockId,
|
|
879
|
+
slotId: item.templateBlockId
|
|
880
|
+
});
|
|
765
881
|
const paragraph = resolveParagraph({
|
|
766
882
|
parts,
|
|
767
883
|
separators: parts.slice(1).map(() => "lineBreak"),
|
|
@@ -793,12 +909,34 @@ const resolvePlan = (source, template, plan) => {
|
|
|
793
909
|
}));
|
|
794
910
|
nestedSlots.push(slot);
|
|
795
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
|
+
}
|
|
796
930
|
partTables(items);
|
|
797
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.");
|
|
798
932
|
const keptPosition = /* @__PURE__ */ new Map();
|
|
799
933
|
for (const [position, item] of items.entries()) if (item.kind === "template") keptPosition.set(item.block.block.id, position);
|
|
800
934
|
const templateOrder = template.story.topLevel.map(({ block }) => block.id);
|
|
801
|
-
const slots = [
|
|
935
|
+
const slots = [
|
|
936
|
+
...nestedSlots,
|
|
937
|
+
...items.flatMap((item) => item.kind === "slot" ? [item] : []),
|
|
938
|
+
...emptied.map((templateBlock) => ({ templateBlock }))
|
|
939
|
+
];
|
|
802
940
|
for (const field of template.story.state.fields) {
|
|
803
941
|
const lastOrdinal = field.closed ? field.endParagraphOrdinal : Number.POSITIVE_INFINITY;
|
|
804
942
|
if (lastOrdinal === field.paragraphOrdinal) continue;
|
|
@@ -823,6 +961,19 @@ const resolvePlan = (source, template, plan) => {
|
|
|
823
961
|
blockId: span.at(0) ?? ""
|
|
824
962
|
}));
|
|
825
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
|
+
}
|
|
826
977
|
const omitted = /* @__PURE__ */ new Map();
|
|
827
978
|
for (const entry of plan.omit) {
|
|
828
979
|
const block = sourceTopLevel(entry.blockId);
|
|
@@ -902,13 +1053,15 @@ const resolvePlan = (source, template, plan) => {
|
|
|
902
1053
|
return Result.ok({
|
|
903
1054
|
items,
|
|
904
1055
|
nestedSlots,
|
|
1056
|
+
emptied,
|
|
905
1057
|
byBlockId,
|
|
906
1058
|
omitted,
|
|
907
1059
|
mints: [...mints.values()],
|
|
908
1060
|
bookmarks,
|
|
909
1061
|
references: resolvedReferences,
|
|
910
1062
|
freezeKinds: new Set(freezeKinds),
|
|
911
|
-
keptTemplateBlocks
|
|
1063
|
+
keptTemplateBlocks,
|
|
1064
|
+
emptiedContents
|
|
912
1065
|
});
|
|
913
1066
|
};
|
|
914
|
-
export { hyperlinkFieldLink, isBlankBlock, isManualLabel, paragraphPieces, piecesContent, resolvePlan, segmentPieces };
|
|
1067
|
+
export { fieldSeparatorRun, hyperlinkFieldLink, isBlankBlock, isManualLabel, paragraphPieces, piecesContent, resolvePlan, segmentPieces };
|
|
@@ -121,6 +121,16 @@ const ALIGNMENTS = /* @__PURE__ */ new Set([
|
|
|
121
121
|
]);
|
|
122
122
|
/** Whether `value` is an alignment a plan may give a paragraph. */
|
|
123
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
|
+
};
|
|
124
134
|
const sourceItemIssue = (item, where) => {
|
|
125
135
|
if (!isString(item["blockId"]) || !isString(item["hash"])) return `${where} names no source block and hash.`;
|
|
126
136
|
for (const key of [
|
|
@@ -137,6 +147,7 @@ const sourceItemIssue = (item, where) => {
|
|
|
137
147
|
if (item["indent"] !== void 0 && !isIndent(item["indent"])) return `${where} carries a malformed indent.`;
|
|
138
148
|
if (item["tabStops"] !== void 0 && !isTabStops(item["tabStops"])) return `${where} carries malformed tab stops.`;
|
|
139
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.`;
|
|
140
151
|
const merge = item["mergeNext"];
|
|
141
152
|
if (merge !== void 0 && !(isString(merge) && MERGES.has(merge))) return `${where} names an unknown merge.`;
|
|
142
153
|
const section = sectionIssue(item["endsSection"], where);
|
|
@@ -151,7 +162,7 @@ const sourceItemIssue = (item, where) => {
|
|
|
151
162
|
if (!isObject(entry) || !isString(entry["blockId"])) return `${where} carries a nested placement without a block.`;
|
|
152
163
|
if (seen.has(entry["blockId"])) return `${where} places nested block ${entry["blockId"]} twice.`;
|
|
153
164
|
seen.add(entry["blockId"]);
|
|
154
|
-
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"])) 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.`;
|
|
155
166
|
const nestedNumbering = numberingIssue(entry["numbering"], where);
|
|
156
167
|
if (nestedNumbering !== null) return nestedNumbering;
|
|
157
168
|
}
|
|
@@ -229,6 +240,6 @@ const compatIssue = (compat) => {
|
|
|
229
240
|
/** Why `plan` is not a version 1 template plan, or null when it is one. */
|
|
230
241
|
const planShapeIssue = (plan) => {
|
|
231
242
|
if (!isObject(plan) || plan["version"] !== 1 || !isString(plan["sourceSha256"]) || !isString(plan["templateSha256"])) return "The plan is not a version 1 template plan.";
|
|
232
|
-
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" ? null : "The plan names an unknown view of tracked changes.") ?? sectionIssue(plan["lastSection"], "The plan's last section") ?? (plan["textEffects"] === void 0 || plan["textEffects"] === "normalize" || plan["textEffects"] === "keep" ? null : "The plan's choice for text effects is unknown.");
|
|
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.");
|
|
233
244
|
};
|
|
234
245
|
export { OMIT_REASONS, PLAN_HIGHLIGHT_COLORS, isPlainText, planShapeIssue };
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
* - A recorded formatting change is dropped when accepted. Rejected, the
|
|
17
17
|
* properties it recorded come back.
|
|
18
18
|
*/
|
|
19
|
+
import { XmlElement } from "../../xmlParser.js";
|
|
19
20
|
import { DocxTrackedChanges, TemplatePlanError, TemplatePlanTrackedView } from "./types.js";
|
|
20
21
|
import { Result } from "better-result";
|
|
21
22
|
type Tally = {
|
|
@@ -29,6 +30,60 @@ type Tally = {
|
|
|
29
30
|
first: string | null;
|
|
30
31
|
last: string | null;
|
|
31
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>>;
|
|
32
87
|
/** One part in the chosen view, or null when it cannot be read whole. */
|
|
33
88
|
export declare const resolvePartRevisions: (path: string, xml: string, view: TemplatePlanTrackedView) => {
|
|
34
89
|
xml: string;
|