docx-diff-editor 1.0.42 → 1.0.44

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
@@ -256,13 +257,19 @@ await editorRef.current?.setProperties({
256
257
 
257
258
  ## Parsing HTML to JSON
258
259
 
259
- Convert HTML strings to ProseMirror JSON without visible rendering:
260
+ Convert HTML strings to ProseMirror JSON without visible rendering. **Inline styles are preserved!**
260
261
 
261
262
  ```tsx
262
263
  // Using the ref method (requires editor to be initialized)
263
264
  const json = await editorRef.current?.parseHtml('<h1>Title</h1><p>Content here</p>');
264
265
  console.log(json); // { type: 'doc', content: [...] }
265
266
 
267
+ // Inline styles are converted to marks
268
+ const styledJson = await editorRef.current?.parseHtml(
269
+ '<p><span style="color: red; font-weight: bold;">styled text</span></p>'
270
+ );
271
+ // Result: text with textStyle mark (color) and bold mark
272
+
266
273
  // Use with other methods
267
274
  await editorRef.current?.updateContent(json);
268
275
 
@@ -271,6 +278,19 @@ import { parseHtmlToJson } from 'docx-diff-editor';
271
278
  const json = await parseHtmlToJson(htmlString, SuperDocClass);
272
279
  ```
273
280
 
281
+ ### Supported Inline Styles
282
+
283
+ | CSS Property | ProseMirror Mark |
284
+ |--------------|------------------|
285
+ | `color` | `textStyle.color` |
286
+ | `font-size` | `textStyle.fontSize` |
287
+ | `font-family` | `textStyle.fontFamily` |
288
+ | `font-weight: bold` | `bold` |
289
+ | `font-style: italic` | `italic` |
290
+ | `text-decoration: underline` | `underline` |
291
+ | `text-decoration: line-through` | `strike` |
292
+ | `background-color` | `highlight.color` |
293
+
274
294
  ## Customization
275
295
 
276
296
  ### CSS Variables
@@ -312,6 +332,18 @@ The component supports three types of track changes:
312
332
 
313
333
  When comparing documents with structural differences (tables, lists, images), a floating pane appears showing these changes with Accept/Reject controls.
314
334
 
335
+ ### How It Works
336
+
337
+ The component uses a **structure-aware merge** approach:
338
+
339
+ 1. **Block alignment**: Documents are aligned at the block level (paragraphs, tables, lists) using content fingerprinting
340
+ 2. **Recursive merge**: Tables and lists are merged recursively (row-by-row, item-by-item)
341
+ 3. **Character-level diff**: Within matched blocks, character-level diffing is applied
342
+ 4. **Insert/delete marking**: New blocks get `trackInsert` marks; deleted blocks are preserved with `trackDelete` marks
343
+ 5. **Shared IDs**: Each structural change has a unique ID linking the track marks to the pane entry
344
+
345
+ 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.
346
+
315
347
  ### What's Detected
316
348
 
317
349
  | Change Type | Description |
package/dist/index.d.mts CHANGED
@@ -424,6 +424,18 @@ declare function detectContentType(content: DocxContent): 'file' | 'html' | 'jso
424
424
  declare function isProseMirrorJSON(content: unknown): boolean;
425
425
  /**
426
426
  * Parse an HTML string into ProseMirror JSON using a hidden SuperDoc instance.
427
+ *
428
+ * IMPORTANT: Uses the "paste" approach instead of the "import" approach.
429
+ * SuperDoc's import path (via `html` option) calls `stripHtmlStyles()` which
430
+ * removes all CSS styles except `text-align`. The paste path (via `view.pasteHTML()`)
431
+ * preserves inline styles like color, font-size, font-family, font-weight, etc.
432
+ *
433
+ * Flow:
434
+ * 1. Create SuperDoc with empty HTML document
435
+ * 2. Wait for editor to be ready
436
+ * 3. Select all content and delete it (start fresh)
437
+ * 4. Use editor.view.pasteHTML(html) - this uses the paste path which preserves styles
438
+ * 5. Return the resulting JSON
427
439
  */
428
440
  declare function parseHtmlToJson(html: string, SuperDoc: SuperDocConstructor): Promise<ProseMirrorJSON>;
429
441
  /**
package/dist/index.d.ts CHANGED
@@ -424,6 +424,18 @@ declare function detectContentType(content: DocxContent): 'file' | 'html' | 'jso
424
424
  declare function isProseMirrorJSON(content: unknown): boolean;
425
425
  /**
426
426
  * Parse an HTML string into ProseMirror JSON using a hidden SuperDoc instance.
427
+ *
428
+ * IMPORTANT: Uses the "paste" approach instead of the "import" approach.
429
+ * SuperDoc's import path (via `html` option) calls `stripHtmlStyles()` which
430
+ * removes all CSS styles except `text-align`. The paste path (via `view.pasteHTML()`)
431
+ * preserves inline styles like color, font-size, font-family, font-weight, etc.
432
+ *
433
+ * Flow:
434
+ * 1. Create SuperDoc with empty HTML document
435
+ * 2. Wait for editor to be ready
436
+ * 3. Select all content and delete it (start fresh)
437
+ * 4. Use editor.view.pasteHTML(html) - this uses the paste path which preserves styles
438
+ * 5. Return the resulting JSON
427
439
  */
428
440
  declare function parseHtmlToJson(html: string, SuperDoc: SuperDocConstructor): Promise<ProseMirrorJSON>;
429
441
  /**