@beyondwork/docx-react-component 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -104
- package/package.json +76 -46
- package/src/README.md +85 -0
- package/src/api/README.md +22 -0
- package/src/api/public-types.ts +525 -0
- package/src/compare/diff-engine.ts +530 -0
- package/src/compare/export-redlines.ts +162 -0
- package/src/compare/snapshot.ts +37 -0
- package/src/component-inventory.md +99 -0
- package/src/core/README.md +10 -0
- package/src/core/commands/README.md +3 -0
- package/src/core/commands/formatting-commands.ts +161 -0
- package/src/core/commands/image-commands.ts +144 -0
- package/src/core/commands/index.ts +1013 -0
- package/src/core/commands/list-commands.ts +370 -0
- package/src/core/commands/review-commands.ts +108 -0
- package/src/core/commands/text-commands.ts +119 -0
- package/src/core/schema/README.md +3 -0
- package/src/core/schema/text-schema.ts +512 -0
- package/src/core/selection/README.md +3 -0
- package/src/core/selection/mapping.ts +238 -0
- package/src/core/selection/review-anchors.ts +94 -0
- package/src/core/state/README.md +3 -0
- package/src/core/state/editor-state.ts +580 -0
- package/src/core/state/text-transaction.ts +276 -0
- package/src/formats/xlsx/io/parse-shared-strings.ts +41 -0
- package/src/formats/xlsx/io/parse-sheet.ts +289 -0
- package/src/formats/xlsx/io/parse-styles.ts +57 -0
- package/src/formats/xlsx/io/parse-workbook.ts +75 -0
- package/src/formats/xlsx/io/xlsx-session.ts +306 -0
- package/src/formats/xlsx/model/cell.ts +189 -0
- package/src/formats/xlsx/model/sheet.ts +244 -0
- package/src/formats/xlsx/model/styles.ts +118 -0
- package/src/formats/xlsx/model/workbook.ts +449 -0
- package/src/index.ts +45 -0
- package/src/io/README.md +10 -0
- package/src/io/docx-session.ts +1763 -0
- package/src/io/export/README.md +3 -0
- package/src/io/export/export-session.ts +165 -0
- package/src/io/export/minimal-docx.ts +115 -0
- package/src/io/export/reattach-preserved-parts.ts +54 -0
- package/src/io/export/serialize-comments.ts +876 -0
- package/src/io/export/serialize-footnotes.ts +217 -0
- package/src/io/export/serialize-headers-footers.ts +200 -0
- package/src/io/export/serialize-main-document.ts +982 -0
- package/src/io/export/serialize-numbering.ts +97 -0
- package/src/io/export/serialize-revisions.ts +389 -0
- package/src/io/export/serialize-runtime-revisions.ts +265 -0
- package/src/io/export/serialize-tables.ts +147 -0
- package/src/io/export/split-review-boundaries.ts +194 -0
- package/src/io/normalize/README.md +3 -0
- package/src/io/normalize/normalize-text.ts +437 -0
- package/src/io/ooxml/README.md +3 -0
- package/src/io/ooxml/parse-comments.ts +779 -0
- package/src/io/ooxml/parse-complex-content.ts +287 -0
- package/src/io/ooxml/parse-fields.ts +438 -0
- package/src/io/ooxml/parse-footnotes.ts +403 -0
- package/src/io/ooxml/parse-headers-footers.ts +483 -0
- package/src/io/ooxml/parse-inline-media.ts +431 -0
- package/src/io/ooxml/parse-main-document.ts +1846 -0
- package/src/io/ooxml/parse-numbering.ts +425 -0
- package/src/io/ooxml/parse-revisions.ts +658 -0
- package/src/io/ooxml/parse-shapes.ts +271 -0
- package/src/io/ooxml/parse-tables.ts +568 -0
- package/src/io/ooxml/parse-theme.ts +314 -0
- package/src/io/ooxml/part-manifest.ts +136 -0
- package/src/io/ooxml/revision-boundaries.ts +351 -0
- package/src/io/opc/README.md +3 -0
- package/src/io/opc/corrupt-package.ts +166 -0
- package/src/io/opc/docx-package.ts +74 -0
- package/src/io/opc/package-reader.ts +320 -0
- package/src/io/opc/package-writer.ts +273 -0
- package/src/legal/bookmarks.ts +196 -0
- package/src/legal/cross-references.ts +356 -0
- package/src/legal/defined-terms.ts +203 -0
- package/src/model/README.md +3 -0
- package/src/model/canonical-document.ts +1911 -0
- package/src/model/cds-1.0.0.ts +196 -0
- package/src/model/snapshot.ts +393 -0
- package/src/preservation/README.md +3 -0
- package/src/preservation/markup-compatibility.ts +48 -0
- package/src/preservation/opaque-fragment-store.ts +89 -0
- package/src/preservation/opaque-region.ts +233 -0
- package/src/preservation/package-preservation.ts +120 -0
- package/src/preservation/preserved-part-manifest.ts +56 -0
- package/src/preservation/relationship-retention.ts +57 -0
- package/src/preservation/store.ts +185 -0
- package/src/review/README.md +16 -0
- package/src/review/store/README.md +3 -0
- package/src/review/store/comment-anchors.ts +70 -0
- package/src/review/store/comment-remapping.ts +154 -0
- package/src/review/store/comment-store.ts +331 -0
- package/src/review/store/comment-thread.ts +109 -0
- package/src/review/store/revision-actions.ts +394 -0
- package/src/review/store/revision-store.ts +303 -0
- package/src/review/store/revision-types.ts +168 -0
- package/src/review/store/runtime-comment-store.ts +43 -0
- package/src/runtime/README.md +3 -0
- package/src/runtime/ai-action-policy.ts +764 -0
- package/src/runtime/document-runtime.ts +967 -0
- package/src/runtime/read-only-diagnostics-runtime.ts +232 -0
- package/src/runtime/review-runtime.ts +44 -0
- package/src/runtime/revision-runtime.ts +107 -0
- package/src/runtime/session-capabilities.ts +138 -0
- package/src/runtime/surface-projection.ts +570 -0
- package/src/runtime/table-commands.ts +87 -0
- package/src/runtime/table-schema.ts +140 -0
- package/src/runtime/virtualized-rendering.ts +258 -0
- package/src/ui/README.md +30 -0
- package/src/ui/WordReviewEditor.tsx +1504 -0
- package/src/ui/comments/README.md +3 -0
- package/src/ui/compatibility/README.md +3 -0
- package/src/ui/editor-surface/README.md +3 -0
- package/src/ui/headless/comment-decoration-model.ts +124 -0
- package/src/ui/headless/revision-decoration-model.ts +128 -0
- package/src/ui/headless/selection-helpers.ts +34 -0
- package/src/ui/headless/use-editor-keyboard.ts +98 -0
- package/src/ui/review/README.md +3 -0
- package/src/ui/shared/revision-filters.ts +31 -0
- package/src/ui/status/README.md +3 -0
- package/src/ui/theme/README.md +3 -0
- package/src/ui/toolbar/README.md +3 -0
- package/src/ui-tailwind/chrome/tw-alert-banner.tsx +48 -0
- package/src/ui-tailwind/chrome/tw-selection-toolbar.tsx +44 -0
- package/src/ui-tailwind/chrome/tw-unsaved-modal.tsx +58 -0
- package/src/ui-tailwind/chrome/use-before-unload.ts +20 -0
- package/src/ui-tailwind/editor-surface/pm-command-bridge.ts +139 -0
- package/src/ui-tailwind/editor-surface/pm-decorations.ts +98 -0
- package/src/ui-tailwind/editor-surface/pm-position-map.ts +123 -0
- package/src/ui-tailwind/editor-surface/pm-schema.ts +452 -0
- package/src/ui-tailwind/editor-surface/pm-state-from-snapshot.ts +327 -0
- package/src/ui-tailwind/editor-surface/search-plugin.ts +157 -0
- package/src/ui-tailwind/editor-surface/tw-caret.tsx +12 -0
- package/src/ui-tailwind/editor-surface/tw-editor-surface.tsx +150 -0
- package/src/ui-tailwind/editor-surface/tw-inline-token.tsx +118 -0
- package/src/ui-tailwind/editor-surface/tw-opaque-block.tsx +52 -0
- package/src/ui-tailwind/editor-surface/tw-paragraph-block.tsx +151 -0
- package/src/ui-tailwind/editor-surface/tw-prosemirror-surface.tsx +215 -0
- package/src/ui-tailwind/editor-surface/tw-segment-view.tsx +111 -0
- package/src/ui-tailwind/editor-surface/tw-table-node-view.tsx +122 -0
- package/src/ui-tailwind/index.ts +61 -0
- package/src/ui-tailwind/review/tw-comment-sidebar.tsx +276 -0
- package/src/ui-tailwind/review/tw-health-panel.tsx +120 -0
- package/src/ui-tailwind/review/tw-review-rail.tsx +120 -0
- package/src/ui-tailwind/review/tw-revision-sidebar.tsx +164 -0
- package/src/ui-tailwind/status/tw-status-bar.tsx +58 -0
- package/src/ui-tailwind/theme/editor-theme.css +190 -0
- package/src/ui-tailwind/toolbar/tw-toolbar-icon-button.tsx +48 -0
- package/src/ui-tailwind/toolbar/tw-toolbar.tsx +231 -0
- package/src/ui-tailwind/tw-review-workspace.tsx +140 -0
- package/src/validation/README.md +3 -0
- package/src/validation/compatibility-engine.ts +317 -0
- package/src/validation/compatibility-report.ts +160 -0
- package/src/validation/diagnostics.ts +203 -0
- package/src/validation/import-diagnostics.ts +128 -0
- package/src/validation/low-priority-word-surfaces.ts +373 -0
- package/dist/chunk-32W6IVQE.js +0 -7725
- package/dist/chunk-32W6IVQE.js.map +0 -1
- package/dist/index.cjs +0 -23722
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -7
- package/dist/index.d.ts +0 -7
- package/dist/index.js +0 -16011
- package/dist/index.js.map +0 -1
- package/dist/public-types-DqCURAz8.d.cts +0 -1152
- package/dist/public-types-DqCURAz8.d.ts +0 -1152
- package/dist/tailwind.cjs +0 -8295
- package/dist/tailwind.cjs.map +0 -1
- package/dist/tailwind.d.cts +0 -323
- package/dist/tailwind.d.ts +0 -323
- package/dist/tailwind.js +0 -553
- package/dist/tailwind.js.map +0 -1
|
@@ -0,0 +1,658 @@
|
|
|
1
|
+
import { createDetachedAnchor } from "../../core/selection/mapping.ts";
|
|
2
|
+
import {
|
|
3
|
+
createRevisionRecord,
|
|
4
|
+
type RevisionRecord,
|
|
5
|
+
} from "../../review/store/revision-store.ts";
|
|
6
|
+
import {
|
|
7
|
+
createRevisionRangeAnchor,
|
|
8
|
+
type MoveData,
|
|
9
|
+
type PropertyChangeData,
|
|
10
|
+
type RevisionKind,
|
|
11
|
+
} from "../../review/store/revision-types.ts";
|
|
12
|
+
import {
|
|
13
|
+
findChildElement,
|
|
14
|
+
findRequiredChildElement,
|
|
15
|
+
localName,
|
|
16
|
+
mapRevisionBoundaries,
|
|
17
|
+
parseXmlWithPositions,
|
|
18
|
+
type RevisionParagraphBoundary,
|
|
19
|
+
type XmlElementNode,
|
|
20
|
+
type XmlNode,
|
|
21
|
+
} from "./revision-boundaries.ts";
|
|
22
|
+
|
|
23
|
+
export interface PreservedRevisionMarkup {
|
|
24
|
+
revisionId: string;
|
|
25
|
+
rawXml: string;
|
|
26
|
+
xmlStart: number;
|
|
27
|
+
xmlEnd: number;
|
|
28
|
+
originalRevisionType: string;
|
|
29
|
+
paragraphIndex?: number;
|
|
30
|
+
containerXmlStart?: number;
|
|
31
|
+
containerXmlEnd?: number;
|
|
32
|
+
beforeContainerXml?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface RevisionImportDiagnostic {
|
|
36
|
+
revisionId: string;
|
|
37
|
+
code:
|
|
38
|
+
| "preserve_only_move_revision"
|
|
39
|
+
| "preserve_only_formatting_revision"
|
|
40
|
+
| "nested_revision_preserve_only"
|
|
41
|
+
| "ambiguous_revision_anchor";
|
|
42
|
+
message: string;
|
|
43
|
+
featureClass: "preserve-only";
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface ParsedRevisionsResult {
|
|
47
|
+
revisions: RevisionRecord[];
|
|
48
|
+
preservedMarkup: PreservedRevisionMarkup[];
|
|
49
|
+
diagnostics: RevisionImportDiagnostic[];
|
|
50
|
+
boundaries: RevisionParagraphBoundary[];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
interface ParseState {
|
|
54
|
+
documentXml: string;
|
|
55
|
+
boundaries: RevisionParagraphBoundary[];
|
|
56
|
+
revisions: RevisionRecord[];
|
|
57
|
+
preservedMarkup: PreservedRevisionMarkup[];
|
|
58
|
+
diagnostics: RevisionImportDiagnostic[];
|
|
59
|
+
nextGeneratedIndex: number;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
interface RevisionMetadata {
|
|
63
|
+
revisionId: string;
|
|
64
|
+
ooxmlRevisionId?: string;
|
|
65
|
+
authorId: string;
|
|
66
|
+
createdAt: string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const SUPPORTED_CONTAINER_TYPES = new Set(["ins", "del"]);
|
|
70
|
+
const PRESERVE_ONLY_CONTAINER_TYPES = new Set(["moveFrom", "moveTo"]);
|
|
71
|
+
const FORMATTING_REVISION_TYPES = new Set(["rPrChange", "pPrChange"]);
|
|
72
|
+
|
|
73
|
+
export function parseRevisionsFromDocumentXml(
|
|
74
|
+
documentXml: string,
|
|
75
|
+
): ParsedRevisionsResult {
|
|
76
|
+
const root = parseXmlWithPositions(documentXml);
|
|
77
|
+
const documentElement = findRequiredChildElement(root, "document");
|
|
78
|
+
const bodyElement = findRequiredChildElement(documentElement, "body");
|
|
79
|
+
const boundaries = mapRevisionBoundaries(documentXml);
|
|
80
|
+
const state: ParseState = {
|
|
81
|
+
documentXml,
|
|
82
|
+
boundaries,
|
|
83
|
+
revisions: [],
|
|
84
|
+
preservedMarkup: [],
|
|
85
|
+
diagnostics: [],
|
|
86
|
+
nextGeneratedIndex: 1,
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
let paragraphIndex = -1;
|
|
90
|
+
let cursor = 0;
|
|
91
|
+
let previousWasParagraph = false;
|
|
92
|
+
|
|
93
|
+
for (const child of bodyElement.children) {
|
|
94
|
+
if (child.type !== "element") {
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const childType = localName(child.name);
|
|
99
|
+
|
|
100
|
+
if (childType !== "p") {
|
|
101
|
+
if (childType === "tbl") {
|
|
102
|
+
parseTblPropertyRevisions(child, cursor, state);
|
|
103
|
+
} else if (childType === "sectPr") {
|
|
104
|
+
parseSectPrRevisions(child, cursor, state);
|
|
105
|
+
}
|
|
106
|
+
cursor += 1;
|
|
107
|
+
previousWasParagraph = false;
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (previousWasParagraph) {
|
|
112
|
+
cursor += 1;
|
|
113
|
+
}
|
|
114
|
+
paragraphIndex += 1;
|
|
115
|
+
const paragraphBoundary = boundaries[paragraphIndex];
|
|
116
|
+
if (!paragraphBoundary) {
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
parseParagraphMarkRevisions(child, paragraphBoundary, state);
|
|
121
|
+
walkParagraphContent(child.children, paragraphIndex, state, () => cursor, (next) => {
|
|
122
|
+
cursor = next;
|
|
123
|
+
});
|
|
124
|
+
previousWasParagraph = true;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return {
|
|
128
|
+
revisions: state.revisions,
|
|
129
|
+
preservedMarkup: state.preservedMarkup.sort((left, right) => left.xmlStart - right.xmlStart),
|
|
130
|
+
diagnostics: state.diagnostics,
|
|
131
|
+
boundaries,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function parseParagraphMarkRevisions(
|
|
136
|
+
paragraph: XmlElementNode,
|
|
137
|
+
boundary: RevisionParagraphBoundary,
|
|
138
|
+
state: ParseState,
|
|
139
|
+
): void {
|
|
140
|
+
const paragraphProperties = findChildElement(paragraph, "pPr");
|
|
141
|
+
const paragraphRunProperties = paragraphProperties
|
|
142
|
+
? findChildElement(paragraphProperties, "rPr")
|
|
143
|
+
: undefined;
|
|
144
|
+
|
|
145
|
+
if (!paragraphProperties) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const paragraphRange =
|
|
150
|
+
boundary.start === boundary.end
|
|
151
|
+
? createRevisionRangeAnchor(boundary.end, boundary.end)
|
|
152
|
+
: createRevisionRangeAnchor(boundary.start, boundary.end);
|
|
153
|
+
|
|
154
|
+
for (const child of paragraphProperties.children) {
|
|
155
|
+
if (child.type !== "element") {
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const type = localName(child.name);
|
|
160
|
+
if (type === "pPrChange") {
|
|
161
|
+
const metadata = readRevisionMetadata(child, state, "formatting");
|
|
162
|
+
const innerPPr = findChildElement(child, "pPr");
|
|
163
|
+
const propertyChangeData: PropertyChangeData = {
|
|
164
|
+
xmlTag: "pPrChange",
|
|
165
|
+
beforeXml: innerPPr ? state.documentXml.slice(innerPPr.start, innerPPr.end) : "",
|
|
166
|
+
};
|
|
167
|
+
state.revisions.push(
|
|
168
|
+
createRevisionRecord({
|
|
169
|
+
revisionId: metadata.revisionId,
|
|
170
|
+
kind: "formatting",
|
|
171
|
+
anchor: paragraphRange,
|
|
172
|
+
authorId: metadata.authorId,
|
|
173
|
+
createdAt: metadata.createdAt,
|
|
174
|
+
metadata: {
|
|
175
|
+
source: "import",
|
|
176
|
+
originalRevisionType: "pPrChange",
|
|
177
|
+
ooxmlRevisionId: metadata.ooxmlRevisionId,
|
|
178
|
+
preserveOnlyReason: "Imported preserve-only revision.",
|
|
179
|
+
propertyChangeData,
|
|
180
|
+
},
|
|
181
|
+
}),
|
|
182
|
+
);
|
|
183
|
+
state.preservedMarkup.push({
|
|
184
|
+
revisionId: metadata.revisionId,
|
|
185
|
+
rawXml: state.documentXml.slice(child.start, child.end),
|
|
186
|
+
xmlStart: child.start,
|
|
187
|
+
xmlEnd: child.end,
|
|
188
|
+
originalRevisionType: "pPrChange",
|
|
189
|
+
});
|
|
190
|
+
state.diagnostics.push({
|
|
191
|
+
revisionId: metadata.revisionId,
|
|
192
|
+
code: "preserve_only_formatting_revision",
|
|
193
|
+
message: "Paragraph property revisions remain preserve-only for Wave 6.",
|
|
194
|
+
featureClass: "preserve-only",
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (!paragraphRunProperties) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
for (const child of paragraphRunProperties.children) {
|
|
204
|
+
if (child.type !== "element") {
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const type = localName(child.name);
|
|
209
|
+
if (!SUPPORTED_CONTAINER_TYPES.has(type)) {
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const metadata = readRevisionMetadata(child, state, type);
|
|
214
|
+
state.revisions.push(
|
|
215
|
+
createRevisionRecord({
|
|
216
|
+
revisionId: metadata.revisionId,
|
|
217
|
+
kind: type === "ins" ? "insertion" : "deletion",
|
|
218
|
+
anchor: createRevisionRangeAnchor(boundary.end, boundary.end),
|
|
219
|
+
authorId: metadata.authorId,
|
|
220
|
+
createdAt: metadata.createdAt,
|
|
221
|
+
metadata: {
|
|
222
|
+
source: "import",
|
|
223
|
+
importedRevisionForm:
|
|
224
|
+
type === "ins" ? "paragraph-insertion" : "paragraph-deletion",
|
|
225
|
+
originalRevisionType: `paragraph-${type}`,
|
|
226
|
+
ooxmlRevisionId: metadata.ooxmlRevisionId,
|
|
227
|
+
},
|
|
228
|
+
}),
|
|
229
|
+
);
|
|
230
|
+
state.preservedMarkup.push({
|
|
231
|
+
revisionId: metadata.revisionId,
|
|
232
|
+
rawXml: state.documentXml.slice(child.start, child.end),
|
|
233
|
+
xmlStart: child.start,
|
|
234
|
+
xmlEnd: child.end,
|
|
235
|
+
originalRevisionType: `paragraph-${type}`,
|
|
236
|
+
paragraphIndex: boundary.paragraphIndex,
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function walkParagraphContent(
|
|
242
|
+
nodes: XmlNode[],
|
|
243
|
+
paragraphIndex: number,
|
|
244
|
+
state: ParseState,
|
|
245
|
+
getCursor: () => number,
|
|
246
|
+
setCursor: (next: number) => void,
|
|
247
|
+
): void {
|
|
248
|
+
for (const node of nodes) {
|
|
249
|
+
walkContentNode(node, paragraphIndex, state, getCursor, setCursor);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function walkContentNode(
|
|
254
|
+
node: XmlNode,
|
|
255
|
+
paragraphIndex: number,
|
|
256
|
+
state: ParseState,
|
|
257
|
+
getCursor: () => number,
|
|
258
|
+
setCursor: (next: number) => void,
|
|
259
|
+
): void {
|
|
260
|
+
if (node.type !== "element") {
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const type = localName(node.name);
|
|
265
|
+
if (type === "pPr") {
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
if (type === "r") {
|
|
270
|
+
parseRunFormattingRevisions(node, paragraphIndex, state, getCursor());
|
|
271
|
+
for (const child of node.children) {
|
|
272
|
+
walkContentNode(child, paragraphIndex, state, getCursor, setCursor);
|
|
273
|
+
}
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
if (SUPPORTED_CONTAINER_TYPES.has(type) || PRESERVE_ONLY_CONTAINER_TYPES.has(type)) {
|
|
278
|
+
const start = getCursor();
|
|
279
|
+
const length = measureStoryLength(node);
|
|
280
|
+
const end = start + length;
|
|
281
|
+
const hasNestedRevision = containsNestedRevision(node);
|
|
282
|
+
const metadata = readRevisionMetadata(
|
|
283
|
+
node,
|
|
284
|
+
state,
|
|
285
|
+
type === "moveFrom" || type === "moveTo" ? "move" : type,
|
|
286
|
+
);
|
|
287
|
+
|
|
288
|
+
if (hasNestedRevision) {
|
|
289
|
+
const nestedKind = type === "ins" ? "insertion" : type === "del" ? "deletion" : "move";
|
|
290
|
+
state.revisions.push(
|
|
291
|
+
createRevisionRecord({
|
|
292
|
+
revisionId: metadata.revisionId,
|
|
293
|
+
kind: nestedKind,
|
|
294
|
+
anchor:
|
|
295
|
+
length > 0
|
|
296
|
+
? createRevisionRangeAnchor(start, end)
|
|
297
|
+
: createDetachedAnchor({ from: start, to: end }, "importAmbiguity"),
|
|
298
|
+
authorId: metadata.authorId,
|
|
299
|
+
createdAt: metadata.createdAt,
|
|
300
|
+
metadata: {
|
|
301
|
+
source: "import",
|
|
302
|
+
originalRevisionType: type,
|
|
303
|
+
ooxmlRevisionId: metadata.ooxmlRevisionId,
|
|
304
|
+
preserveOnlyReason: "Nested revision markup remains preserve-only.",
|
|
305
|
+
},
|
|
306
|
+
}),
|
|
307
|
+
);
|
|
308
|
+
state.preservedMarkup.push({
|
|
309
|
+
revisionId: metadata.revisionId,
|
|
310
|
+
rawXml: state.documentXml.slice(node.start, node.end),
|
|
311
|
+
xmlStart: node.start,
|
|
312
|
+
xmlEnd: node.end,
|
|
313
|
+
originalRevisionType: type,
|
|
314
|
+
});
|
|
315
|
+
state.diagnostics.push({
|
|
316
|
+
revisionId: metadata.revisionId,
|
|
317
|
+
code: "nested_revision_preserve_only",
|
|
318
|
+
message: "Nested revision markup remains preserve-only and is exported unchanged.",
|
|
319
|
+
featureClass: "preserve-only",
|
|
320
|
+
});
|
|
321
|
+
advanceCursor(node, setCursor, getCursor);
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
if (type === "moveFrom" || type === "moveTo") {
|
|
326
|
+
const moveData: MoveData = {
|
|
327
|
+
moveId: metadata.ooxmlRevisionId ?? `generated-${metadata.revisionId}`,
|
|
328
|
+
direction: type === "moveFrom" ? "from" : "to",
|
|
329
|
+
};
|
|
330
|
+
state.revisions.push(
|
|
331
|
+
createRevisionRecord({
|
|
332
|
+
revisionId: metadata.revisionId,
|
|
333
|
+
kind: "move",
|
|
334
|
+
anchor:
|
|
335
|
+
length > 0
|
|
336
|
+
? createRevisionRangeAnchor(start, end)
|
|
337
|
+
: createDetachedAnchor({ from: start, to: end }, "importAmbiguity"),
|
|
338
|
+
authorId: metadata.authorId,
|
|
339
|
+
createdAt: metadata.createdAt,
|
|
340
|
+
metadata: {
|
|
341
|
+
source: "import",
|
|
342
|
+
originalRevisionType: type,
|
|
343
|
+
ooxmlRevisionId: metadata.ooxmlRevisionId,
|
|
344
|
+
preserveOnlyReason: "Imported preserve-only revision.",
|
|
345
|
+
moveData,
|
|
346
|
+
},
|
|
347
|
+
}),
|
|
348
|
+
);
|
|
349
|
+
state.preservedMarkup.push({
|
|
350
|
+
revisionId: metadata.revisionId,
|
|
351
|
+
rawXml: state.documentXml.slice(node.start, node.end),
|
|
352
|
+
xmlStart: node.start,
|
|
353
|
+
xmlEnd: node.end,
|
|
354
|
+
originalRevisionType: type,
|
|
355
|
+
});
|
|
356
|
+
state.diagnostics.push({
|
|
357
|
+
revisionId: metadata.revisionId,
|
|
358
|
+
code: "preserve_only_move_revision",
|
|
359
|
+
message: "Tracked move revisions remain preserve-only for Wave 6.",
|
|
360
|
+
featureClass: "preserve-only",
|
|
361
|
+
});
|
|
362
|
+
advanceCursor(node, setCursor, getCursor);
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
state.revisions.push(
|
|
367
|
+
createRevisionRecord({
|
|
368
|
+
revisionId: metadata.revisionId,
|
|
369
|
+
kind: type === "ins" ? "insertion" : "deletion",
|
|
370
|
+
anchor: createRevisionRangeAnchor(start, end),
|
|
371
|
+
authorId: metadata.authorId,
|
|
372
|
+
createdAt: metadata.createdAt,
|
|
373
|
+
metadata: {
|
|
374
|
+
source: "import",
|
|
375
|
+
importedRevisionForm:
|
|
376
|
+
type === "ins" ? "run-insertion" : "run-deletion",
|
|
377
|
+
originalRevisionType: type,
|
|
378
|
+
ooxmlRevisionId: metadata.ooxmlRevisionId,
|
|
379
|
+
},
|
|
380
|
+
}),
|
|
381
|
+
);
|
|
382
|
+
state.preservedMarkup.push({
|
|
383
|
+
revisionId: metadata.revisionId,
|
|
384
|
+
rawXml: state.documentXml.slice(node.start, node.end),
|
|
385
|
+
xmlStart: node.start,
|
|
386
|
+
xmlEnd: node.end,
|
|
387
|
+
originalRevisionType: type,
|
|
388
|
+
});
|
|
389
|
+
advanceCursor(node, setCursor, getCursor);
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
switch (type) {
|
|
394
|
+
case "t":
|
|
395
|
+
case "delText":
|
|
396
|
+
case "instrText":
|
|
397
|
+
case "delInstrText": {
|
|
398
|
+
const text = node.children
|
|
399
|
+
.filter((child): child is XmlElementNode["children"][number] & { type: "text" } => child.type === "text")
|
|
400
|
+
.map((child) => child.text)
|
|
401
|
+
.join("");
|
|
402
|
+
setCursor(getCursor() + text.length);
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
case "tab":
|
|
406
|
+
case "br":
|
|
407
|
+
case "cr":
|
|
408
|
+
setCursor(getCursor() + 1);
|
|
409
|
+
return;
|
|
410
|
+
default:
|
|
411
|
+
for (const child of node.children) {
|
|
412
|
+
walkContentNode(child, paragraphIndex, state, getCursor, setCursor);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
function parseRunFormattingRevisions(
|
|
418
|
+
run: XmlElementNode,
|
|
419
|
+
_paragraphIndex: number,
|
|
420
|
+
state: ParseState,
|
|
421
|
+
runStart: number,
|
|
422
|
+
): void {
|
|
423
|
+
const runProperties = findChildElement(run, "rPr");
|
|
424
|
+
if (!runProperties) {
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
const runLength = measureStoryLength(run);
|
|
429
|
+
const anchor =
|
|
430
|
+
runLength > 0
|
|
431
|
+
? createRevisionRangeAnchor(runStart, runStart + runLength)
|
|
432
|
+
: createDetachedAnchor({ from: runStart, to: runStart }, "importAmbiguity");
|
|
433
|
+
|
|
434
|
+
for (const child of runProperties.children) {
|
|
435
|
+
if (child.type !== "element" || !FORMATTING_REVISION_TYPES.has(localName(child.name))) {
|
|
436
|
+
continue;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
const childLocalName = localName(child.name) as "rPrChange" | "pPrChange";
|
|
440
|
+
const metadata = readRevisionMetadata(child, state, "formatting");
|
|
441
|
+
const innerRPr = findChildElement(child, "rPr");
|
|
442
|
+
const propertyChangeData: PropertyChangeData = {
|
|
443
|
+
xmlTag: childLocalName === "rPrChange" ? "rPrChange" : "pPrChange",
|
|
444
|
+
beforeXml: innerRPr ? state.documentXml.slice(innerRPr.start, innerRPr.end) : "",
|
|
445
|
+
};
|
|
446
|
+
state.revisions.push(
|
|
447
|
+
createRevisionRecord({
|
|
448
|
+
revisionId: metadata.revisionId,
|
|
449
|
+
kind: "formatting",
|
|
450
|
+
anchor,
|
|
451
|
+
authorId: metadata.authorId,
|
|
452
|
+
createdAt: metadata.createdAt,
|
|
453
|
+
metadata: {
|
|
454
|
+
source: "import",
|
|
455
|
+
originalRevisionType: childLocalName,
|
|
456
|
+
ooxmlRevisionId: metadata.ooxmlRevisionId,
|
|
457
|
+
preserveOnlyReason: "Imported preserve-only revision.",
|
|
458
|
+
propertyChangeData,
|
|
459
|
+
},
|
|
460
|
+
}),
|
|
461
|
+
);
|
|
462
|
+
state.preservedMarkup.push({
|
|
463
|
+
revisionId: metadata.revisionId,
|
|
464
|
+
rawXml: state.documentXml.slice(child.start, child.end),
|
|
465
|
+
xmlStart: child.start,
|
|
466
|
+
xmlEnd: child.end,
|
|
467
|
+
originalRevisionType: childLocalName,
|
|
468
|
+
});
|
|
469
|
+
state.diagnostics.push({
|
|
470
|
+
revisionId: metadata.revisionId,
|
|
471
|
+
code: "preserve_only_formatting_revision",
|
|
472
|
+
message: "Formatting revisions remain preserve-only for Wave 6.",
|
|
473
|
+
featureClass: "preserve-only",
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
function parseTblPropertyRevisions(
|
|
479
|
+
table: XmlElementNode,
|
|
480
|
+
position: number,
|
|
481
|
+
state: ParseState,
|
|
482
|
+
): void {
|
|
483
|
+
const tblPr = findChildElement(table, "tblPr");
|
|
484
|
+
if (!tblPr) {
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
const tblPrChange = findChildElement(tblPr, "tblPrChange");
|
|
489
|
+
if (!tblPrChange) {
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
const metadata = readRevisionMetadata(tblPrChange, state, "property-change");
|
|
494
|
+
const innerTblPr = findChildElement(tblPrChange, "tblPr");
|
|
495
|
+
const beforeXml = innerTblPr ? state.documentXml.slice(innerTblPr.start, innerTblPr.end) : "";
|
|
496
|
+
const propertyChangeData: PropertyChangeData = { xmlTag: "tblPrChange", beforeXml };
|
|
497
|
+
|
|
498
|
+
state.revisions.push(
|
|
499
|
+
createRevisionRecord({
|
|
500
|
+
revisionId: metadata.revisionId,
|
|
501
|
+
kind: "property-change",
|
|
502
|
+
anchor: createRevisionRangeAnchor(position, position),
|
|
503
|
+
authorId: metadata.authorId,
|
|
504
|
+
createdAt: metadata.createdAt,
|
|
505
|
+
metadata: {
|
|
506
|
+
source: "import",
|
|
507
|
+
originalRevisionType: "tblPrChange",
|
|
508
|
+
ooxmlRevisionId: metadata.ooxmlRevisionId,
|
|
509
|
+
propertyChangeData,
|
|
510
|
+
},
|
|
511
|
+
}),
|
|
512
|
+
);
|
|
513
|
+
state.preservedMarkup.push({
|
|
514
|
+
revisionId: metadata.revisionId,
|
|
515
|
+
rawXml: state.documentXml.slice(tblPrChange.start, tblPrChange.end),
|
|
516
|
+
xmlStart: tblPrChange.start,
|
|
517
|
+
xmlEnd: tblPrChange.end,
|
|
518
|
+
originalRevisionType: "tblPrChange",
|
|
519
|
+
containerXmlStart: tblPr.start,
|
|
520
|
+
containerXmlEnd: tblPr.end,
|
|
521
|
+
beforeContainerXml: beforeXml,
|
|
522
|
+
});
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
function parseSectPrRevisions(
|
|
526
|
+
sectPr: XmlElementNode,
|
|
527
|
+
position: number,
|
|
528
|
+
state: ParseState,
|
|
529
|
+
): void {
|
|
530
|
+
const sectPrChange = findChildElement(sectPr, "sectPrChange");
|
|
531
|
+
if (!sectPrChange) {
|
|
532
|
+
return;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
const metadata = readRevisionMetadata(sectPrChange, state, "property-change");
|
|
536
|
+
const innerSectPr = findChildElement(sectPrChange, "sectPr");
|
|
537
|
+
const beforeXml = innerSectPr ? state.documentXml.slice(innerSectPr.start, innerSectPr.end) : "";
|
|
538
|
+
const propertyChangeData: PropertyChangeData = { xmlTag: "sectPrChange", beforeXml };
|
|
539
|
+
|
|
540
|
+
state.revisions.push(
|
|
541
|
+
createRevisionRecord({
|
|
542
|
+
revisionId: metadata.revisionId,
|
|
543
|
+
kind: "property-change",
|
|
544
|
+
anchor: createRevisionRangeAnchor(position, position),
|
|
545
|
+
authorId: metadata.authorId,
|
|
546
|
+
createdAt: metadata.createdAt,
|
|
547
|
+
metadata: {
|
|
548
|
+
source: "import",
|
|
549
|
+
originalRevisionType: "sectPrChange",
|
|
550
|
+
ooxmlRevisionId: metadata.ooxmlRevisionId,
|
|
551
|
+
propertyChangeData,
|
|
552
|
+
},
|
|
553
|
+
}),
|
|
554
|
+
);
|
|
555
|
+
state.preservedMarkup.push({
|
|
556
|
+
revisionId: metadata.revisionId,
|
|
557
|
+
rawXml: state.documentXml.slice(sectPrChange.start, sectPrChange.end),
|
|
558
|
+
xmlStart: sectPrChange.start,
|
|
559
|
+
xmlEnd: sectPrChange.end,
|
|
560
|
+
originalRevisionType: "sectPrChange",
|
|
561
|
+
containerXmlStart: sectPr.start,
|
|
562
|
+
containerXmlEnd: sectPr.end,
|
|
563
|
+
beforeContainerXml: beforeXml,
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
function readRevisionMetadata(
|
|
568
|
+
node: XmlElementNode,
|
|
569
|
+
state: ParseState,
|
|
570
|
+
prefix: string,
|
|
571
|
+
): RevisionMetadata {
|
|
572
|
+
const rawId = node.attributes["w:id"] ?? node.attributes.id;
|
|
573
|
+
const ooxmlRevisionId = rawId ? rawId : undefined;
|
|
574
|
+
const revisionId = rawId
|
|
575
|
+
? `revision:${sanitizeRevisionToken(prefix)}-${sanitizeRevisionToken(rawId)}`
|
|
576
|
+
: `revision:${sanitizeRevisionToken(prefix)}-generated-${state.nextGeneratedIndex++}`;
|
|
577
|
+
const authorId =
|
|
578
|
+
node.attributes["w:author"] ??
|
|
579
|
+
node.attributes.author ??
|
|
580
|
+
"word:unknown-author";
|
|
581
|
+
const createdAt =
|
|
582
|
+
normalizeImportedTimestamp(
|
|
583
|
+
node.attributes["w:date"] ?? node.attributes.date,
|
|
584
|
+
) ??
|
|
585
|
+
"1970-01-01T00:00:00.000Z";
|
|
586
|
+
|
|
587
|
+
return {
|
|
588
|
+
revisionId,
|
|
589
|
+
ooxmlRevisionId,
|
|
590
|
+
authorId,
|
|
591
|
+
createdAt,
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
function normalizeImportedTimestamp(value: string | undefined): string | undefined {
|
|
596
|
+
if (!value) {
|
|
597
|
+
return undefined;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
const parsed = new Date(value);
|
|
601
|
+
if (Number.isNaN(parsed.valueOf())) {
|
|
602
|
+
return undefined;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
return parsed.toISOString();
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
function sanitizeRevisionToken(value: string): string {
|
|
609
|
+
const sanitized = value.replace(/[^A-Za-z0-9._-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
610
|
+
return sanitized.length > 0 ? sanitized : "unknown";
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
function containsNestedRevision(node: XmlElementNode): boolean {
|
|
614
|
+
return node.children.some(
|
|
615
|
+
(child) =>
|
|
616
|
+
child.type === "element" &&
|
|
617
|
+
(SUPPORTED_CONTAINER_TYPES.has(localName(child.name)) ||
|
|
618
|
+
PRESERVE_ONLY_CONTAINER_TYPES.has(localName(child.name)) ||
|
|
619
|
+
FORMATTING_REVISION_TYPES.has(localName(child.name)) ||
|
|
620
|
+
containsNestedRevision(child)),
|
|
621
|
+
);
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
function advanceCursor(
|
|
625
|
+
node: XmlElementNode,
|
|
626
|
+
setCursor: (next: number) => void,
|
|
627
|
+
getCursor: () => number,
|
|
628
|
+
): void {
|
|
629
|
+
setCursor(getCursor() + measureStoryLength(node));
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
function measureStoryLength(node: XmlNode): number {
|
|
633
|
+
if (node.type !== "element") {
|
|
634
|
+
return 0;
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
switch (localName(node.name)) {
|
|
638
|
+
case "t":
|
|
639
|
+
case "delText":
|
|
640
|
+
case "instrText":
|
|
641
|
+
case "delInstrText":
|
|
642
|
+
return node.children
|
|
643
|
+
.filter((child): child is XmlElementNode["children"][number] & { type: "text" } => child.type === "text")
|
|
644
|
+
.map((child) => child.text.length)
|
|
645
|
+
.reduce((total, length) => total + length, 0);
|
|
646
|
+
case "tab":
|
|
647
|
+
case "br":
|
|
648
|
+
case "cr":
|
|
649
|
+
return 1;
|
|
650
|
+
case "pPr":
|
|
651
|
+
case "rPr":
|
|
652
|
+
case "rPrChange":
|
|
653
|
+
case "pPrChange":
|
|
654
|
+
return 0;
|
|
655
|
+
default:
|
|
656
|
+
return node.children.reduce((total, child) => total + measureStoryLength(child), 0);
|
|
657
|
+
}
|
|
658
|
+
}
|