docx-diff-editor 1.0.41 → 1.0.43

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 CHANGED
@@ -6,8 +6,9 @@ A React component for DOCX document comparison with track changes visualization.
6
6
 
7
7
  - 📄 Compare two DOCX documents side by side
8
8
  - 🔍 Character-level diff with track changes
9
- - 📊 **Block-level diffing** for tables, lists, and images
10
- - Accept/reject individual changes
9
+ - 📊 **Block-level structural diffing** for tables, lists, paragraphs, and images
10
+ - 🔄 **Structure-aware merge** - inserted/deleted blocks appear in the editor with track marks
11
+ - ✅ Accept/reject individual changes (both text and structural)
11
12
  - 🎨 Visual track changes (insert, delete, format)
12
13
  - 📋 **Structural Changes Pane** for table rows, list items, images
13
14
  - 🤖 Extract enriched change context for LLM processing
@@ -149,6 +150,9 @@ interface DocxDiffEditorRef {
149
150
 
150
151
  // Set document core properties (partial update)
151
152
  setProperties(properties: Partial<DocumentProperties>): Promise<boolean>;
153
+
154
+ // Parse HTML to ProseMirror JSON
155
+ parseHtml(html: string): Promise<ProseMirrorJSON>;
152
156
  }
153
157
  ```
154
158
 
@@ -251,6 +255,23 @@ await editorRef.current?.setProperties({
251
255
  });
252
256
  ```
253
257
 
258
+ ## Parsing HTML to JSON
259
+
260
+ Convert HTML strings to ProseMirror JSON without visible rendering:
261
+
262
+ ```tsx
263
+ // Using the ref method (requires editor to be initialized)
264
+ const json = await editorRef.current?.parseHtml('<h1>Title</h1><p>Content here</p>');
265
+ console.log(json); // { type: 'doc', content: [...] }
266
+
267
+ // Use with other methods
268
+ await editorRef.current?.updateContent(json);
269
+
270
+ // Or use the standalone function (requires SuperDoc class)
271
+ import { parseHtmlToJson } from 'docx-diff-editor';
272
+ const json = await parseHtmlToJson(htmlString, SuperDocClass);
273
+ ```
274
+
254
275
  ## Customization
255
276
 
256
277
  ### CSS Variables
@@ -292,6 +313,18 @@ The component supports three types of track changes:
292
313
 
293
314
  When comparing documents with structural differences (tables, lists, images), a floating pane appears showing these changes with Accept/Reject controls.
294
315
 
316
+ ### How It Works
317
+
318
+ The component uses a **structure-aware merge** approach:
319
+
320
+ 1. **Block alignment**: Documents are aligned at the block level (paragraphs, tables, lists) using content fingerprinting
321
+ 2. **Recursive merge**: Tables and lists are merged recursively (row-by-row, item-by-item)
322
+ 3. **Character-level diff**: Within matched blocks, character-level diffing is applied
323
+ 4. **Insert/delete marking**: New blocks get `trackInsert` marks; deleted blocks are preserved with `trackDelete` marks
324
+ 5. **Shared IDs**: Each structural change has a unique ID linking the track marks to the pane entry
325
+
326
+ This means inserted tables, paragraphs, and list items actually appear in the editor (with green highlighting), and deleted content remains visible (with red strikethrough) until you accept or reject the changes.
327
+
295
328
  ### What's Detected
296
329
 
297
330
  | Change Type | Description |
package/dist/index.d.mts CHANGED
@@ -362,6 +362,8 @@ interface DocxDiffEditorRef {
362
362
  getProperties(): Promise<DocumentProperties | null>;
363
363
  /** Set document core properties (partial update) */
364
364
  setProperties(properties: Partial<DocumentProperties>): Promise<boolean>;
365
+ /** Parse HTML string to ProseMirror JSON (uses hidden SuperDoc instance) */
366
+ parseHtml(html: string): Promise<ProseMirrorJSON>;
365
367
  }
366
368
 
367
369
  /**
@@ -420,6 +422,10 @@ declare function detectContentType(content: DocxContent): 'file' | 'html' | 'jso
420
422
  * Validate that content looks like ProseMirror JSON
421
423
  */
422
424
  declare function isProseMirrorJSON(content: unknown): boolean;
425
+ /**
426
+ * Parse an HTML string into ProseMirror JSON using a hidden SuperDoc instance.
427
+ */
428
+ declare function parseHtmlToJson(html: string, SuperDoc: SuperDocConstructor): Promise<ProseMirrorJSON>;
423
429
  /**
424
430
  * Parse a DOCX File into ProseMirror JSON using a hidden SuperDoc instance.
425
431
  */
@@ -710,4 +716,4 @@ declare function getBlankTemplateBlob(): Blob;
710
716
  */
711
717
  declare function isValidDocxFile(file: File): boolean;
712
718
 
