@stll/folio-core 0.74.0 → 0.76.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/clean-text.d.ts +4 -1
- package/dist/ai-edits/clean-text.js +21 -7
- package/dist/ai-edits/headless.d.ts +7 -3
- package/dist/ai-edits/headless.js +36 -21
- package/dist/ai-edits/note-references.d.ts +1 -1
- package/dist/ai-edits/note-references.js +1 -1
- package/dist/ai-edits/pending-suggestions.d.ts +9 -7
- package/dist/ai-edits/pending-suggestions.js +135 -90
- package/dist/ai-edits/pendingJoin.d.ts +5 -1
- package/dist/ai-edits/pendingJoin.js +6 -2
- package/dist/ai-edits/read.js +9 -3
- package/dist/ai-edits/retired-comment-receipts.d.ts +2 -2
- package/dist/ai-edits/retired-comment-receipts.js +3 -18
- package/dist/ai-edits/tracked-batch-fidelity.d.ts +6 -10
- package/dist/ai-edits/tracked-batch-fidelity.js +3 -182
- package/dist/ai-edits/types.d.ts +9 -4
- package/dist/canonical/batchCommentReferences.js +2 -1
- package/dist/canonical/canonicalBatchReview.d.ts +4 -1
- package/dist/canonical/canonicalBatchReview.js +37 -22
- package/dist/canonical/canonicalComments.d.ts +6 -2
- package/dist/canonical/canonicalComments.js +16 -6
- package/dist/canonical/canonicalCompilerRefusal.d.ts +2 -4
- package/dist/canonical/canonicalCompilerRefusal.js +20 -14
- package/dist/canonical/canonicalPublicOperations.js +231 -79
- package/dist/canonical/canonicalRefusalGrounds.d.ts +4 -0
- package/dist/canonical/canonicalRefusalGrounds.js +56 -0
- package/dist/canonical/canonicalSession.d.ts +12 -6
- package/dist/canonical/canonicalSession.js +119 -122
- package/dist/canonical/canonicalTrackedBatchFidelity.js +3 -3
- package/dist/compare/inline-atoms.d.ts +35 -41
- package/dist/compare/inline-atoms.js +2 -465
- package/dist/compare/section-boundary-properties.d.ts +3 -30
- package/dist/compare/section-boundary-properties.js +4 -72
- package/dist/controller/canonicalClipboard.d.ts +1 -1
- package/dist/controller/canonicalClipboard.js +110 -55
- package/dist/controller/canonicalComposition.d.ts +1 -1
- package/dist/controller/canonicalComposition.js +5 -5
- package/dist/controller/canonicalContentControlValue.js +7 -7
- package/dist/controller/canonicalInput.d.ts +4 -2
- package/dist/controller/canonicalInput.js +33 -16
- package/dist/controller/canonicalReview.d.ts +21 -0
- package/dist/controller/canonicalReview.js +44 -9
- package/dist/controller/canonicalStoryEditor.d.ts +2 -3
- package/dist/controller/canonicalStoryEditor.js +43 -25
- package/dist/controller/canonicalStructure.d.ts +19 -3
- package/dist/controller/canonicalStructure.js +182 -58
- package/dist/controller/deferredDisplayListPainter.d.ts +8 -0
- package/dist/controller/deferredDisplayListPainter.js +34 -0
- package/dist/controller/folioEditor.js +4 -2
- package/dist/controller/fontReadiness.js +50 -23
- package/dist/controller/headerFooterEditorManager.js +3 -17
- package/dist/controller/hiddenEditorApi.d.ts +24 -3
- package/dist/controller/hiddenEditorApi.js +2 -0
- package/dist/controller/hiddenEditorManager.js +135 -207
- package/dist/controller/layoutPipeline.d.ts +4 -86
- package/dist/controller/layoutPipeline.js +8 -727
- package/dist/controller/layoutPipelineExecution.d.ts +94 -0
- package/dist/controller/layoutPipelineExecution.js +730 -0
- package/dist/controller/noteEditorManager.js +3 -16
- package/dist/docx/blockContentParser.d.ts +1 -3
- package/dist/docx/blockContentParser.js +3 -10
- package/dist/docx/bulletMarkers.d.ts +8 -0
- package/dist/docx/bulletMarkers.js +9 -1
- package/dist/docx/canonicalSave.d.ts +4 -3
- package/dist/docx/canonicalSave.js +4 -3
- 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/listMarkerComputation.d.ts +24 -17
- package/dist/docx/listMarkerComputation.js +31 -60
- package/dist/docx/listModelNormalization.js +8 -15
- package/dist/docx/rezip.d.ts +16 -3
- package/dist/docx/rezip.js +35 -9
- package/dist/docx/selectiveSave.js +13 -5
- package/dist/docx/server/templatePlan/apply.js +96 -7
- package/dist/docx/server/templatePlan/blocks.d.ts +70 -3
- package/dist/docx/server/templatePlan/blocks.js +272 -10
- package/dist/docx/server/templatePlan/builders.d.ts +52 -2
- package/dist/docx/server/templatePlan/builders.js +224 -5
- 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 +46 -2
- package/dist/docx/server/templatePlan/inspect.js +39 -52
- package/dist/docx/server/templatePlan/labels.d.ts +7 -2
- package/dist/docx/server/templatePlan/labels.js +120 -23
- package/dist/docx/server/templatePlan/plan.d.ts +24 -3
- package/dist/docx/server/templatePlan/plan.js +54 -15
- package/dist/docx/server/templatePlan/planShape.js +76 -22
- package/dist/docx/server/templatePlan/revisions.d.ts +46 -0
- package/dist/docx/server/templatePlan/revisions.js +407 -0
- package/dist/docx/server/templatePlan/story.d.ts +23 -1
- package/dist/docx/server/templatePlan/story.js +60 -2
- package/dist/docx/server/templatePlan/types.d.ts +354 -16
- package/dist/docx/server/templatePlan/verify.js +164 -14
- package/dist/docx/server/templatePlan/xml.d.ts +3 -0
- package/dist/docx/server/templatePlan/xml.js +4 -1
- package/dist/i18n/messages/ar.gen.js +1 -0
- package/dist/i18n/messages/catalogs.gen.d.ts +17 -0
- package/dist/i18n/messages/catalogs.gen.js +17 -0
- package/dist/i18n/messages/cs.gen.js +1 -0
- package/dist/i18n/messages/de.gen.js +1 -0
- package/dist/i18n/messages/en.gen.js +1 -0
- package/dist/i18n/messages/es.gen.js +1 -0
- package/dist/i18n/messages/et.gen.js +1 -0
- package/dist/i18n/messages/fr.gen.js +1 -0
- package/dist/i18n/messages/he.gen.js +1 -0
- package/dist/i18n/messages/hi.gen.js +1 -0
- package/dist/i18n/messages/hu.gen.js +1 -0
- package/dist/i18n/messages/lt.gen.js +1 -0
- package/dist/i18n/messages/lv.gen.js +1 -0
- package/dist/i18n/messages/messages.gen.d.ts +1 -0
- package/dist/i18n/messages/pl.gen.js +1 -0
- package/dist/i18n/messages/pt-BR.gen.js +1 -0
- package/dist/i18n/messages/sk.gen.js +1 -0
- package/dist/i18n/messages/tr.gen.js +1 -0
- package/dist/i18n/messages/zh-CN.gen.js +1 -0
- package/dist/internal/revisionResolutionStep.d.ts +2 -31
- package/dist/internal/revisionResolutionStep.js +2 -171
- package/dist/layout-bridge/convert/toFlowBlocks.js +0 -12
- package/dist/layout-bridge/convert/topLevelConversion.js +1 -10
- 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/commands/tableCellMergeResolution.d.ts +1 -11
- package/dist/prosemirror/commands/tableCellMergeResolution.js +3 -154
- package/dist/prosemirror/extensions/features/ImagePasteExtension.js +1 -1
- 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/listMarker.d.ts +1 -6
- package/dist/prosemirror/listMarker.js +4 -56
- 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 +2 -5
- package/dist/prosemirror/replacedAnnotations.js +1 -10
- 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/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 +40 -69
- package/dist/types/canonicalCapabilities.js +51 -65
- package/dist/types/canonicalComments.d.ts +2 -2
- package/dist/types/canonicalSections.d.ts +2 -2
- package/dist/utils/clipboard.d.ts +2 -28
- package/dist/utils/clipboard.js +1 -96
- package/dist/utils/clipboardFiles.d.ts +27 -0
- package/dist/utils/clipboardFiles.js +98 -0
- package/dist/utils/rulerControl.d.ts +1 -0
- package/dist/utils/rulerControl.js +2 -1
- package/package.json +2 -2
- package/dist/internal/headlessRevisionResolutionGuard.d.ts +0 -3
- package/dist/internal/headlessRevisionResolutionGuard.js +0 -18
|
@@ -1,26 +1,16 @@
|
|
|
1
1
|
import { RELATIONSHIP_TYPES } from "../../relsParser.js";
|
|
2
2
|
import { parseSectionProperties } from "../../sectionParser.js";
|
|
3
|
-
import { analyzeDocument, styleOutlineLevel } from "./blocks.js";
|
|
3
|
+
import { analyzeDocument, statedAlignments, statedLooks, storySections, styleAlignment, styleLook, styleOutlineLevel } from "./blocks.js";
|
|
4
|
+
import { findInvisibleEffects } from "./effects.js";
|
|
4
5
|
import { styleNumbering } from "./labels.js";
|
|
5
6
|
import { guarded, readPartText } from "./package.js";
|
|
6
7
|
import { createStoryState, endStory, readParagraph, walkBlocks } from "./story.js";
|
|
7
8
|
import { TemplatePlanError } from "./types.js";
|
|
8
|
-
import { integerOrNull, isW, readRawPart, twipsOrNull, wAttr, wChild,
|
|
9
|
+
import { integerOrNull, isW, readRawPart, twipsOrNull, wAttr, wChild, wChildren, walkElements } from "./xml.js";
|
|
9
10
|
import { Result } from "better-result";
|
|
10
11
|
// src/docx/server/templatePlan/inspect.ts
|
|
11
12
|
/** A template's inventory: what a plan may name when it places blocks onto it. */
|
|
12
13
|
const DEFAULT_LEVEL_START = 1;
|
|
13
|
-
/** The `w:jc` each style of the styles part states itself, by style id. */
|
|
14
|
-
const statedAlignments = ({ stylesPath, stylesXml }) => {
|
|
15
|
-
const alignments = /* @__PURE__ */ new Map();
|
|
16
|
-
const part = stylesPath === null || stylesXml === null ? null : readRawPart(stylesPath, stylesXml);
|
|
17
|
-
for (const style of wChildren(part?.root, "style")) {
|
|
18
|
-
const styleId = wAttr(style, "styleId");
|
|
19
|
-
const alignment = wChildVal(wChild(style, "pPr"), "jc");
|
|
20
|
-
if (styleId !== null && alignment !== null) alignments.set(styleId, alignment);
|
|
21
|
-
}
|
|
22
|
-
return alignments;
|
|
23
|
-
};
|
|
24
14
|
/** The indent each level of the numbering part states, by definition and level. */
|
|
25
15
|
const statedIndents = ({ numberingPath, numberingXml }) => {
|
|
26
16
|
const indents = /* @__PURE__ */ new Map();
|
|
@@ -43,21 +33,11 @@ const NO_INDENT = {
|
|
|
43
33
|
};
|
|
44
34
|
const inspectStyles = (analyzed) => {
|
|
45
35
|
const { styles, numbering } = analyzed;
|
|
46
|
-
const stated = statedAlignments(analyzed);
|
|
47
|
-
|
|
48
|
-
const alignmentOf = (styleId) => {
|
|
49
|
-
const seen = /* @__PURE__ */ new Set();
|
|
50
|
-
let cursor = styleId;
|
|
51
|
-
while (cursor !== void 0 && !seen.has(cursor)) {
|
|
52
|
-
seen.add(cursor);
|
|
53
|
-
const alignment = stated.get(cursor);
|
|
54
|
-
if (alignment !== void 0) return alignment;
|
|
55
|
-
cursor = styles.get(cursor)?.basedOn;
|
|
56
|
-
}
|
|
57
|
-
return null;
|
|
58
|
-
};
|
|
36
|
+
const stated = statedAlignments(analyzed.stylesPath, analyzed.stylesXml);
|
|
37
|
+
const looks = statedLooks(analyzed.stylesPath, analyzed.stylesXml);
|
|
59
38
|
return [...styles.values()].map((style) => {
|
|
60
39
|
const bound = styleNumbering(style.styleId, styles, numbering);
|
|
40
|
+
const { bold, size, keepNext, indentLeft } = styleLook(style.styleId, styles, looks);
|
|
61
41
|
return {
|
|
62
42
|
styleId: style.styleId,
|
|
63
43
|
name: style.name ?? null,
|
|
@@ -68,7 +48,11 @@ const inspectStyles = (analyzed) => {
|
|
|
68
48
|
ilvl: bound.ilvl ?? 0
|
|
69
49
|
} : null,
|
|
70
50
|
outlineLvl: styleOutlineLevel(style),
|
|
71
|
-
alignment:
|
|
51
|
+
alignment: styleAlignment(style.styleId, styles, stated),
|
|
52
|
+
bold,
|
|
53
|
+
size,
|
|
54
|
+
keepNext,
|
|
55
|
+
indentLeft,
|
|
72
56
|
isDefault: style.default === true
|
|
73
57
|
};
|
|
74
58
|
});
|
|
@@ -99,35 +83,25 @@ const inspectNumbering = (analyzed) => {
|
|
|
99
83
|
}))
|
|
100
84
|
};
|
|
101
85
|
};
|
|
102
|
-
const inspectSections = ({ story, pkg }) =>
|
|
103
|
-
const properties = parseSectionProperties(sectPr);
|
|
86
|
+
const inspectSections = ({ story, pkg }) => {
|
|
104
87
|
const partOf = (rId) => {
|
|
105
88
|
const relationship = pkg.documentRelationships.get(rId);
|
|
106
89
|
return relationship === void 0 ? null : pkg.resolveDocumentTarget(relationship.target);
|
|
107
90
|
};
|
|
108
|
-
return {
|
|
109
|
-
index
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
type,
|
|
123
|
-
part: partOf(rId)
|
|
124
|
-
})),
|
|
125
|
-
footers: (properties.footerReferences ?? []).map(({ type, rId }) => ({
|
|
126
|
-
type,
|
|
127
|
-
part: partOf(rId)
|
|
128
|
-
}))
|
|
129
|
-
};
|
|
130
|
-
});
|
|
91
|
+
return storySections(story).map((section) => {
|
|
92
|
+
const properties = parseSectionProperties(story.sections[section.index] ?? null);
|
|
93
|
+
return Object.assign(section, {
|
|
94
|
+
headers: (properties.headerReferences ?? []).map(({ type, rId }) => ({
|
|
95
|
+
type,
|
|
96
|
+
part: partOf(rId)
|
|
97
|
+
})),
|
|
98
|
+
footers: (properties.footerReferences ?? []).map(({ type, rId }) => ({
|
|
99
|
+
type,
|
|
100
|
+
part: partOf(rId)
|
|
101
|
+
}))
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
};
|
|
131
105
|
const fieldOf = (part, { instruction, kind, result }) => ({
|
|
132
106
|
part,
|
|
133
107
|
instruction: instruction.trim(),
|
|
@@ -209,8 +183,21 @@ const inspectAnalyzedTemplate = async (analyzed) => {
|
|
|
209
183
|
fields.push(...partFields(part).map((field) => fieldOf(part.path, field)));
|
|
210
184
|
bookmarks.push(...bookmarksOf(part));
|
|
211
185
|
}
|
|
186
|
+
const effectParts = [
|
|
187
|
+
document,
|
|
188
|
+
...[[analyzed.numberingPath, analyzed.numberingXml], [analyzed.stylesPath, analyzed.stylesXml]].flatMap(([path, xml]) => {
|
|
189
|
+
const part = path === null || xml === null ? null : readRawPart(path, xml);
|
|
190
|
+
return part === null ? [] : [part];
|
|
191
|
+
}),
|
|
192
|
+
...headersAndFooters.value
|
|
193
|
+
];
|
|
212
194
|
return Result.ok({
|
|
213
195
|
...manifest,
|
|
196
|
+
invisibleEffects: effectParts.flatMap((part) => findInvisibleEffects(part).map(({ effect, owner }) => ({
|
|
197
|
+
part: part.path,
|
|
198
|
+
effect,
|
|
199
|
+
owner
|
|
200
|
+
}))),
|
|
214
201
|
styles: inspectStyles(analyzed),
|
|
215
202
|
numbering: inspectNumbering(analyzed),
|
|
216
203
|
fields,
|
|
@@ -15,7 +15,8 @@ export type ParagraphLabel = {
|
|
|
15
15
|
/**
|
|
16
16
|
* The label and what its list puts after it, when the label can stand as
|
|
17
17
|
* text: it reads the same wherever the file is opened. Null for a bullet,
|
|
18
|
-
* whose glyph belongs to a font,
|
|
18
|
+
* whose glyph belongs to a font, for a number a language spells out, and
|
|
19
|
+
* for an ordinal in a language whose way of writing it is not known.
|
|
19
20
|
*/
|
|
20
21
|
asText: {
|
|
21
22
|
label: string;
|
|
@@ -32,6 +33,8 @@ export type LabelCounter = {
|
|
|
32
33
|
next: (paragraph: {
|
|
33
34
|
styleId: string | null;
|
|
34
35
|
numPr: ParagraphNumberingOverride | undefined;
|
|
36
|
+
/** The language the paragraph mark states itself, or null. */
|
|
37
|
+
language?: string | null;
|
|
35
38
|
}) => ParagraphLabel;
|
|
36
39
|
};
|
|
37
40
|
type LabelCounterOptions = {
|
|
@@ -39,7 +42,9 @@ type LabelCounterOptions = {
|
|
|
39
42
|
styles: StyleMap;
|
|
40
43
|
/** The style a paragraph without `w:pStyle` takes. */
|
|
41
44
|
defaultStyleId: string | null;
|
|
45
|
+
/** The language the document defaults give every run. */
|
|
46
|
+
defaultLanguage?: string | null;
|
|
42
47
|
};
|
|
43
48
|
/** A counter over one story; call `next` for every paragraph in document order. */
|
|
44
|
-
export declare const createLabelCounter: ({ numbering, styles, defaultStyleId }: LabelCounterOptions) => LabelCounter;
|
|
49
|
+
export declare const createLabelCounter: ({ numbering, styles, defaultStyleId, defaultLanguage }: LabelCounterOptions) => LabelCounter;
|
|
45
50
|
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { bulletMarkerFontName, bulletTextFace } from "../../bulletMarkers.js";
|
|
1
2
|
import { computeListMarker } from "../../listMarkerComputation.js";
|
|
2
3
|
import { resolveListTemplateWithComponents } from "../../listTemplate.js";
|
|
3
4
|
import { computeListRendering } from "../../numberingParser.js";
|
|
@@ -25,11 +26,24 @@ const PLAIN_FORMATS = /* @__PURE__ */ new Set([
|
|
|
25
26
|
"lowerLetter"
|
|
26
27
|
]);
|
|
27
28
|
const LEVEL_PLACEHOLDER = /%([1-9])/gu;
|
|
28
|
-
|
|
29
|
+
/**
|
|
30
|
+
* What a block says of a bullet level: that it is one, and the text face its
|
|
31
|
+
* mark is a character of. `mark` is the level's own text, before it is read
|
|
32
|
+
* as the glyph it paints.
|
|
33
|
+
*/
|
|
34
|
+
const bulletFacts = ({ isBullet, markerFormatting }, mark) => {
|
|
35
|
+
if (!isBullet) return {};
|
|
36
|
+
const face = bulletTextFace(mark, bulletMarkerFontName(markerFormatting));
|
|
37
|
+
return face === void 0 ? { bullet: true } : {
|
|
38
|
+
bullet: true,
|
|
39
|
+
bulletFont: face
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
const labelAsText = ({ label, template, levelFormats, suffix, ordinalKnown }) => {
|
|
29
43
|
if (label.trim() === "") return null;
|
|
30
44
|
for (const [, digit] of template.matchAll(LEVEL_PLACEHOLDER)) {
|
|
31
45
|
const format = levelFormats?.[Number(digit) - 1];
|
|
32
|
-
if (format
|
|
46
|
+
if (!(format !== void 0 && (PLAIN_FORMATS.has(format) || format === "ordinal" && ordinalKnown))) return null;
|
|
33
47
|
}
|
|
34
48
|
return {
|
|
35
49
|
label,
|
|
@@ -62,17 +76,69 @@ const styleNumbering = (styleId, styles, numbering) => {
|
|
|
62
76
|
return stated;
|
|
63
77
|
};
|
|
64
78
|
const stripTrailingPeriods = (value) => value.replace(/\.+$/u, "");
|
|
65
|
-
/**
|
|
66
|
-
|
|
67
|
-
|
|
79
|
+
/**
|
|
80
|
+
* The `ordinal` format by the language of the paragraph mark, as the
|
|
81
|
+
* reference consumer prints it: Czech and German write the number with a
|
|
82
|
+
* period, French `1er` and `2e`, English `1st`. A language not listed here
|
|
83
|
+
* has no entry: its ordinals are not known to be any of these.
|
|
84
|
+
*/
|
|
85
|
+
const ORDINALS = {
|
|
86
|
+
cs: (value) => `${String(value)}.`,
|
|
87
|
+
de: (value) => `${String(value)}.`,
|
|
88
|
+
fr: (value) => value === 1 ? "1er" : `${String(value)}e`
|
|
89
|
+
};
|
|
90
|
+
const primaryLanguage = (language) => language === null ? null : language.split(/[-_]/u).at(0)?.toLowerCase() ?? null;
|
|
91
|
+
/** A level text over its counters, ordinals written by the language. */
|
|
92
|
+
const renderLabel = ({ template, counters, levelFormats, forceDecimal, language }) => {
|
|
93
|
+
const rendered = resolveListTemplateWithComponents({
|
|
68
94
|
template,
|
|
69
95
|
counters,
|
|
70
96
|
levelFormats,
|
|
71
97
|
forceDecimal
|
|
72
98
|
});
|
|
99
|
+
const isOrdinal = (level) => !forceDecimal && levelFormats?.[level] === "ordinal";
|
|
100
|
+
const hasOrdinal = rendered.components.some(({ level }) => isOrdinal(level));
|
|
101
|
+
const primary = primaryLanguage(language);
|
|
102
|
+
const ordinal = primary === null ? void 0 : ORDINALS[primary];
|
|
103
|
+
if (!hasOrdinal || ordinal === void 0) return {
|
|
104
|
+
...rendered,
|
|
105
|
+
byLanguage: hasOrdinal,
|
|
106
|
+
known: !hasOrdinal || primary === "en"
|
|
107
|
+
};
|
|
108
|
+
let value = "";
|
|
109
|
+
let cursor = 0;
|
|
110
|
+
const components = rendered.components.map((component) => {
|
|
111
|
+
const { level, start, end } = component;
|
|
112
|
+
value += rendered.value.slice(cursor, start);
|
|
113
|
+
cursor = end;
|
|
114
|
+
const written = isOrdinal(level) ? ordinal(counters[level] ?? 0) : rendered.value.slice(start, end);
|
|
115
|
+
const moved = {
|
|
116
|
+
...component,
|
|
117
|
+
start: value.length
|
|
118
|
+
};
|
|
119
|
+
value += written;
|
|
120
|
+
return {
|
|
121
|
+
...moved,
|
|
122
|
+
end: value.length
|
|
123
|
+
};
|
|
124
|
+
});
|
|
125
|
+
value += rendered.value.slice(cursor);
|
|
126
|
+
return {
|
|
127
|
+
value,
|
|
128
|
+
components,
|
|
129
|
+
byLanguage: true,
|
|
130
|
+
known: true
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* Drop the literal runs of a level text that hold a letter. Of the others
|
|
135
|
+
* a `\t` field keeps the delimiters and drops the blanks: `Part %1 -` gives
|
|
136
|
+
* `B-`.
|
|
137
|
+
*/
|
|
138
|
+
const numberOnlyLabel = ({ value, components }) => {
|
|
73
139
|
let out = "";
|
|
74
140
|
let cursor = 0;
|
|
75
|
-
const literal = (text) => /\p{L}/u.test(text) ? "" : text;
|
|
141
|
+
const literal = (text) => /\p{L}/u.test(text) ? "" : text.replaceAll(/\s+/gu, "");
|
|
76
142
|
for (const { start, end } of components) {
|
|
77
143
|
out += literal(value.slice(cursor, start)) + value.slice(start, end);
|
|
78
144
|
cursor = end;
|
|
@@ -80,20 +146,47 @@ const numberOnlyLabel = ({ template, counters, levelFormats, forceDecimal }) =>
|
|
|
80
146
|
out += literal(value.slice(cursor));
|
|
81
147
|
return stripTrailingPeriods(out.trim());
|
|
82
148
|
};
|
|
149
|
+
/**
|
|
150
|
+
* The language each style gives a paragraph mark: its own, or the one of
|
|
151
|
+
* the nearest style it is based on. Resolved once per style, so a long
|
|
152
|
+
* `basedOn` chain is walked once however many paragraphs use it.
|
|
153
|
+
*/
|
|
154
|
+
const createStyleLanguages = (styles) => {
|
|
155
|
+
const resolved = /* @__PURE__ */ new Map();
|
|
156
|
+
return (styleId) => {
|
|
157
|
+
if (styleId === null) return null;
|
|
158
|
+
const walked = /* @__PURE__ */ new Set();
|
|
159
|
+
let language = null;
|
|
160
|
+
let cursor = styleId;
|
|
161
|
+
while (cursor !== void 0 && !walked.has(cursor)) {
|
|
162
|
+
const known = resolved.get(cursor);
|
|
163
|
+
if (known !== void 0) {
|
|
164
|
+
language = known;
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
walked.add(cursor);
|
|
168
|
+
const style = styles.get(cursor);
|
|
169
|
+
const stated = style?.rPr?.language?.val;
|
|
170
|
+
if (stated !== void 0) {
|
|
171
|
+
language = stated;
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
cursor = style?.basedOn;
|
|
175
|
+
}
|
|
176
|
+
for (const id of walked) resolved.set(id, language);
|
|
177
|
+
return language;
|
|
178
|
+
};
|
|
179
|
+
};
|
|
83
180
|
/** A counter over one story; call `next` for every paragraph in document order. */
|
|
84
|
-
const createLabelCounter = ({ numbering, styles, defaultStyleId }) => {
|
|
181
|
+
const createLabelCounter = ({ numbering, styles, defaultStyleId, defaultLanguage = null }) => {
|
|
85
182
|
const counters = {
|
|
86
183
|
numbering,
|
|
87
184
|
listCounters: /* @__PURE__ */ new Map(),
|
|
88
185
|
abstractCounters: /* @__PURE__ */ new Map(),
|
|
89
|
-
|
|
90
|
-
previousList: {
|
|
91
|
-
abstractNumId: null,
|
|
92
|
-
fromStyle: false,
|
|
93
|
-
numId: null
|
|
94
|
-
}
|
|
186
|
+
startedLevels: /* @__PURE__ */ new Set()
|
|
95
187
|
};
|
|
96
|
-
|
|
188
|
+
const styleLanguage = createStyleLanguages(styles);
|
|
189
|
+
return { next: ({ styleId, numPr, language = null }) => {
|
|
97
190
|
const fromStyle = styleNumbering(styleId ?? defaultStyleId, styles, numbering);
|
|
98
191
|
const inherits = fromStyle !== void 0 && (numPr === void 0 || numPr.kind === "levelOnly");
|
|
99
192
|
const effective = inherits ? mergeParagraphNumbering(fromStyle, numPr) : numPr;
|
|
@@ -116,11 +209,19 @@ const createLabelCounter = ({ numbering, styles, defaultStyleId }) => {
|
|
|
116
209
|
const advance = computeListMarker(paragraph, counters);
|
|
117
210
|
if (advance === null || listRendering === null || numbering === null || resolved.kind !== "reference") return NO_LABEL;
|
|
118
211
|
const abstractNumId = numbering.getAbstractNumId(resolved.numId);
|
|
119
|
-
const
|
|
212
|
+
const rendered = renderLabel({
|
|
213
|
+
template,
|
|
214
|
+
counters: advance.counters,
|
|
215
|
+
levelFormats: listRendering.levelNumFmts,
|
|
216
|
+
forceDecimal: listRendering.isLegal === true,
|
|
217
|
+
language: language ?? styleLanguage(styleId ?? defaultStyleId) ?? defaultLanguage
|
|
218
|
+
});
|
|
219
|
+
const label = rendered.byLanguage && rendered.known ? rendered.value : listRendering.marker;
|
|
120
220
|
const numberingInfo = abstractNumId === null ? null : {
|
|
121
221
|
numId: resolved.numId,
|
|
122
222
|
ilvl: resolved.ilvl,
|
|
123
|
-
abstractNumId
|
|
223
|
+
abstractNumId,
|
|
224
|
+
...bulletFacts(listRendering, template)
|
|
124
225
|
};
|
|
125
226
|
if (listRendering.markerHidden === true) return {
|
|
126
227
|
...NO_LABEL,
|
|
@@ -140,15 +241,11 @@ const createLabelCounter = ({ numbering, styles, defaultStyleId }) => {
|
|
|
140
241
|
label,
|
|
141
242
|
template,
|
|
142
243
|
levelFormats: listRendering.levelNumFmts,
|
|
143
|
-
suffix: listRendering.markerSuffix
|
|
244
|
+
suffix: listRendering.markerSuffix,
|
|
245
|
+
ordinalKnown: rendered.known
|
|
144
246
|
}),
|
|
145
247
|
paragraphNumber: stripTrailingPeriods(label.trim()),
|
|
146
|
-
numberOnly: numberOnlyLabel(
|
|
147
|
-
template,
|
|
148
|
-
counters: advance.counters,
|
|
149
|
-
levelFormats: listRendering.levelNumFmts,
|
|
150
|
-
forceDecimal: listRendering.isLegal === true
|
|
151
|
-
})
|
|
248
|
+
numberOnly: numberOnlyLabel(rendered)
|
|
152
249
|
};
|
|
153
250
|
} };
|
|
154
251
|
};
|
|
@@ -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, TemplatePlanError, TemplatePlanOmitReason, TemplatePlanReference } from "./types.js";
|
|
12
|
+
import { TemplatePlan, TemplatePlanAlignment, TemplatePlanError, TemplatePlanIndent, TemplatePlanOmitReason, TemplatePlanReference, TemplatePlanSection } from "./types.js";
|
|
13
13
|
import { Result } from "better-result";
|
|
14
14
|
export type ExpectedPiece = {
|
|
15
15
|
kind: AtomKind;
|
|
@@ -67,10 +67,30 @@ export type ResolvedParagraph = {
|
|
|
67
67
|
signatures: string[];
|
|
68
68
|
inlineObjects: number;
|
|
69
69
|
placement: "body" | "nested" | "slot";
|
|
70
|
+
/** Whether the paragraph starts on a new page. */
|
|
71
|
+
pageBreakBefore: boolean;
|
|
72
|
+
/** Whether the paragraph is kept with the one after it. */
|
|
73
|
+
keepNext: boolean;
|
|
74
|
+
/** The paragraph's own indent, or null. */
|
|
75
|
+
indent: TemplatePlanIndent | null;
|
|
76
|
+
/** The paragraph's own left tab stops, or null. */
|
|
77
|
+
tabStops: readonly number[] | null;
|
|
78
|
+
/** The paragraph's own alignment, or null. */
|
|
79
|
+
alignment: TemplatePlanAlignment | null;
|
|
80
|
+
/** The section the paragraph is the last of, or null. */
|
|
81
|
+
endsSection: TemplatePlanSection | null;
|
|
70
82
|
};
|
|
71
83
|
export type ResolvedItem = {
|
|
72
84
|
kind: "template";
|
|
73
85
|
block: AnalyzedBlock;
|
|
86
|
+
} |
|
|
87
|
+
/**
|
|
88
|
+
* An empty paragraph the writer adds, in no plan: between two tables that
|
|
89
|
+
* would otherwise stand next to each other and read as one, and after a
|
|
90
|
+
* table that would end the body.
|
|
91
|
+
*/
|
|
92
|
+
{
|
|
93
|
+
kind: "separator";
|
|
74
94
|
} | {
|
|
75
95
|
kind: "paragraph";
|
|
76
96
|
paragraph: ResolvedParagraph;
|
|
@@ -112,8 +132,9 @@ export type ResolvedPlan = {
|
|
|
112
132
|
/**
|
|
113
133
|
* Whether `label` reads as a manual list label: up to three leading words
|
|
114
134
|
* ("Article", "§", "Annex No.") and one designator, a number, a roman numeral
|
|
115
|
-
* or a letter with its brackets and punctuation; or a single bullet
|
|
116
|
-
*
|
|
135
|
+
* or a letter with its brackets and punctuation; or a single bullet; or a
|
|
136
|
+
* number whose parts stand apart (`1. 1.` for `1.1.`). This is the only text
|
|
137
|
+
* a plan may have removed.
|
|
117
138
|
*/
|
|
118
139
|
export declare const isManualLabel: (label: string) => boolean;
|
|
119
140
|
/** Whether a block holds no text and no object. */
|
|
@@ -6,7 +6,7 @@ import { emphasisDeviation, emphasisSignature, paragraphBaseline, readDirectEmph
|
|
|
6
6
|
import { styleNumbering } from "./labels.js";
|
|
7
7
|
import { PLAN_HIGHLIGHT_COLORS, planShapeIssue } from "./planShape.js";
|
|
8
8
|
import { TemplatePlanError } from "./types.js";
|
|
9
|
-
import { isW, maxOf, wAttr, wChildVal, walkElements } from "./xml.js";
|
|
9
|
+
import { isW, maxOf, wAttr, wChild, wChildVal, walkElements } from "./xml.js";
|
|
10
10
|
import { Result } from "better-result";
|
|
11
11
|
// src/docx/server/templatePlan/plan.ts
|
|
12
12
|
/**
|
|
@@ -27,16 +27,19 @@ const ROMAN_NUMERAL = /^(?=.)M{0,3}(?:CM|CD|D?C{0,3})(?:XC|XL|L?X{0,3})(?:IX|IV|
|
|
|
27
27
|
const LABEL_WORD = /^(?:\p{L}[\p{L}\p{M}]*\.?|§{1,2}|№|#)$/u;
|
|
28
28
|
const LABEL_DESIGNATOR = /^[([]?(?<core>\d+(?:[.\-\u2013]\d+)*[a-z]?|\p{L}+)[)\]]?[.:)]*$/u;
|
|
29
29
|
const LABEL_BULLET = /^[-\u2013\u2014\u2022\u00B7\u25AA\u25E6*]$/u;
|
|
30
|
+
/** A number of several parts typed with blanks between them: `1. 1.`. */
|
|
31
|
+
const LABEL_SPACED_NUMBER = /^\d{1,3}\.(?:[ \u00A0]+\d{1,3}\.){1,3}$/u;
|
|
30
32
|
const MAX_LABEL_WORDS = 3;
|
|
31
33
|
/**
|
|
32
34
|
* Whether `label` reads as a manual list label: up to three leading words
|
|
33
35
|
* ("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
|
-
*
|
|
36
|
+
* or a letter with its brackets and punctuation; or a single bullet; or a
|
|
37
|
+
* number whose parts stand apart (`1. 1.` for `1.1.`). This is the only text
|
|
38
|
+
* a plan may have removed.
|
|
36
39
|
*/
|
|
37
40
|
const isManualLabel = (label) => {
|
|
38
41
|
if (label === "" || label.length > MAX_LABEL_LENGTH) return false;
|
|
39
|
-
if (LABEL_BULLET.test(label)) return true;
|
|
42
|
+
if (LABEL_BULLET.test(label) || LABEL_SPACED_NUMBER.test(label)) return true;
|
|
40
43
|
const tokens = label.split(/[ \u00A0]/u);
|
|
41
44
|
const designator = tokens.at(-1) ?? "";
|
|
42
45
|
const words = tokens.slice(0, -1);
|
|
@@ -48,6 +51,8 @@ const NOTES_OF_REFERENCE = {
|
|
|
48
51
|
endnoteReference: "endnotes"
|
|
49
52
|
};
|
|
50
53
|
const LABEL_SPACE = /^[ \t ]+/u;
|
|
54
|
+
/** The blank behind a label when a line break behind it goes too. */
|
|
55
|
+
const LABEL_SPACE_AND_BREAK = /^[ \t ]*(?:\n[ \t ]*)?/u;
|
|
51
56
|
const LEADING_SPACE = /^[ \t ]*/u;
|
|
52
57
|
/** Whether a block holds no text and no object. */
|
|
53
58
|
const isBlankBlock = ({ block }) => block.text.trim() === "" && block.inlineObjects === 0;
|
|
@@ -69,6 +74,8 @@ const hyperlinkFieldLink = ({ instruction, kind }) => {
|
|
|
69
74
|
const NOTE_REFERENCE_KINDS = /* @__PURE__ */ new Set(["footnoteReference", "endnoteReference"]);
|
|
70
75
|
/** What a stripped label may consist of. */
|
|
71
76
|
const STRIPPABLE_KINDS = /* @__PURE__ */ new Set(["text", "tab"]);
|
|
77
|
+
/** The same when a line break behind the label goes with it. */
|
|
78
|
+
const STRIPPABLE_WITH_BREAK = /* @__PURE__ */ new Set([...STRIPPABLE_KINDS, "lineBreak"]);
|
|
72
79
|
/**
|
|
73
80
|
* Character styles that only give a link its look. The template supplies
|
|
74
81
|
* that look; any other character style inside a link is emphasis.
|
|
@@ -157,7 +164,8 @@ const spansOverlap = (spans) => {
|
|
|
157
164
|
return previous !== void 0 && span.start < previous.end;
|
|
158
165
|
});
|
|
159
166
|
};
|
|
160
|
-
const partSegments = ({ block, pieces, strippedLength, references, highlights }) => {
|
|
167
|
+
const partSegments = ({ block, pieces, strippedLength, strippedBreak, references, highlights }) => {
|
|
168
|
+
const strippable = strippedBreak ? STRIPPABLE_WITH_BREAK : STRIPPABLE_KINDS;
|
|
161
169
|
const blockId = block.block.id;
|
|
162
170
|
const length = block.block.text.length;
|
|
163
171
|
const badReference = (message) => Result.err(refuse({
|
|
@@ -192,7 +200,7 @@ const partSegments = ({ block, pieces, strippedLength, references, highlights })
|
|
|
192
200
|
for (const entry of split) {
|
|
193
201
|
const empty = entry.start === entry.end;
|
|
194
202
|
if (entry.end <= strippedLength && !empty) {
|
|
195
|
-
if (!
|
|
203
|
+
if (!strippable.has(entry.piece.kind)) return Result.err(refuse({
|
|
196
204
|
code: "strip-label-mismatch",
|
|
197
205
|
message: `The label to strip from block ${blockId} covers more than text.`,
|
|
198
206
|
blockId
|
|
@@ -300,6 +308,15 @@ const piecesContent = (pieces) => {
|
|
|
300
308
|
signatures
|
|
301
309
|
};
|
|
302
310
|
};
|
|
311
|
+
const isTableItem = (item) => item.kind === "table" || item.kind === "template" && item.block.block.kind === "table";
|
|
312
|
+
/** Puts a separator between two neighbouring tables and after a last one. */
|
|
313
|
+
const partTables = (items) => {
|
|
314
|
+
for (let index = items.length - 1; index >= 0; index -= 1) {
|
|
315
|
+
const item = items[index];
|
|
316
|
+
const next = items[index + 1];
|
|
317
|
+
if (item !== void 0 && isTableItem(item) && (next === void 0 || isTableItem(next))) items.splice(index + 1, 0, { kind: "separator" });
|
|
318
|
+
}
|
|
319
|
+
};
|
|
303
320
|
const plainPiece = (kind, text) => ({
|
|
304
321
|
kind,
|
|
305
322
|
text,
|
|
@@ -452,7 +469,7 @@ const resolvePlan = (source, template, plan) => {
|
|
|
452
469
|
placed.add(id);
|
|
453
470
|
return Result.ok(void 0);
|
|
454
471
|
};
|
|
455
|
-
const resolveParagraph = ({ parts, separators, styleId, numbering, placement, ordinal }) => {
|
|
472
|
+
const resolveParagraph = ({ parts, separators, styleId, numbering, placement, ordinal, pageBreakBefore = false, keepNext = false, indent, tabStops, alignment, endsSection }) => {
|
|
456
473
|
const first = parts.at(0);
|
|
457
474
|
if (first === void 0) return invalid("A plan item names no source block.");
|
|
458
475
|
const firstId = first.block.block.id;
|
|
@@ -468,7 +485,7 @@ const resolvePlan = (source, template, plan) => {
|
|
|
468
485
|
const segments = [];
|
|
469
486
|
const resolvedParts = [];
|
|
470
487
|
for (const [index, planned] of parts.entries()) {
|
|
471
|
-
const { block, stripLabel } = planned;
|
|
488
|
+
const { block, stripLabel, stripLabelBreak } = planned;
|
|
472
489
|
const { id, text } = block.block;
|
|
473
490
|
if (block.read === null) return invalid(`Block ${id} is a table and cannot be joined or slotted.`);
|
|
474
491
|
const placedOnce = place(block);
|
|
@@ -484,7 +501,8 @@ const resolvePlan = (source, template, plan) => {
|
|
|
484
501
|
message: `Block ${id} does not start with the label to strip.`,
|
|
485
502
|
blockId: id
|
|
486
503
|
}));
|
|
487
|
-
|
|
504
|
+
const blank = stripLabelBreak === true ? LABEL_SPACE_AND_BREAK : LABEL_SPACE;
|
|
505
|
+
strippedPrefix = text.slice(0, labelEnd + (blank.exec(text.slice(labelEnd))?.[0].length ?? 0));
|
|
488
506
|
}
|
|
489
507
|
const part = partSegments({
|
|
490
508
|
block,
|
|
@@ -495,6 +513,7 @@ const resolvePlan = (source, template, plan) => {
|
|
|
495
513
|
fields: source.story.state.fields
|
|
496
514
|
}),
|
|
497
515
|
strippedLength: strippedPrefix.length,
|
|
516
|
+
strippedBreak: stripLabelBreak === true,
|
|
498
517
|
references: referencesByBlock.get(id) ?? [],
|
|
499
518
|
highlights: highlightsByBlock.get(id) ?? []
|
|
500
519
|
});
|
|
@@ -543,7 +562,13 @@ const resolvePlan = (source, template, plan) => {
|
|
|
543
562
|
segments,
|
|
544
563
|
...piecesContent(pieces),
|
|
545
564
|
inlineObjects: pieces.filter(({ kind }) => kind === "object").length,
|
|
546
|
-
placement
|
|
565
|
+
placement,
|
|
566
|
+
pageBreakBefore,
|
|
567
|
+
keepNext,
|
|
568
|
+
indent: indent ?? null,
|
|
569
|
+
tabStops: tabStops ?? null,
|
|
570
|
+
alignment: alignment ?? null,
|
|
571
|
+
endsSection: endsSection ?? null
|
|
547
572
|
};
|
|
548
573
|
for (const { block } of resolvedParts) byBlockId.set(block.block.id, paragraph);
|
|
549
574
|
return Result.ok(paragraph);
|
|
@@ -559,7 +584,7 @@ const resolvePlan = (source, template, plan) => {
|
|
|
559
584
|
};
|
|
560
585
|
const resolveTable = (block, item, tableOrdinal) => {
|
|
561
586
|
const { id } = block.block;
|
|
562
|
-
if (item.mergeNext !== void 0 || item.stripLabel !== void 0 || item.labelAsText !== void 0 || item.numbering !== void 0) return invalid(`Table ${id} takes a style and nested placements only.`);
|
|
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.`);
|
|
563
588
|
if (item.styleId !== void 0 && template.styles.get(item.styleId)?.type !== "table") return Result.err(refuse({
|
|
564
589
|
code: "style-unknown",
|
|
565
590
|
message: `The template has no table style ${item.styleId}.`,
|
|
@@ -588,7 +613,11 @@ const resolvePlan = (source, template, plan) => {
|
|
|
588
613
|
styleId: override?.styleId ?? item.cellStyleId,
|
|
589
614
|
numbering: override?.numbering,
|
|
590
615
|
placement: "nested",
|
|
591
|
-
ordinal: tableOrdinal * 1e6 + nested.block.index
|
|
616
|
+
ordinal: tableOrdinal * 1e6 + nested.block.index,
|
|
617
|
+
keepNext: override?.keepNext === true,
|
|
618
|
+
indent: override?.indent,
|
|
619
|
+
tabStops: override?.tabStops,
|
|
620
|
+
alignment: override?.alignment
|
|
592
621
|
});
|
|
593
622
|
if (Result.isError(paragraph)) return paragraph;
|
|
594
623
|
cells.set(nested.element, paragraph.value);
|
|
@@ -656,6 +685,7 @@ const resolvePlan = (source, template, plan) => {
|
|
|
656
685
|
const parts = [{
|
|
657
686
|
block: block.value,
|
|
658
687
|
stripLabel: item.stripLabel,
|
|
688
|
+
stripLabelBreak: item.stripLabelBreak === true,
|
|
659
689
|
labelAsText: item.labelAsText === true
|
|
660
690
|
}];
|
|
661
691
|
const separators = [];
|
|
@@ -673,15 +703,16 @@ const resolvePlan = (source, template, plan) => {
|
|
|
673
703
|
message: `Block ${next.blockId} does not have the hash the plan pins.`,
|
|
674
704
|
blockId: next.blockId
|
|
675
705
|
}));
|
|
676
|
-
if (next.styleId !== void 0 || next.numbering !== void 0 || next.cellStyleId !== void 0 || next.nested !== void 0) return Result.err(refuse({
|
|
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({
|
|
677
707
|
code: "merge-invalid",
|
|
678
|
-
message: `Block ${next.blockId} joins the paragraph before it and cannot carry a style
|
|
708
|
+
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.`,
|
|
679
709
|
blockId: next.blockId
|
|
680
710
|
}));
|
|
681
711
|
separators.push(merge);
|
|
682
712
|
parts.push({
|
|
683
713
|
block: nextBlock.value,
|
|
684
714
|
stripLabel: next.stripLabel,
|
|
715
|
+
stripLabelBreak: next.stripLabelBreak === true,
|
|
685
716
|
labelAsText: next.labelAsText === true
|
|
686
717
|
});
|
|
687
718
|
merge = next.mergeNext;
|
|
@@ -693,7 +724,13 @@ const resolvePlan = (source, template, plan) => {
|
|
|
693
724
|
styleId: item.styleId,
|
|
694
725
|
numbering: item.numbering,
|
|
695
726
|
placement: "body",
|
|
696
|
-
ordinal
|
|
727
|
+
ordinal,
|
|
728
|
+
pageBreakBefore: item.pageBreakBefore === true,
|
|
729
|
+
keepNext: item.keepNext === true,
|
|
730
|
+
indent: item.indent,
|
|
731
|
+
tabStops: item.tabStops,
|
|
732
|
+
alignment: item.alignment,
|
|
733
|
+
endsSection: item.endsSection
|
|
697
734
|
});
|
|
698
735
|
if (Result.isError(paragraph)) return paragraph;
|
|
699
736
|
items.push({
|
|
@@ -756,6 +793,8 @@ const resolvePlan = (source, template, plan) => {
|
|
|
756
793
|
}));
|
|
757
794
|
nestedSlots.push(slot);
|
|
758
795
|
}
|
|
796
|
+
partTables(items);
|
|
797
|
+
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.");
|
|
759
798
|
const keptPosition = /* @__PURE__ */ new Map();
|
|
760
799
|
for (const [position, item] of items.entries()) if (item.kind === "template") keptPosition.set(item.block.block.id, position);
|
|
761
800
|
const templateOrder = template.story.topLevel.map(({ block }) => block.id);
|