@haklex/rich-diff-core 0.24.0 → 0.25.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/README.md +95 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# @haklex/rich-diff-core
|
|
2
|
+
|
|
3
|
+
Headless Lexical diff engine providing character-level and structural diffing between two editor states, with node decoration for visual annotation. Zero UI dependencies — shared by the `@haklex/rich-diff` viewer and `@haklex/rich-agent-core` for AI edit review.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @haklex/rich-diff-core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Peer Dependencies
|
|
12
|
+
|
|
13
|
+
| Package | Version |
|
|
14
|
+
| --------- | --------- |
|
|
15
|
+
| `lexical` | `^0.45.0` |
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
### Compute a diff between two editor states
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { computeDiff } from '@haklex/rich-diff-core';
|
|
23
|
+
|
|
24
|
+
const hunks = computeDiff(beforeEditorState, afterEditorState);
|
|
25
|
+
// hunks: DiffHunk[] with op: 'add' | 'remove' | 'equal'
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Decorate nodes with diff annotations
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import { decorateSubtree, diffMergedNode, diffModifiedNode } from '@haklex/rich-diff-core';
|
|
32
|
+
|
|
33
|
+
// Decorate a subtree to show additions/removals
|
|
34
|
+
const decorated = decorateSubtree(rootNode, hunks);
|
|
35
|
+
|
|
36
|
+
// Mark a single merged (modified) node
|
|
37
|
+
const merged = diffMergedNode(node);
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Compute and format diff statistics
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import { computeDeltaStats, formatDeltaStats } from '@haklex/rich-diff-core';
|
|
44
|
+
|
|
45
|
+
const stats = computeDeltaStats(beforeState, afterState);
|
|
46
|
+
// { addedChars: 42, removedChars: 10, addedNodes: 3, removedNodes: 1 }
|
|
47
|
+
|
|
48
|
+
const summary = formatDeltaStats(stats);
|
|
49
|
+
// "+42 / -10 characters, +3 / -1 nodes"
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Exports
|
|
53
|
+
|
|
54
|
+
### Core Diff
|
|
55
|
+
|
|
56
|
+
| Export | Description |
|
|
57
|
+
| ---------------------------- | -------------------------------------------------------- |
|
|
58
|
+
| `computeDiff(before, after)` | Compute diff hunks between two `EditorState` objects |
|
|
59
|
+
| `DiffHunk` | A single diff hunk with `op` type and content |
|
|
60
|
+
| `DiffOpType` | Diff operation type (`'add'` \| `'remove'` \| `'equal'`) |
|
|
61
|
+
| `MarkKind` | Mark decoration kind (`'add'` \| `'remove'`) |
|
|
62
|
+
|
|
63
|
+
### Decoration
|
|
64
|
+
|
|
65
|
+
| Export | Description |
|
|
66
|
+
| ------------------------------ | ------------------------------------------- |
|
|
67
|
+
| `decorateSubtree(node, hunks)` | Apply diff decorations to a node subtree |
|
|
68
|
+
| `diffMergedNode(node)` | Mark a node as modified (merged add/remove) |
|
|
69
|
+
| `diffModifiedNode(node)` | Mark a node with inline modified marks |
|
|
70
|
+
|
|
71
|
+
### Statistics
|
|
72
|
+
|
|
73
|
+
| Export | Description |
|
|
74
|
+
| ---------------------------------- | -------------------------------------------------- |
|
|
75
|
+
| `computeDeltaStats(before, after)` | Compute character and node-level delta statistics |
|
|
76
|
+
| `formatDeltaStats(stats)` | Format delta stats as a human-readable string |
|
|
77
|
+
| `DeltaStats` | Type for diff statistics (character + node counts) |
|
|
78
|
+
|
|
79
|
+
### Sub-path Exports
|
|
80
|
+
|
|
81
|
+
| Import Path | Description |
|
|
82
|
+
| ------------------------ | ------------------------------------------------------ |
|
|
83
|
+
| `@haklex/rich-diff-core` | Full exports — diff engine, decoration, and statistics |
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
> **Note:** This package is headless (no React, no DOM). For a React diff viewer component, see `@haklex/rich-diff`.
|
|
88
|
+
|
|
89
|
+
## Part of Haklex
|
|
90
|
+
|
|
91
|
+
This package is part of the [Haklex](../../README.md) rich editor ecosystem.
|
|
92
|
+
|
|
93
|
+
## License
|
|
94
|
+
|
|
95
|
+
MIT
|