713
- export { type AttrDiff, type AttributeChange, CSS_PREFIX, type ChangeLocation, type ComparisonResult, DEFAULT_AUTHOR, DEFAULT_SUPERDOC_USER, type DiffResult, type DiffSegment, type DocumentInfo, type DocumentProperties, type DocxContent, DocxDiffEditor, type DocxDiffEditorProps, type DocxDiffEditorRef, type EnrichedChange, type FingerprintedNode, type FormatChange, type FormatDetails, type HybridDiffResult, type NodeMatch, type ProseMirrorJSON, type ProseMirrorMark, type ProseMirrorNode, type StructuralChange, type StructuralChangeInfo, type StructuralChangeType, StructuralChangesPane, type StructuralPanePosition, type TrackChangeAuthor, alignDocuments, createTrackDeleteMark, createTrackFormatMark, createTrackInsertMark, DocxDiffEditor as default, detectContentType, diffDocuments, diffImages, diffLists, diffTables, extractEnrichedChanges, extractEnrichedChangesWithStructural, generateFingerprint, generateStructuralChangeSummary, getBlankTemplateBlob, getBlankTemplateFile, isAtomicNode, isImage, isList, isProseMirrorJSON, isTable, isValidDocxFile, mergeDocuments, parseDocxFile, processStructuralChanges };
719
+ export { type AttrDiff, type AttributeChange, CSS_PREFIX, type ChangeLocation, type ComparisonResult, DEFAULT_AUTHOR, DEFAULT_SUPERDOC_USER, type DiffResult, type DiffSegment, type DocumentInfo, type DocumentProperties, type DocxContent, DocxDiffEditor, type DocxDiffEditorProps, type DocxDiffEditorRef, type EnrichedChange, type FingerprintedNode, type FormatChange, type FormatDetails, type HybridDiffResult, type NodeMatch, type ProseMirrorJSON, type ProseMirrorMark, type ProseMirrorNode, type StructuralChange, type StructuralChangeInfo, type StructuralChangeType, StructuralChangesPane, type StructuralPanePosition, type TrackChangeAuthor, alignDocuments, createTrackDeleteMark, createTrackFormatMark, createTrackInsertMark, DocxDiffEditor as default, detectContentType, diffDocuments, diffImages, diffLists, diffTables, extractEnrichedChanges, extractEnrichedChangesWithStructural, generateFingerprint, generateStructuralChangeSummary, getBlankTemplateBlob, getBlankTemplateFile, isAtomicNode, isImage, isList, isProseMirrorJSON, isTable, isValidDocxFile, mergeDocuments, parseDocxFile, parseHtmlToJson, processStructuralChanges };
package/dist/index.d.ts CHANGED
@@ -362,6 +362,8 @@ interface DocxDiffEditorRef {
362
362
  getProperties(): Promise<DocumentProperties | null>;
363
363
  /** Set document core properties (partial update) */
364
364
  setProperties(properties: Partial<DocumentProperties>): Promise<boolean>;
365
+ /** Parse HTML string to ProseMirror JSON (uses hidden SuperDoc instance) */
366
+ parseHtml(html: string): Promise<ProseMirrorJSON>;
365
367
  }
366
368
 
367
369
  /**
@@ -420,6 +422,10 @@ declare function detectContentType(content: DocxContent): 'file' | 'html' | 'jso
420
422
  * Validate that content looks like ProseMirror JSON
421
423
  */
422
424
  declare function isProseMirrorJSON(content: unknown): boolean;
425
+ /**
426
+ * Parse an HTML string into ProseMirror JSON using a hidden SuperDoc instance.
427
+ */
428
+ declare function parseHtmlToJson(html: string, SuperDoc: SuperDocConstructor): Promise<ProseMirrorJSON>;
423
429
  /**
424
430
  * Parse a DOCX File into ProseMirror JSON using a hidden SuperDoc instance.
425
431
  */
@@ -710,4 +716,4 @@ declare function getBlankTemplateBlob(): Blob;
710
716
  */
711
717
  declare function isValidDocxFile(file: File): boolean;
712
718
 
713
- export { type AttrDiff, type AttributeChange, CSS_PREFIX, type ChangeLocation, type ComparisonResult, DEFAULT_AUTHOR, DEFAULT_SUPERDOC_USER, type DiffResult, type DiffSegment, type DocumentInfo, type DocumentProperties, type DocxContent, DocxDiffEditor, type DocxDiffEditorProps, type DocxDiffEditorRef, type EnrichedChange, type FingerprintedNode, type FormatChange, type FormatDetails, type HybridDiffResult, type NodeMatch, type ProseMirrorJSON, type ProseMirrorMark, type ProseMirrorNode, type StructuralChange, type StructuralChangeInfo, type StructuralChangeType, StructuralChangesPane, type StructuralPanePosition, type TrackChangeAuthor, alignDocuments, createTrackDeleteMark, createTrackFormatMark, createTrackInsertMark, DocxDiffEditor as default, detectContentType, diffDocuments, diffImages, diffLists, diffTables, extractEnrichedChanges, extractEnrichedChangesWithStructural, generateFingerprint, generateStructuralChangeSummary, getBlankTemplateBlob, getBlankTemplateFile, isAtomicNode, isImage, isList, isProseMirrorJSON, isTable, isValidDocxFile, mergeDocuments, parseDocxFile, processStructuralChanges };
719
+ export { type AttrDiff, type AttributeChange, CSS_PREFIX, type ChangeLocation, type ComparisonResult, DEFAULT_AUTHOR, DEFAULT_SUPERDOC_USER, type DiffResult, type DiffSegment, type DocumentInfo, type DocumentProperties, type DocxContent, DocxDiffEditor, type DocxDiffEditorProps, type DocxDiffEditorRef, type EnrichedChange, type FingerprintedNode, type FormatChange, type FormatDetails, type HybridDiffResult, type NodeMatch, type ProseMirrorJSON, type ProseMirrorMark, type ProseMirrorNode, type StructuralChange, type StructuralChangeInfo, type StructuralChangeType, StructuralChangesPane, type StructuralPanePosition, type TrackChangeAuthor, alignDocuments, createTrackDeleteMark, createTrackFormatMark, createTrackInsertMark, DocxDiffEditor as default, detectContentType, diffDocuments, diffImages, diffLists, diffTables, extractEnrichedChanges, extractEnrichedChangesWithStructural, generateFingerprint, generateStructuralChangeSummary, getBlankTemplateBlob, getBlankTemplateFile, isAtomicNode, isImage, isList, isProseMirrorJSON, isTable, isValidDocxFile, mergeDocuments, parseDocxFile, parseHtmlToJson, processStructuralChanges };