|
1 | 1 | # virtualized-diff-viewer |
2 | 2 |
|
3 | | -A high-performance React diff viewer built for large files. |
| 3 | +A high-performance, virtualized React diff viewer designed for **very large text files** and smooth developer experience. |
| 4 | + |
| 5 | +> Package name on npm: **`react-virtualized-diff`** |
| 6 | +
|
| 7 | +[中文文档(Chinese README)](./README.zh-CN.md) |
| 8 | + |
| 9 | +--- |
| 10 | + |
| 11 | +## Why this project |
| 12 | + |
| 13 | +Most diff viewers are good for small files but become slow when input grows to tens of thousands of lines. |
| 14 | + |
| 15 | +`virtualized-diff-viewer` focuses on: |
| 16 | + |
| 17 | +- **Performance first** rendering with virtualization |
| 18 | +- **Readable side-by-side UI** for code/text review |
| 19 | +- **Configurable context lines** around changes |
| 20 | +- **TypeScript support** for reliable integration |
| 21 | +- **Simple React API** for quick adoption |
4 | 22 |
|
5 | 23 | --- |
6 | 24 |
|
7 | | -## ✨ Features |
| 25 | +## Features |
8 | 26 |
|
9 | | -- Side-by-side diff view |
10 | | -- Virtualized rendering for large files |
11 | | -- Collapsed unchanged blocks |
12 | | -- Configurable context lines |
13 | | -- TypeScript support |
| 27 | +- ✅ Side-by-side diff layout |
| 28 | +- ✅ Virtualized row rendering (good for large files) |
| 29 | +- ✅ Collapsed unchanged blocks with configurable context |
| 30 | +- ✅ Lightweight integration in React apps |
| 31 | +- ✅ TypeScript declarations out of the box |
14 | 32 |
|
15 | 33 | --- |
16 | 34 |
|
17 | | -## 📦 Installation |
| 35 | +## Installation |
18 | 36 |
|
19 | 37 | ```bash |
| 38 | +# pnpm |
20 | 39 | pnpm add react-virtualized-diff |
| 40 | + |
| 41 | +# npm |
| 42 | +npm install react-virtualized-diff |
| 43 | + |
| 44 | +# yarn |
| 45 | +yarn add react-virtualized-diff |
21 | 46 | ``` |
22 | 47 |
|
23 | 48 | --- |
24 | 49 |
|
25 | | -## 🚀 Usage |
| 50 | +## Quick start |
26 | 51 |
|
27 | 52 | ```tsx |
28 | 53 | import { DiffViewer } from 'react-virtualized-diff'; |
29 | 54 |
|
30 | | -function Example() { |
| 55 | +const oldText = `line 1\nline 2\nline 3`; |
| 56 | +const newText = `line 1\nline 2 changed\nline 3\nline 4`; |
| 57 | + |
| 58 | +export function Example() { |
31 | 59 | return ( |
32 | 60 | <DiffViewer |
33 | 61 | original={oldText} |
34 | 62 | modified={newText} |
35 | 63 | contextLines={2} |
36 | | - height={500} |
| 64 | + height={480} |
37 | 65 | /> |
38 | 66 | ); |
39 | 67 | } |
40 | 68 | ``` |
41 | 69 |
|
42 | 70 | --- |
43 | 71 |
|
44 | | -## 🧠 Why this project? |
| 72 | +## API (current) |
| 73 | + |
| 74 | +### `DiffViewer` props |
| 75 | + |
| 76 | +- `original: string` – original text content |
| 77 | +- `modified: string` – modified text content |
| 78 | +- `contextLines?: number` – unchanged lines to keep around changes (default behavior from component) |
| 79 | +- `height?: number | string` – viewport height for virtualization container |
| 80 | + |
| 81 | +> Tip: for best performance with huge files, keep rendering area constrained with a fixed `height`. |
45 | 82 |
|
46 | | -Most React diff viewers work well for small files but struggle with large inputs. |
| 83 | +--- |
47 | 84 |
|
48 | | -This project focuses on: |
| 85 | +## Monorepo structure |
49 | 86 |
|
50 | | -- Rendering large diffs efficiently |
51 | | -- Reducing unnecessary DOM nodes |
52 | | -- Keeping interaction smooth even with 100k+ lines |
| 87 | +```text |
| 88 | +apps/demo/ # Vite demo app |
| 89 | +packages/react/ # npm package: react-virtualized-diff |
| 90 | +``` |
53 | 91 |
|
54 | 92 | --- |
55 | 93 |
|
56 | | -## 🛠 Development |
| 94 | +## Local development |
57 | 95 |
|
58 | 96 | ```bash |
59 | 97 | pnpm install |
60 | | -pnpm dev |
61 | | -pnpm build |
| 98 | +pnpm dev # run demo app |
| 99 | +pnpm build # build workspace packages |
62 | 100 | ``` |
63 | 101 |
|
64 | 102 | --- |
65 | 103 |
|
66 | | -## 📊 Roadmap |
| 104 | +## npm package README support |
| 105 | + |
| 106 | +To ensure npm users always see correct documentation: |
| 107 | + |
| 108 | +- Package-level README is maintained at `packages/react/README.md` |
| 109 | +- `packages/react/package.json` includes README in publish files |
| 110 | +- Root README links to the package docs and Chinese docs |
| 111 | + |
| 112 | +--- |
| 113 | + |
| 114 | +## Release log |
| 115 | + |
| 116 | +See [CHANGELOG.md](./CHANGELOG.md) for tracked releases and supported capabilities. |
| 117 | + |
| 118 | +--- |
| 119 | + |
| 120 | +## Future plan |
| 121 | + |
| 122 | +### Near-term roadmap |
| 123 | + |
| 124 | +- [ ] Optional syntax highlighting (performance-aware) |
| 125 | +- [ ] More comprehensive live demo scenarios (big files, mixed edits) |
| 126 | +- [ ] Public hosted demo site for quick evaluation |
| 127 | +- [ ] Better customization hooks (line renderers, gutters) |
| 128 | + |
| 129 | +### Additional TODOs to make this project more popular |
67 | 130 |
|
68 | | -- [ ] Syntax highlighting (optional, performance-aware) |
69 | | -- [ ] Custom render hooks |
70 | | -- [ ] Worker-based diff computation |
71 | | -- [ ] Benchmark suite |
| 131 | +- [ ] Detailed benchmark report vs common diff viewers |
| 132 | +- [ ] Keyboard navigation + accessibility improvements |
| 133 | +- [ ] Dark/light theme presets and design tokens |
| 134 | +- [ ] SSR usage guide (Next.js / Remix examples) |
| 135 | +- [ ] More real-world examples (JSON, logs, markdown, code) |
| 136 | +- [ ] CI release automation + semantic versioning workflow |
| 137 | +- [ ] Contribution guide and issue templates |
| 138 | +- [ ] International docs beyond English/Chinese |
72 | 139 |
|
73 | 140 | --- |
74 | 141 |
|
75 | | -## 📄 License |
| 142 | +## License |
76 | 143 |
|
77 | | -MIT License |
| 144 | +MIT |
0 commit comments