@stll/folio-core 0.76.0 → 0.78.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/canonicalBatchReview.js +7 -6
- 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 +19 -40
- 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 +190 -194
- package/dist/compare/inline-provenance.js +8 -1
- 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/paragraphParser.js +1 -1
- package/dist/docx/reviewResolutionProvenance.d.ts +2 -0
- package/dist/docx/reviewResolutionProvenance.js +22 -2
- package/dist/docx/server/templatePlan/apply.js +47 -2
- package/dist/docx/server/templatePlan/blocks.d.ts +34 -7
- package/dist/docx/server/templatePlan/blocks.js +190 -13
- package/dist/docx/server/templatePlan/builders.d.ts +8 -1
- package/dist/docx/server/templatePlan/builders.js +21 -5
- 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 +26 -1
- package/dist/docx/server/templatePlan/plan.js +181 -21
- package/dist/docx/server/templatePlan/planShape.js +15 -3
- 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 +58 -1
- package/dist/docx/server/templatePlan/story.js +176 -12
- package/dist/docx/server/templatePlan/types.d.ts +153 -1
- package/dist/docx/server/templatePlan/verify.js +58 -15
- package/dist/docx/settingsHeaderFooterUpdate.d.ts +1 -1
- package/dist/docx/tableGridXml.d.ts +3 -7
- package/dist/docx/tableGridXml.js +23 -15
- package/dist/docx/tableParser.js +3 -1
- 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 +7 -9
- package/dist/prosemirror/conversion/markupViewSource.d.ts +17 -0
- package/dist/prosemirror/conversion/markupViewSource.js +11 -0
- package/dist/prosemirror/conversion/toProseDoc.d.ts +8 -0
- package/dist/prosemirror/conversion/toProseDoc.js +43 -19
- 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
|
@@ -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 [
|
|
@@ -132,11 +142,13 @@ const sourceItemIssue = (item, where) => {
|
|
|
132
142
|
"labelAsText",
|
|
133
143
|
"pageBreakBefore",
|
|
134
144
|
"keepNext",
|
|
135
|
-
"stripLabelBreak"
|
|
145
|
+
"stripLabelBreak",
|
|
146
|
+
"dropPageShapes"
|
|
136
147
|
]) if (!isOptionalBoolean(item[key])) return `${where} carries a malformed ${key}.`;
|
|
137
148
|
if (item["indent"] !== void 0 && !isIndent(item["indent"])) return `${where} carries a malformed indent.`;
|
|
138
149
|
if (item["tabStops"] !== void 0 && !isTabStops(item["tabStops"])) return `${where} carries malformed tab stops.`;
|
|
139
150
|
if (item["alignment"] !== void 0 && !isAlignment(item["alignment"])) return `${where} carries an unknown alignment.`;
|
|
151
|
+
if (item["spacing"] !== void 0 && !isSpacing(item["spacing"])) return `${where} carries a malformed spacing.`;
|
|
140
152
|
const merge = item["mergeNext"];
|
|
141
153
|
if (merge !== void 0 && !(isString(merge) && MERGES.has(merge))) return `${where} names an unknown merge.`;
|
|
142
154
|
const section = sectionIssue(item["endsSection"], where);
|
|
@@ -151,7 +163,7 @@ const sourceItemIssue = (item, where) => {
|
|
|
151
163
|
if (!isObject(entry) || !isString(entry["blockId"])) return `${where} carries a nested placement without a block.`;
|
|
152
164
|
if (seen.has(entry["blockId"])) return `${where} places nested block ${entry["blockId"]} twice.`;
|
|
153
165
|
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.`;
|
|
166
|
+
if (!isOptionalString(entry["styleId"]) || !isOptionalString(entry["stripLabel"]) || !isOptionalBoolean(entry["labelAsText"]) || !isOptionalBoolean(entry["keepNext"]) || !isOptionalBoolean(entry["dropPageShapes"]) || 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
167
|
const nestedNumbering = numberingIssue(entry["numbering"], where);
|
|
156
168
|
if (nestedNumbering !== null) return nestedNumbering;
|
|
157
169
|
}
|
|
@@ -229,6 +241,6 @@ const compatIssue = (compat) => {
|
|
|
229
241
|
/** Why `plan` is not a version 1 template plan, or null when it is one. */
|
|
230
242
|
const planShapeIssue = (plan) => {
|
|
231
243
|
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.");
|
|
244
|
+
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
245
|
};
|
|
234
246
|
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;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { spliceXml } from "../../selectiveXmlPatch.js";
|
|
2
2
|
import { loadPackage } from "./package.js";
|
|
3
3
|
import { TemplatePlanError } from "./types.js";
|
|
4
|
-
import { elementChildren, innerRangeOf, rangeOf, readRawPart, wAttr, wChild, wName } from "./xml.js";
|
|
4
|
+
import { elementChildren, escapeXmlAttribute, innerRangeOf, rangeOf, readRawPart, wAttr, wChild, wName } from "./xml.js";
|
|
5
5
|
import { Result } from "better-result";
|
|
6
6
|
import { ZipArchive } from "@stll/docx-core/zip";
|
|
7
7
|
// src/docx/server/templatePlan/revisions.ts
|
|
@@ -312,6 +312,280 @@ const summaryOf = (tally) => ({
|
|
|
312
312
|
first: tally.first,
|
|
313
313
|
last: tally.last
|
|
314
314
|
});
|
|
315
|
+
/**
|
|
316
|
+
* The text a deleted paragraph mark is carried as, inside a deletion of
|
|
317
|
+
* its own, by a reading that keeps tracked changes: a private-use character
|
|
318
|
+
* no document's text holds.
|
|
319
|
+
*/
|
|
320
|
+
const DELETED_PARAGRAPH_MARK = "";
|
|
321
|
+
/**
|
|
322
|
+
* The element a deleted table row is kept in by a reading that keeps
|
|
323
|
+
* tracked changes. The accepted view has no such row, so it may be no row
|
|
324
|
+
* of the table to the readers of blocks; in a namespace of its own it is
|
|
325
|
+
* none, and the writer and verification find it by this name.
|
|
326
|
+
*/
|
|
327
|
+
const KEPT_DELETED_ROW_NAMESPACE = "urn:stll:folio:kept-deleted-row";
|
|
328
|
+
const KEPT_DELETED_ROW = "keptDeletedRow";
|
|
329
|
+
/** The row a kept-deleted-row element holds, or null for any other element. */
|
|
330
|
+
const keptDeletedRowOf = (element) => element.namespaceUri === "urn:stll:folio:kept-deleted-row" ? elementChildren(element).find((child) => wName(child) === "tr") ?? null : null;
|
|
331
|
+
/** The deletion a row's properties record, or null. */
|
|
332
|
+
const deletedRowMarkOf = (row) => wChild(wChild(row, "trPr"), "del");
|
|
333
|
+
/** The insertion a row's properties record, or null. */
|
|
334
|
+
const insertedRowMarkOf = (row) => wChild(wChild(row, "trPr"), "ins");
|
|
335
|
+
/** What a deleted row held: its cells' text, deleted text included, a tab
|
|
336
|
+
* between cells and a line break between paragraphs. */
|
|
337
|
+
const rowTextOf = (row) => {
|
|
338
|
+
const paragraphText = (paragraph) => {
|
|
339
|
+
let text = "";
|
|
340
|
+
const stack = [...elementChildren(paragraph)].toReversed();
|
|
341
|
+
for (let next = stack.pop(); next !== void 0; next = stack.pop()) {
|
|
342
|
+
const name = wName(next);
|
|
343
|
+
if (name === "t" || name === "delText") text += (next.elements ?? []).map((node) => node.type === "text" ? String(node.text ?? "") : "").join("");
|
|
344
|
+
else stack.push(...elementChildren(next).toReversed());
|
|
345
|
+
}
|
|
346
|
+
return text;
|
|
347
|
+
};
|
|
348
|
+
const cellText = (cell) => {
|
|
349
|
+
const lines = [];
|
|
350
|
+
const stack = [...elementChildren(cell)].toReversed();
|
|
351
|
+
for (let next = stack.pop(); next !== void 0; next = stack.pop()) if (wName(next) === "p") lines.push(paragraphText(next));
|
|
352
|
+
else stack.push(...elementChildren(next).toReversed());
|
|
353
|
+
return lines.join("\n");
|
|
354
|
+
};
|
|
355
|
+
const cells = [];
|
|
356
|
+
const stack = [...elementChildren(row)].toReversed();
|
|
357
|
+
for (let next = stack.pop(); next !== void 0; next = stack.pop()) if (wName(next) === "tc") cells.push(cellText(next));
|
|
358
|
+
else if (wName(next) !== "trPr") stack.push(...elementChildren(next).toReversed());
|
|
359
|
+
return cells.join(" ");
|
|
360
|
+
};
|
|
361
|
+
/**
|
|
362
|
+
* The row revisions a table carries in the kept form, in order: an inserted
|
|
363
|
+
* row by the place it has among the table's rows, a deleted one by the
|
|
364
|
+
* place it was taken from and by its text; each with who made the change.
|
|
365
|
+
* Rows of a table nested in a cell are that table's.
|
|
366
|
+
*/
|
|
367
|
+
const tableRowRevisions = (table) => {
|
|
368
|
+
const out = [];
|
|
369
|
+
let rows = 0;
|
|
370
|
+
const by = (mark) => `${wAttr(mark, "author") ?? ""}:${wAttr(mark, "date") ?? ""}`;
|
|
371
|
+
const visit = (container) => {
|
|
372
|
+
for (const child of elementChildren(container)) {
|
|
373
|
+
const deleted = keptDeletedRowOf(child);
|
|
374
|
+
if (deleted !== null) out.push(`${String(rows)}:del:${by(deletedRowMarkOf(deleted))}:${rowTextOf(deleted)}`);
|
|
375
|
+
else if (wName(child) === "tr") {
|
|
376
|
+
const inserted = insertedRowMarkOf(child);
|
|
377
|
+
if (inserted !== null) out.push(`${String(rows)}:ins:${by(inserted)}`);
|
|
378
|
+
rows += 1;
|
|
379
|
+
} else if (wName(child) === "sdt") {
|
|
380
|
+
const content = wChild(child, "sdtContent");
|
|
381
|
+
if (content !== null) visit(content);
|
|
382
|
+
} else if (wName(child) === "customXml") visit(child);
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
visit(table);
|
|
386
|
+
return out;
|
|
387
|
+
};
|
|
388
|
+
const deletedMarkOf = (paragraph) => wChild(wChild(wChild(paragraph, "pPr"), "rPr"), "del");
|
|
389
|
+
/** Whether `xml` may hold a paragraph mark recorded as deleted: an empty
|
|
390
|
+
* deletion, in either spelling of an empty element. */
|
|
391
|
+
const mayHoldDeletedMark = (xml) => /<[A-Za-z0-9]+:del\b[^>]*(?:\/>|><\/)/u.test(xml);
|
|
392
|
+
/** Whether the opening tag of an element declares a namespace of its own. */
|
|
393
|
+
const declaresNamespace = (source) => /^<[^>]*\sxmlns[:=]/u.test(source);
|
|
394
|
+
/**
|
|
395
|
+
* The deletion that stands for a deleted paragraph mark, by who deleted it.
|
|
396
|
+
* It is written with the prefix of the paragraph it came from, which is
|
|
397
|
+
* bound wherever that paragraph's content may stand.
|
|
398
|
+
*/
|
|
399
|
+
const markDeletionXml = (paragraph, mark) => {
|
|
400
|
+
const prefix = (paragraph.name ?? "w:p").split(":").at(0) ?? "w";
|
|
401
|
+
const attribute = (name) => {
|
|
402
|
+
const value = wAttr(mark, name);
|
|
403
|
+
return value === null ? "" : ` ${prefix}:${name}="${escapeXmlAttribute(value)}"`;
|
|
404
|
+
};
|
|
405
|
+
return `<${prefix}:del ${prefix}:id="0"${attribute("author")}${attribute("date")}><${prefix}:r><${prefix}:delText></${prefix}:delText></${prefix}:r></${prefix}:del>`;
|
|
406
|
+
};
|
|
407
|
+
/**
|
|
408
|
+
* The children of `container` with every paragraph whose mark is deleted
|
|
409
|
+
* joined to the paragraph after it: its content, then a deletion that
|
|
410
|
+
* stands for the mark, then that paragraph's own content under that
|
|
411
|
+
* paragraph's properties. This is what the document reads with its changes
|
|
412
|
+
* accepted, with the deleted mark still on record. A paragraph that has no
|
|
413
|
+
* paragraph after it in its container keeps its mark, and so does one whose
|
|
414
|
+
* own tag declares a namespace: its content would lose the binding in
|
|
415
|
+
* another paragraph.
|
|
416
|
+
*/
|
|
417
|
+
const joinChildren = (walk, container) => {
|
|
418
|
+
const inner = innerRangeOf(walk.xml, container);
|
|
419
|
+
if (inner === null) return "";
|
|
420
|
+
let out = "";
|
|
421
|
+
let cursor = inner.start;
|
|
422
|
+
/** A paragraph whose mark is deleted, waiting for the next paragraph. */
|
|
423
|
+
let held = null;
|
|
424
|
+
const release = () => {
|
|
425
|
+
if (held !== null) {
|
|
426
|
+
out += held.xml;
|
|
427
|
+
held = null;
|
|
428
|
+
}
|
|
429
|
+
};
|
|
430
|
+
for (const child of elementChildren(container)) {
|
|
431
|
+
const range = rangeOf(child);
|
|
432
|
+
if (range === null) {
|
|
433
|
+
walk.sound = false;
|
|
434
|
+
return "";
|
|
435
|
+
}
|
|
436
|
+
const between = walk.xml.slice(cursor, range.start);
|
|
437
|
+
cursor = range.end;
|
|
438
|
+
const source = walk.xml.slice(range.start, range.end);
|
|
439
|
+
if (wName(child) === "tr" && deletedRowMarkOf(child) !== null) {
|
|
440
|
+
release();
|
|
441
|
+
out += `${between}<kept:${KEPT_DELETED_ROW} xmlns:kept="${KEPT_DELETED_ROW_NAMESPACE}">${source}</kept:${KEPT_DELETED_ROW}>`;
|
|
442
|
+
continue;
|
|
443
|
+
}
|
|
444
|
+
if (wName(child) !== "p") {
|
|
445
|
+
release();
|
|
446
|
+
out += between + joinElement(walk, child, source);
|
|
447
|
+
continue;
|
|
448
|
+
}
|
|
449
|
+
const carried = held === null ? "" : held.content;
|
|
450
|
+
const joined = withLeadingContent(source, carried);
|
|
451
|
+
const mark = declaresNamespace(source) ? null : deletedMarkOf(child);
|
|
452
|
+
if (mark === null) {
|
|
453
|
+
out += between + joined;
|
|
454
|
+
held = null;
|
|
455
|
+
continue;
|
|
456
|
+
}
|
|
457
|
+
held = {
|
|
458
|
+
xml: between + joined,
|
|
459
|
+
content: contentOf(joined) + markDeletionXml(child, mark)
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
release();
|
|
463
|
+
return out + walk.xml.slice(cursor, inner.end);
|
|
464
|
+
};
|
|
465
|
+
const joinElement = (walk, element, source) => {
|
|
466
|
+
const outer = rangeOf(element);
|
|
467
|
+
const inner = innerRangeOf(walk.xml, element);
|
|
468
|
+
if (!mayHoldDeletedMark(source) || outer === null || inner === null) return source;
|
|
469
|
+
return `${walk.xml.slice(outer.start, inner.start)}${joinChildren(walk, element)}${walk.xml.slice(inner.end, outer.end)}`;
|
|
470
|
+
};
|
|
471
|
+
/** One part with its deleted paragraph marks carried as deletions; null
|
|
472
|
+
* when it cannot be read whole. */
|
|
473
|
+
const joinDeletedMarksInPart = (path, xml) => {
|
|
474
|
+
if (!mayHoldDeletedMark(xml)) return xml;
|
|
475
|
+
const part = readRawPart(path, xml);
|
|
476
|
+
const outer = part === null ? null : rangeOf(part.root);
|
|
477
|
+
if (part === null || outer === null) return null;
|
|
478
|
+
const walk = {
|
|
479
|
+
xml,
|
|
480
|
+
sound: true
|
|
481
|
+
};
|
|
482
|
+
const joined = joinElement(walk, part.root, xml.slice(outer.start, outer.end));
|
|
483
|
+
return walk.sound ? spliceXml(xml, [{
|
|
484
|
+
...outer,
|
|
485
|
+
newXml: joined
|
|
486
|
+
}]) : null;
|
|
487
|
+
};
|
|
488
|
+
/**
|
|
489
|
+
* A package in the form a reading that keeps tracked changes takes it in:
|
|
490
|
+
* the main document and the notes with their deleted paragraph marks
|
|
491
|
+
* carried as deletions. The bytes are the document's own when it has none.
|
|
492
|
+
*/
|
|
493
|
+
const withDeletedMarksJoined = async (docx) => {
|
|
494
|
+
const loaded = await loadPackage(docx);
|
|
495
|
+
if (loaded.isErr()) return Result.err(loaded.error);
|
|
496
|
+
const pkg = loaded.value;
|
|
497
|
+
const paths = [
|
|
498
|
+
pkg.documentPath,
|
|
499
|
+
pkg.partPath("footnotes"),
|
|
500
|
+
pkg.partPath("endnotes")
|
|
501
|
+
].filter((path) => path !== null);
|
|
502
|
+
const rewritten = /* @__PURE__ */ new Map();
|
|
503
|
+
for (const path of paths) {
|
|
504
|
+
const xml = path === pkg.documentPath ? pkg.documentXml : await pkg.readText(path);
|
|
505
|
+
if (xml === null) continue;
|
|
506
|
+
const joined = joinDeletedMarksInPart(path, xml);
|
|
507
|
+
if (joined === null) return Result.err(new TemplatePlanError({
|
|
508
|
+
code: "xml-unreadable",
|
|
509
|
+
message: `The deleted paragraph marks of ${path} could not be read.`
|
|
510
|
+
}));
|
|
511
|
+
if (joined !== xml) rewritten.set(path, joined);
|
|
512
|
+
}
|
|
513
|
+
if (rewritten.size === 0) return Result.ok(docx);
|
|
514
|
+
return await Result.tryPromise({
|
|
515
|
+
try: async () => {
|
|
516
|
+
const zip = await ZipArchive.read(docx);
|
|
517
|
+
for (const [path, content] of rewritten) {
|
|
518
|
+
const current = zip.entry(path);
|
|
519
|
+
zip.set(path, content, current === void 0 ? {} : { modified: current.modified });
|
|
520
|
+
}
|
|
521
|
+
return await zip.generate();
|
|
522
|
+
},
|
|
523
|
+
catch: (cause) => new TemplatePlanError({
|
|
524
|
+
code: "archive-unreadable",
|
|
525
|
+
message: "The package could not be rewritten with its marks joined.",
|
|
526
|
+
cause
|
|
527
|
+
})
|
|
528
|
+
});
|
|
529
|
+
};
|
|
530
|
+
const REVISION_WRAPPERS = /* @__PURE__ */ new Set([
|
|
531
|
+
"ins",
|
|
532
|
+
"del",
|
|
533
|
+
"moveFrom",
|
|
534
|
+
"moveTo"
|
|
535
|
+
]);
|
|
536
|
+
const countObstacles = (root, into) => {
|
|
537
|
+
const visit = (element, parent, grandparent) => {
|
|
538
|
+
const name = wName(element);
|
|
539
|
+
if (name !== null && REVISION_WRAPPERS.has(name)) {
|
|
540
|
+
if (parent === "rPr" && grandparent === "pPr") {
|
|
541
|
+
into.paragraphMarks += 1;
|
|
542
|
+
into.moves += name === "moveFrom" || name === "moveTo" ? 1 : 0;
|
|
543
|
+
} else if (parent === "trPr") into.tableRows += 1;
|
|
544
|
+
else if (name === "moveFrom" || name === "moveTo") into.moves += 1;
|
|
545
|
+
} else if (name !== null && CELL_MARKS.has(name)) into.tableCells += 1;
|
|
546
|
+
for (const child of elementChildren(element)) visit(child, name, parent);
|
|
547
|
+
};
|
|
548
|
+
visit(root, null, null);
|
|
549
|
+
};
|
|
550
|
+
/**
|
|
551
|
+
* What a document tracks, and which of it a plan that keeps tracked changes
|
|
552
|
+
* cannot carry: a change that makes the paragraphs of the accepted and the
|
|
553
|
+
* rejected view differ.
|
|
554
|
+
*/
|
|
555
|
+
const keptRevisionObstacles = async (docx) => {
|
|
556
|
+
const loaded = await loadPackage(docx);
|
|
557
|
+
if (loaded.isErr()) return Result.err(loaded.error);
|
|
558
|
+
const pkg = loaded.value;
|
|
559
|
+
const tally = newTally();
|
|
560
|
+
const obstacles = {
|
|
561
|
+
paragraphMarks: 0,
|
|
562
|
+
tableRows: 0,
|
|
563
|
+
tableCells: 0,
|
|
564
|
+
moves: 0
|
|
565
|
+
};
|
|
566
|
+
const paths = [
|
|
567
|
+
pkg.documentPath,
|
|
568
|
+
pkg.partPath("footnotes"),
|
|
569
|
+
pkg.partPath("endnotes")
|
|
570
|
+
].filter((path) => path !== null);
|
|
571
|
+
for (const path of paths) {
|
|
572
|
+
const xml = path === pkg.documentPath ? pkg.documentXml : await pkg.readText(path);
|
|
573
|
+
if (xml === null || !mayHoldRevision(xml)) continue;
|
|
574
|
+
const part = readRawPart(path, xml);
|
|
575
|
+
if (part !== null) {
|
|
576
|
+
tallyPart(part.root, tally);
|
|
577
|
+
countObstacles(part.root, obstacles);
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
return Result.ok({
|
|
581
|
+
tracked: {
|
|
582
|
+
...summaryOf(tally),
|
|
583
|
+
paragraphMarks: obstacles.paragraphMarks,
|
|
584
|
+
tableRows: obstacles.tableRows
|
|
585
|
+
},
|
|
586
|
+
obstacles
|
|
587
|
+
});
|
|
588
|
+
};
|
|
315
589
|
/** One part in the chosen view, or null when it cannot be read whole. */
|
|
316
590
|
const resolvePartRevisions = (path, xml, view) => {
|
|
317
591
|
const part = readRawPart(path, xml);
|
|
@@ -404,4 +678,4 @@ const resolveTrackedChanges = async (docx, view) => {
|
|
|
404
678
|
})
|
|
405
679
|
});
|
|
406
680
|
};
|
|
407
|
-
export { resolvePartRevisions, resolveTrackedChanges };
|
|
681
|
+
export { DELETED_PARAGRAPH_MARK, KEPT_DELETED_ROW_NAMESPACE, deletedRowMarkOf, insertedRowMarkOf, joinDeletedMarksInPart, keptDeletedRowOf, keptRevisionObstacles, resolvePartRevisions, resolveTrackedChanges, rowTextOf, tableRowRevisions, withDeletedMarksJoined };
|
|
@@ -5,6 +5,16 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { XmlElement } from "../../xmlParser.js";
|
|
7
7
|
import { ParagraphNumberingOverride } from "@stll/docx-core/model";
|
|
8
|
+
/**
|
|
9
|
+
* Whether an object of a paragraph is a drawn shape fixed to the page: a
|
|
10
|
+
* single shape without a picture and without text of its own (a rule, a
|
|
11
|
+
* dot, a line), floating, with its horizontal place counted from the page
|
|
12
|
+
* or a margin. Such a mark belongs to the layout of the page it was drawn
|
|
13
|
+
* on: when the text around it is set anew it stands where that page had it.
|
|
14
|
+
* A picture, a text box, a group, a chart, an inline drawing and a shape
|
|
15
|
+
* that follows its column, character or paragraph are none.
|
|
16
|
+
*/
|
|
17
|
+
export declare const isPageShape: (object: XmlElement) => boolean;
|
|
8
18
|
/** The mark a footnote or endnote reference leaves in a block's text. */
|
|
9
19
|
export declare const NOTE_REFERENCE_MARK = "";
|
|
10
20
|
export type AtomKind = "text" | "tab" | "lineBreak" | "pageBreak" | "noBreakHyphen" | "softHyphen" | "symbol" | "footnoteReference" | "endnoteReference" | "selfNumber" | "object";
|
|
@@ -37,6 +47,33 @@ export type InlineAtom = {
|
|
|
37
47
|
fields: readonly number[];
|
|
38
48
|
/** The code of the field a `selfNumber` atom stands for. */
|
|
39
49
|
instruction?: string;
|
|
50
|
+
/** The tracked change the atom is part of, in a reading that keeps them. */
|
|
51
|
+
revision?: AtomRevision;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* A tracked change an atom is part of, as a reading that keeps revisions
|
|
55
|
+
* reports it. An inserted atom is content like any other with this tag. A
|
|
56
|
+
* deleted one is a text atom without text: it takes no place in the text
|
|
57
|
+
* the document reads with its changes accepted, and holds what was deleted
|
|
58
|
+
* in `deleted` (a tab as `\t`, a line break as `\n`, a paragraph mark as
|
|
59
|
+
* the private character a keeping reading carries it as). An inserted
|
|
60
|
+
* paragraph mark is a text atom without text at the end of its paragraph,
|
|
61
|
+
* tagged `mark`.
|
|
62
|
+
*/
|
|
63
|
+
export type AtomRevision = {
|
|
64
|
+
kind: "ins" | "del";
|
|
65
|
+
author: string;
|
|
66
|
+
date: string | null;
|
|
67
|
+
deleted?: string;
|
|
68
|
+
mark?: true;
|
|
69
|
+
/**
|
|
70
|
+
* The insertion a deletion sits in: text one hand inserted and another
|
|
71
|
+
* deleted again. It reads in neither view and is on record in both.
|
|
72
|
+
*/
|
|
73
|
+
within?: {
|
|
74
|
+
author: string;
|
|
75
|
+
date: string | null;
|
|
76
|
+
};
|
|
40
77
|
};
|
|
41
78
|
/** Whether a field kind prints a number of its own and caches no text. */
|
|
42
79
|
export declare const isSelfNumberingField: (kind: string) => boolean;
|
|
@@ -71,8 +108,20 @@ export type StoryState = {
|
|
|
71
108
|
formattingRevisions: number;
|
|
72
109
|
/** Field separators and ends met with no field open to take them. */
|
|
73
110
|
strayFieldEnds: number;
|
|
111
|
+
/**
|
|
112
|
+
* Whether inline insertions and deletions are read as tagged atoms. Left
|
|
113
|
+
* out, an insertion reads as plain content and a deletion is skipped.
|
|
114
|
+
*/
|
|
115
|
+
keepsRevisions: boolean;
|
|
116
|
+
/**
|
|
117
|
+
* Revisions a keeping reading could not tag: one inside another, deleted
|
|
118
|
+
* content that is no text, a change inside a drawing or an equation.
|
|
119
|
+
*/
|
|
120
|
+
untaggedRevisions: number;
|
|
74
121
|
};
|
|
75
|
-
export declare const createStoryState: (
|
|
122
|
+
export declare const createStoryState: (options?: {
|
|
123
|
+
keepsRevisions?: boolean;
|
|
124
|
+
}) => StoryState;
|
|
76
125
|
/** A bookmark start, with how many atoms of its paragraph come before it. */
|
|
77
126
|
/**
|
|
78
127
|
* Close a story at its end: a field still open there never closes, and must
|
|
@@ -107,6 +156,8 @@ export type ParagraphRead = {
|
|
|
107
156
|
bookmarks: ParagraphBookmark[];
|
|
108
157
|
bookmarkEnds: ParagraphBookmarkEnd[];
|
|
109
158
|
inlineObjects: number;
|
|
159
|
+
/** How many of them are drawn shapes fixed to the page. */
|
|
160
|
+
pageShapes: number;
|
|
110
161
|
/** Names of content the reader has no text for and the transfer cannot carry. */
|
|
111
162
|
unsupported: string[];
|
|
112
163
|
hasSectionBreak: boolean;
|
|
@@ -114,6 +165,12 @@ export type ParagraphRead = {
|
|
|
114
165
|
pageBreakBefore: boolean | null;
|
|
115
166
|
/** `w:jc` as the paragraph itself states it, or null. */
|
|
116
167
|
alignment: string | null;
|
|
168
|
+
/** The space in front and behind (`w:spacing`) the paragraph itself
|
|
169
|
+
* states, in twentieths of a point; null for a side it does not state. */
|
|
170
|
+
spacing: {
|
|
171
|
+
before: number | null;
|
|
172
|
+
after: number | null;
|
|
173
|
+
};
|
|
117
174
|
/** The sides of `w:ind` the paragraph itself states, in twentieths of a
|
|
118
175
|
* point: where its lines start, and what its first line adds to that
|
|
119
176
|
* (negative for a hanging indent). Null for a side it does not state. */
|