docx-diff-editor 1.0.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/LICENSE +191 -0
- package/README.md +218 -0
- package/dist/index.d.mts +318 -0
- package/dist/index.d.ts +318 -0
- package/dist/index.js +1194 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1168 -0
- package/dist/index.mjs.map +1 -0
- package/dist/styles.css +384 -0
- package/package.json +73 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Type definitions for DocxDiffEditor
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* ProseMirror JSON document structure
|
|
8
|
+
*/
|
|
9
|
+
type ProseMirrorJSON = any;
|
|
10
|
+
/**
|
|
11
|
+
* ProseMirror mark (bold, italic, trackInsert, etc.)
|
|
12
|
+
*/
|
|
13
|
+
type ProseMirrorMark = any;
|
|
14
|
+
/**
|
|
15
|
+
* ProseMirror node
|
|
16
|
+
*/
|
|
17
|
+
type ProseMirrorNode = any;
|
|
18
|
+
/**
|
|
19
|
+
* Content that can be set as source or compared against.
|
|
20
|
+
* - File: DOCX file object
|
|
21
|
+
* - string: HTML content
|
|
22
|
+
* - ProseMirrorJSON: Direct JSON structure
|
|
23
|
+
*/
|
|
24
|
+
type DocxContent = File | ProseMirrorJSON | string;
|
|
25
|
+
/**
|
|
26
|
+
* Result of content resolution (converting any input to JSON)
|
|
27
|
+
*/
|
|
28
|
+
interface ResolvedContent {
|
|
29
|
+
json: ProseMirrorJSON;
|
|
30
|
+
type: 'file' | 'html' | 'json';
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* A segment from the diff algorithm
|
|
34
|
+
*/
|
|
35
|
+
interface DiffSegment {
|
|
36
|
+
type: 'equal' | 'insert' | 'delete';
|
|
37
|
+
text: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A format change on unchanged text
|
|
41
|
+
*/
|
|
42
|
+
interface FormatChange {
|
|
43
|
+
from: number;
|
|
44
|
+
to: number;
|
|
45
|
+
text: string;
|
|
46
|
+
before: ProseMirrorMark[];
|
|
47
|
+
after: ProseMirrorMark[];
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Result of diffing two documents
|
|
51
|
+
*/
|
|
52
|
+
interface DiffResult {
|
|
53
|
+
/** Character-level diff segments */
|
|
54
|
+
segments: DiffSegment[];
|
|
55
|
+
/** Format changes on unchanged text */
|
|
56
|
+
formatChanges: FormatChange[];
|
|
57
|
+
/** Full text from original document */
|
|
58
|
+
textA: string;
|
|
59
|
+
/** Full text from new document */
|
|
60
|
+
textB: string;
|
|
61
|
+
/** Human-readable summary */
|
|
62
|
+
summary: string[];
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Result returned after comparing two documents
|
|
66
|
+
*/
|
|
67
|
+
interface ComparisonResult {
|
|
68
|
+
/** Total number of changes */
|
|
69
|
+
totalChanges: number;
|
|
70
|
+
/** Number of insertions */
|
|
71
|
+
insertions: number;
|
|
72
|
+
/** Number of deletions */
|
|
73
|
+
deletions: number;
|
|
74
|
+
/** Number of format changes */
|
|
75
|
+
formatChanges: number;
|
|
76
|
+
/** Human-readable summary strings */
|
|
77
|
+
summary: string[];
|
|
78
|
+
/** The merged JSON document with track changes */
|
|
79
|
+
mergedJson: ProseMirrorJSON;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Location context for a change
|
|
83
|
+
*/
|
|
84
|
+
interface ChangeLocation {
|
|
85
|
+
nodeType: 'heading' | 'paragraph' | 'listItem' | 'tableCell' | 'unknown';
|
|
86
|
+
headingLevel?: number;
|
|
87
|
+
paragraphIndex?: number;
|
|
88
|
+
sectionTitle?: string;
|
|
89
|
+
description: string;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Format change details
|
|
93
|
+
*/
|
|
94
|
+
interface FormatDetails {
|
|
95
|
+
added: string[];
|
|
96
|
+
removed: string[];
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Enriched change with full context for LLM processing
|
|
100
|
+
*/
|
|
101
|
+
interface EnrichedChange {
|
|
102
|
+
type: 'insertion' | 'deletion' | 'replacement' | 'format';
|
|
103
|
+
text?: string;
|
|
104
|
+
oldText?: string;
|
|
105
|
+
newText?: string;
|
|
106
|
+
location: ChangeLocation;
|
|
107
|
+
formatDetails?: FormatDetails;
|
|
108
|
+
charCount?: number;
|
|
109
|
+
/** The sentence or clause containing the change */
|
|
110
|
+
surroundingText?: string;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Author information for track changes
|
|
114
|
+
*/
|
|
115
|
+
interface TrackChangeAuthor {
|
|
116
|
+
name: string;
|
|
117
|
+
email: string;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Props for DocxDiffEditor component
|
|
121
|
+
*/
|
|
122
|
+
interface DocxDiffEditorProps {
|
|
123
|
+
/** Optional initial source document */
|
|
124
|
+
initialSource?: DocxContent;
|
|
125
|
+
/** Optional template DOCX for styles when using HTML/JSON input */
|
|
126
|
+
templateDocx?: File;
|
|
127
|
+
/** Show rulers in the editor (default: false) */
|
|
128
|
+
showRulers?: boolean;
|
|
129
|
+
/** Show toolbar (default: true) */
|
|
130
|
+
showToolbar?: boolean;
|
|
131
|
+
/** Author info for track changes */
|
|
132
|
+
author?: TrackChangeAuthor;
|
|
133
|
+
/** Callback when editor is ready */
|
|
134
|
+
onReady?: () => void;
|
|
135
|
+
/** Callback when source document is loaded */
|
|
136
|
+
onSourceLoaded?: (json: ProseMirrorJSON) => void;
|
|
137
|
+
/** Callback when comparison completes */
|
|
138
|
+
onComparisonComplete?: (result: ComparisonResult) => void;
|
|
139
|
+
/** Callback on errors */
|
|
140
|
+
onError?: (error: Error) => void;
|
|
141
|
+
/** Container className */
|
|
142
|
+
className?: string;
|
|
143
|
+
/** Toolbar container className */
|
|
144
|
+
toolbarClassName?: string;
|
|
145
|
+
/** Editor container className */
|
|
146
|
+
editorClassName?: string;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Ref methods exposed by DocxDiffEditor
|
|
150
|
+
*/
|
|
151
|
+
interface DocxDiffEditorRef {
|
|
152
|
+
/** Set the source/base document */
|
|
153
|
+
setSource(content: DocxContent): Promise<void>;
|
|
154
|
+
/** Compare source with new content, show track changes */
|
|
155
|
+
compareWith(content: DocxContent): Promise<ComparisonResult>;
|
|
156
|
+
/** Get raw diff segments */
|
|
157
|
+
getDiffSegments(): DiffSegment[];
|
|
158
|
+
/** Get enriched changes with context for LLM processing */
|
|
159
|
+
getEnrichedChangesContext(): EnrichedChange[];
|
|
160
|
+
/** Get current document content as JSON */
|
|
161
|
+
getContent(): ProseMirrorJSON;
|
|
162
|
+
/** Get source document JSON (before comparison) */
|
|
163
|
+
getSourceContent(): ProseMirrorJSON | null;
|
|
164
|
+
/** Export current document to DOCX blob */
|
|
165
|
+
exportDocx(): Promise<Blob>;
|
|
166
|
+
/** Reset to source state (clear comparison) */
|
|
167
|
+
resetComparison(): void;
|
|
168
|
+
/** Check if editor is ready */
|
|
169
|
+
isReady(): boolean;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* DocxDiffEditor Component
|
|
174
|
+
*/
|
|
175
|
+
declare const DocxDiffEditor: react.ForwardRefExoticComponent<DocxDiffEditorProps & react.RefAttributes<DocxDiffEditorRef>>;
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Content Resolver Service
|
|
179
|
+
* Detects content type and converts to ProseMirror JSON.
|
|
180
|
+
*
|
|
181
|
+
* Supports three input formats:
|
|
182
|
+
* - File: DOCX file parsed by SuperDoc
|
|
183
|
+
* - string: HTML content loaded via SuperDoc's html option
|
|
184
|
+
* - object: Direct ProseMirror JSON (passed through)
|
|
185
|
+
*/
|
|
186
|
+
|
|
187
|
+
type SuperDocConstructor = any;
|
|
188
|
+
/**
|
|
189
|
+
* Detect the type of content provided
|
|
190
|
+
*/
|
|
191
|
+
declare function detectContentType(content: DocxContent): 'file' | 'html' | 'json';
|
|
192
|
+
/**
|
|
193
|
+
* Validate that content looks like ProseMirror JSON
|
|
194
|
+
*/
|
|
195
|
+
declare function isProseMirrorJSON(content: unknown): boolean;
|
|
196
|
+
/**
|
|
197
|
+
* Parse a DOCX File into ProseMirror JSON using a hidden SuperDoc instance.
|
|
198
|
+
*/
|
|
199
|
+
declare function parseDocxFile(file: File, SuperDoc: SuperDocConstructor): Promise<ProseMirrorJSON>;
|
|
200
|
+
/**
|
|
201
|
+
* Parse HTML content into ProseMirror JSON using SuperDoc's html option.
|
|
202
|
+
*/
|
|
203
|
+
declare function parseHtmlContent(html: string, SuperDoc: SuperDocConstructor, templateDocx?: File): Promise<ProseMirrorJSON>;
|
|
204
|
+
/**
|
|
205
|
+
* Resolve any content type to ProseMirror JSON.
|
|
206
|
+
*
|
|
207
|
+
* @param content - File, HTML string, or ProseMirror JSON
|
|
208
|
+
* @param SuperDoc - The SuperDoc constructor (passed in to avoid bundling)
|
|
209
|
+
* @param templateDocx - Optional template DOCX for HTML content
|
|
210
|
+
*/
|
|
211
|
+
declare function resolveContent(content: DocxContent, SuperDoc: SuperDocConstructor, templateDocx?: File): Promise<ResolvedContent>;
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Document Differ Service
|
|
215
|
+
* Diffs two ProseMirror JSON documents at the character level,
|
|
216
|
+
* including text changes and formatting changes.
|
|
217
|
+
*/
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Diff two ProseMirror JSON documents at the character level.
|
|
221
|
+
* Detects both text changes and formatting changes.
|
|
222
|
+
*/
|
|
223
|
+
declare function diffDocuments(docA: ProseMirrorJSON, docB: ProseMirrorJSON): DiffResult;
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Merge Documents Service
|
|
227
|
+
* Applies track change marks to the original document structure
|
|
228
|
+
* based on character-level diff segments.
|
|
229
|
+
*/
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Build a merged document by applying diff segments to the original structure.
|
|
233
|
+
*
|
|
234
|
+
* Strategy:
|
|
235
|
+
* 1. Clone docA (original)
|
|
236
|
+
* 2. Walk through diff segments
|
|
237
|
+
* 3. For 'equal' segments: keep original content as-is
|
|
238
|
+
* 4. For 'delete' segments: add trackDelete mark to the corresponding text
|
|
239
|
+
* 5. For 'insert' segments: insert new text nodes with trackInsert mark
|
|
240
|
+
*/
|
|
241
|
+
declare function mergeDocuments(docA: ProseMirrorNode, docB: ProseMirrorNode, diffResult: DiffResult, author?: TrackChangeAuthor): ProseMirrorNode;
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Track Change Injector Service
|
|
245
|
+
* Creates track change marks for insertions, deletions, and format changes.
|
|
246
|
+
*/
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Create a trackInsert mark.
|
|
250
|
+
*/
|
|
251
|
+
declare function createTrackInsertMark(author?: TrackChangeAuthor): ProseMirrorMark;
|
|
252
|
+
/**
|
|
253
|
+
* Create a trackDelete mark.
|
|
254
|
+
*/
|
|
255
|
+
declare function createTrackDeleteMark(author?: TrackChangeAuthor): ProseMirrorMark;
|
|
256
|
+
/**
|
|
257
|
+
* Create a trackFormat mark.
|
|
258
|
+
*/
|
|
259
|
+
declare function createTrackFormatMark(before: ProseMirrorMark[], after: ProseMirrorMark[], author?: TrackChangeAuthor): ProseMirrorMark;
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Change Context Extractor
|
|
263
|
+
* Extracts enriched changes with semantic context from merged document.
|
|
264
|
+
* Provides surrounding text so the LLM can understand what the change is about.
|
|
265
|
+
*/
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Main entry point - extract enriched changes from merged document
|
|
269
|
+
*/
|
|
270
|
+
declare function extractEnrichedChanges(mergedJson: ProseMirrorJSON): EnrichedChange[];
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Constants for DocxDiffEditor
|
|
274
|
+
*/
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Default author for track changes
|
|
278
|
+
*/
|
|
279
|
+
declare const DEFAULT_AUTHOR: TrackChangeAuthor;
|
|
280
|
+
/**
|
|
281
|
+
* Default SuperDoc user (used for editor initialization)
|
|
282
|
+
*/
|
|
283
|
+
declare const DEFAULT_SUPERDOC_USER: {
|
|
284
|
+
name: string;
|
|
285
|
+
email: string;
|
|
286
|
+
};
|
|
287
|
+
/**
|
|
288
|
+
* CSS class prefix for all component styles
|
|
289
|
+
*/
|
|
290
|
+
declare const CSS_PREFIX = "dde";
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Embedded minimal DOCX template
|
|
294
|
+
*
|
|
295
|
+
* This is a base64-encoded minimal DOCX file that provides the basic
|
|
296
|
+
* schema, styles, and fonts needed to initialize SuperDoc when working
|
|
297
|
+
* with HTML or JSON content.
|
|
298
|
+
*
|
|
299
|
+
* The DOCX contains:
|
|
300
|
+
* - Basic document structure
|
|
301
|
+
* - Standard styles (Normal, Heading 1-6, etc.)
|
|
302
|
+
* - Common font definitions (Calibri, Arial, Times New Roman)
|
|
303
|
+
* - Empty content (to be replaced with user content)
|
|
304
|
+
*/
|
|
305
|
+
/**
|
|
306
|
+
* Get the blank DOCX template as a File object
|
|
307
|
+
*/
|
|
308
|
+
declare function getBlankTemplateFile(): File;
|
|
309
|
+
/**
|
|
310
|
+
* Get the blank DOCX template as a Blob
|
|
311
|
+
*/
|
|
312
|
+
declare function getBlankTemplateBlob(): Blob;
|
|
313
|
+
/**
|
|
314
|
+
* Check if a File is a valid DOCX file (basic check)
|
|
315
|
+
*/
|
|
316
|
+
declare function isValidDocxFile(file: File): boolean;
|
|
317
|
+
|
|
318
|
+
export { CSS_PREFIX, type ChangeLocation, type ComparisonResult, DEFAULT_AUTHOR, DEFAULT_SUPERDOC_USER, type DiffResult, type DiffSegment, type DocxContent, DocxDiffEditor, type DocxDiffEditorProps, type DocxDiffEditorRef, type EnrichedChange, type FormatChange, type FormatDetails, type ProseMirrorJSON, type ProseMirrorMark, type ProseMirrorNode, type TrackChangeAuthor, createTrackDeleteMark, createTrackFormatMark, createTrackInsertMark, DocxDiffEditor as default, detectContentType, diffDocuments, extractEnrichedChanges, getBlankTemplateBlob, getBlankTemplateFile, isProseMirrorJSON, isValidDocxFile, mergeDocuments, parseDocxFile, parseHtmlContent, resolveContent };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Type definitions for DocxDiffEditor
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* ProseMirror JSON document structure
|
|
8
|
+
*/
|
|
9
|
+
type ProseMirrorJSON = any;
|
|
10
|
+
/**
|
|
11
|
+
* ProseMirror mark (bold, italic, trackInsert, etc.)
|
|
12
|
+
*/
|
|
13
|
+
type ProseMirrorMark = any;
|
|
14
|
+
/**
|
|
15
|
+
* ProseMirror node
|
|
16
|
+
*/
|
|
17
|
+
type ProseMirrorNode = any;
|
|
18
|
+
/**
|
|
19
|
+
* Content that can be set as source or compared against.
|
|
20
|
+
* - File: DOCX file object
|
|
21
|
+
* - string: HTML content
|
|
22
|
+
* - ProseMirrorJSON: Direct JSON structure
|
|
23
|
+
*/
|
|
24
|
+
type DocxContent = File | ProseMirrorJSON | string;
|
|
25
|
+
/**
|
|
26
|
+
* Result of content resolution (converting any input to JSON)
|
|
27
|
+
*/
|
|
28
|
+
interface ResolvedContent {
|
|
29
|
+
json: ProseMirrorJSON;
|
|
30
|
+
type: 'file' | 'html' | 'json';
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* A segment from the diff algorithm
|
|
34
|
+
*/
|
|
35
|
+
interface DiffSegment {
|
|
36
|
+
type: 'equal' | 'insert' | 'delete';
|
|
37
|
+
text: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A format change on unchanged text
|
|
41
|
+
*/
|
|
42
|
+
interface FormatChange {
|
|
43
|
+
from: number;
|
|
44
|
+
to: number;
|
|
45
|
+
text: string;
|
|
46
|
+
before: ProseMirrorMark[];
|
|
47
|
+
after: ProseMirrorMark[];
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Result of diffing two documents
|
|
51
|
+
*/
|
|
52
|
+
interface DiffResult {
|
|
53
|
+
/** Character-level diff segments */
|
|
54
|
+
segments: DiffSegment[];
|
|
55
|
+
/** Format changes on unchanged text */
|
|
56
|
+
formatChanges: FormatChange[];
|
|
57
|
+
/** Full text from original document */
|
|
58
|
+
textA: string;
|
|
59
|
+
/** Full text from new document */
|
|
60
|
+
textB: string;
|
|
61
|
+
/** Human-readable summary */
|
|
62
|
+
summary: string[];
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Result returned after comparing two documents
|
|
66
|
+
*/
|
|
67
|
+
interface ComparisonResult {
|
|
68
|
+
/** Total number of changes */
|
|
69
|
+
totalChanges: number;
|
|
70
|
+
/** Number of insertions */
|
|
71
|
+
insertions: number;
|
|
72
|
+
/** Number of deletions */
|
|
73
|
+
deletions: number;
|
|
74
|
+
/** Number of format changes */
|
|
75
|
+
formatChanges: number;
|
|
76
|
+
/** Human-readable summary strings */
|
|
77
|
+
summary: string[];
|
|
78
|
+
/** The merged JSON document with track changes */
|
|
79
|
+
mergedJson: ProseMirrorJSON;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Location context for a change
|
|
83
|
+
*/
|
|
84
|
+
interface ChangeLocation {
|
|
85
|
+
nodeType: 'heading' | 'paragraph' | 'listItem' | 'tableCell' | 'unknown';
|
|
86
|
+
headingLevel?: number;
|
|
87
|
+
paragraphIndex?: number;
|
|
88
|
+
sectionTitle?: string;
|
|
89
|
+
description: string;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Format change details
|
|
93
|
+
*/
|
|
94
|
+
interface FormatDetails {
|
|
95
|
+
added: string[];
|
|
96
|
+
removed: string[];
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Enriched change with full context for LLM processing
|
|
100
|
+
*/
|
|
101
|
+
interface EnrichedChange {
|
|
102
|
+
type: 'insertion' | 'deletion' | 'replacement' | 'format';
|
|
103
|
+
text?: string;
|
|
104
|
+
oldText?: string;
|
|
105
|
+
newText?: string;
|
|
106
|
+
location: ChangeLocation;
|
|
107
|
+
formatDetails?: FormatDetails;
|
|
108
|
+
charCount?: number;
|
|
109
|
+
/** The sentence or clause containing the change */
|
|
110
|
+
surroundingText?: string;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Author information for track changes
|
|
114
|
+
*/
|
|
115
|
+
interface TrackChangeAuthor {
|
|
116
|
+
name: string;
|
|
117
|
+
email: string;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Props for DocxDiffEditor component
|
|
121
|
+
*/
|
|
122
|
+
interface DocxDiffEditorProps {
|
|
123
|
+
/** Optional initial source document */
|
|
124
|
+
initialSource?: DocxContent;
|
|
125
|
+
/** Optional template DOCX for styles when using HTML/JSON input */
|
|
126
|
+
templateDocx?: File;
|
|
127
|
+
/** Show rulers in the editor (default: false) */
|
|
128
|
+
showRulers?: boolean;
|
|
129
|
+
/** Show toolbar (default: true) */
|
|
130
|
+
showToolbar?: boolean;
|
|
131
|
+
/** Author info for track changes */
|
|
132
|
+
author?: TrackChangeAuthor;
|
|
133
|
+
/** Callback when editor is ready */
|
|
134
|
+
onReady?: () => void;
|
|
135
|
+
/** Callback when source document is loaded */
|
|
136
|
+
onSourceLoaded?: (json: ProseMirrorJSON) => void;
|
|
137
|
+
/** Callback when comparison completes */
|
|
138
|
+
onComparisonComplete?: (result: ComparisonResult) => void;
|
|
139
|
+
/** Callback on errors */
|
|
140
|
+
onError?: (error: Error) => void;
|
|
141
|
+
/** Container className */
|
|
142
|
+
className?: string;
|
|
143
|
+
/** Toolbar container className */
|
|
144
|
+
toolbarClassName?: string;
|
|
145
|
+
/** Editor container className */
|
|
146
|
+
editorClassName?: string;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Ref methods exposed by DocxDiffEditor
|
|
150
|
+
*/
|
|
151
|
+
interface DocxDiffEditorRef {
|
|
152
|
+
/** Set the source/base document */
|
|
153
|
+
setSource(content: DocxContent): Promise<void>;
|
|
154
|
+
/** Compare source with new content, show track changes */
|
|
155
|
+
compareWith(content: DocxContent): Promise<ComparisonResult>;
|
|
156
|
+
/** Get raw diff segments */
|
|
157
|
+
getDiffSegments(): DiffSegment[];
|
|
158
|
+
/** Get enriched changes with context for LLM processing */
|
|
159
|
+
getEnrichedChangesContext(): EnrichedChange[];
|
|
160
|
+
/** Get current document content as JSON */
|
|
161
|
+
getContent(): ProseMirrorJSON;
|
|
162
|
+
/** Get source document JSON (before comparison) */
|
|
163
|
+
getSourceContent(): ProseMirrorJSON | null;
|
|
164
|
+
/** Export current document to DOCX blob */
|
|
165
|
+
exportDocx(): Promise<Blob>;
|
|
166
|
+
/** Reset to source state (clear comparison) */
|
|
167
|
+
resetComparison(): void;
|
|
168
|
+
/** Check if editor is ready */
|
|
169
|
+
isReady(): boolean;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* DocxDiffEditor Component
|
|
174
|
+
*/
|
|
175
|
+
declare const DocxDiffEditor: react.ForwardRefExoticComponent<DocxDiffEditorProps & react.RefAttributes<DocxDiffEditorRef>>;
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Content Resolver Service
|
|
179
|
+
* Detects content type and converts to ProseMirror JSON.
|
|
180
|
+
*
|
|
181
|
+
* Supports three input formats:
|
|
182
|
+
* - File: DOCX file parsed by SuperDoc
|
|
183
|
+
* - string: HTML content loaded via SuperDoc's html option
|
|
184
|
+
* - object: Direct ProseMirror JSON (passed through)
|
|
185
|
+
*/
|
|
186
|
+
|
|
187
|
+
type SuperDocConstructor = any;
|
|
188
|
+
/**
|
|
189
|
+
* Detect the type of content provided
|
|
190
|
+
*/
|
|
191
|
+
declare function detectContentType(content: DocxContent): 'file' | 'html' | 'json';
|
|
192
|
+
/**
|
|
193
|
+
* Validate that content looks like ProseMirror JSON
|
|
194
|
+
*/
|
|
195
|
+
declare function isProseMirrorJSON(content: unknown): boolean;
|
|
196
|
+
/**
|
|
197
|
+
* Parse a DOCX File into ProseMirror JSON using a hidden SuperDoc instance.
|
|
198
|
+
*/
|
|
199
|
+
declare function parseDocxFile(file: File, SuperDoc: SuperDocConstructor): Promise<ProseMirrorJSON>;
|
|
200
|
+
/**
|
|
201
|
+
* Parse HTML content into ProseMirror JSON using SuperDoc's html option.
|
|
202
|
+
*/
|
|
203
|
+
declare function parseHtmlContent(html: string, SuperDoc: SuperDocConstructor, templateDocx?: File): Promise<ProseMirrorJSON>;
|
|
204
|
+
/**
|
|
205
|
+
* Resolve any content type to ProseMirror JSON.
|
|
206
|
+
*
|
|
207
|
+
* @param content - File, HTML string, or ProseMirror JSON
|
|
208
|
+
* @param SuperDoc - The SuperDoc constructor (passed in to avoid bundling)
|
|
209
|
+
* @param templateDocx - Optional template DOCX for HTML content
|
|
210
|
+
*/
|
|
211
|
+
declare function resolveContent(content: DocxContent, SuperDoc: SuperDocConstructor, templateDocx?: File): Promise<ResolvedContent>;
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Document Differ Service
|
|
215
|
+
* Diffs two ProseMirror JSON documents at the character level,
|
|
216
|
+
* including text changes and formatting changes.
|
|
217
|
+
*/
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Diff two ProseMirror JSON documents at the character level.
|
|
221
|
+
* Detects both text changes and formatting changes.
|
|
222
|
+
*/
|
|
223
|
+
declare function diffDocuments(docA: ProseMirrorJSON, docB: ProseMirrorJSON): DiffResult;
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Merge Documents Service
|
|
227
|
+
* Applies track change marks to the original document structure
|
|
228
|
+
* based on character-level diff segments.
|
|
229
|
+
*/
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Build a merged document by applying diff segments to the original structure.
|
|
233
|
+
*
|
|
234
|
+
* Strategy:
|
|
235
|
+
* 1. Clone docA (original)
|
|
236
|
+
* 2. Walk through diff segments
|
|
237
|
+
* 3. For 'equal' segments: keep original content as-is
|
|
238
|
+
* 4. For 'delete' segments: add trackDelete mark to the corresponding text
|
|
239
|
+
* 5. For 'insert' segments: insert new text nodes with trackInsert mark
|
|
240
|
+
*/
|
|
241
|
+
declare function mergeDocuments(docA: ProseMirrorNode, docB: ProseMirrorNode, diffResult: DiffResult, author?: TrackChangeAuthor): ProseMirrorNode;
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Track Change Injector Service
|
|
245
|
+
* Creates track change marks for insertions, deletions, and format changes.
|
|
246
|
+
*/
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Create a trackInsert mark.
|
|
250
|
+
*/
|
|
251
|
+
declare function createTrackInsertMark(author?: TrackChangeAuthor): ProseMirrorMark;
|
|
252
|
+
/**
|
|
253
|
+
* Create a trackDelete mark.
|
|
254
|
+
*/
|
|
255
|
+
declare function createTrackDeleteMark(author?: TrackChangeAuthor): ProseMirrorMark;
|
|
256
|
+
/**
|
|
257
|
+
* Create a trackFormat mark.
|
|
258
|
+
*/
|
|
259
|
+
declare function createTrackFormatMark(before: ProseMirrorMark[], after: ProseMirrorMark[], author?: TrackChangeAuthor): ProseMirrorMark;
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Change Context Extractor
|
|
263
|
+
* Extracts enriched changes with semantic context from merged document.
|
|
264
|
+
* Provides surrounding text so the LLM can understand what the change is about.
|
|
265
|
+
*/
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Main entry point - extract enriched changes from merged document
|
|
269
|
+
*/
|
|
270
|
+
declare function extractEnrichedChanges(mergedJson: ProseMirrorJSON): EnrichedChange[];
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Constants for DocxDiffEditor
|
|
274
|
+
*/
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Default author for track changes
|
|
278
|
+
*/
|
|
279
|
+
declare const DEFAULT_AUTHOR: TrackChangeAuthor;
|
|
280
|
+
/**
|
|
281
|
+
* Default SuperDoc user (used for editor initialization)
|
|
282
|
+
*/
|
|
283
|
+
declare const DEFAULT_SUPERDOC_USER: {
|
|
284
|
+
name: string;
|
|
285
|
+
email: string;
|
|
286
|
+
};
|
|
287
|
+
/**
|
|
288
|
+
* CSS class prefix for all component styles
|
|
289
|
+
*/
|
|
290
|
+
declare const CSS_PREFIX = "dde";
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Embedded minimal DOCX template
|
|
294
|
+
*
|
|
295
|
+
* This is a base64-encoded minimal DOCX file that provides the basic
|
|
296
|
+
* schema, styles, and fonts needed to initialize SuperDoc when working
|
|
297
|
+
* with HTML or JSON content.
|
|
298
|
+
*
|
|
299
|
+
* The DOCX contains:
|
|
300
|
+
* - Basic document structure
|
|
301
|
+
* - Standard styles (Normal, Heading 1-6, etc.)
|
|
302
|
+
* - Common font definitions (Calibri, Arial, Times New Roman)
|
|
303
|
+
* - Empty content (to be replaced with user content)
|
|
304
|
+
*/
|
|
305
|
+
/**
|
|
306
|
+
* Get the blank DOCX template as a File object
|
|
307
|
+
*/
|
|
308
|
+
declare function getBlankTemplateFile(): File;
|
|
309
|
+
/**
|
|
310
|
+
* Get the blank DOCX template as a Blob
|
|
311
|
+
*/
|
|
312
|
+
declare function getBlankTemplateBlob(): Blob;
|
|
313
|
+
/**
|
|
314
|
+
* Check if a File is a valid DOCX file (basic check)
|
|
315
|
+
*/
|
|
316
|
+
declare function isValidDocxFile(file: File): boolean;
|
|
317
|
+
|
|
318
|
+
export { CSS_PREFIX, type ChangeLocation, type ComparisonResult, DEFAULT_AUTHOR, DEFAULT_SUPERDOC_USER, type DiffResult, type DiffSegment, type DocxContent, DocxDiffEditor, type DocxDiffEditorProps, type DocxDiffEditorRef, type EnrichedChange, type FormatChange, type FormatDetails, type ProseMirrorJSON, type ProseMirrorMark, type ProseMirrorNode, type TrackChangeAuthor, createTrackDeleteMark, createTrackFormatMark, createTrackInsertMark, DocxDiffEditor as default, detectContentType, diffDocuments, extractEnrichedChanges, getBlankTemplateBlob, getBlankTemplateFile, isProseMirrorJSON, isValidDocxFile, mergeDocuments, parseDocxFile, parseHtmlContent, resolveContent };
|