virtual-react-json-diff 1.0.14 β 1.0.16
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 +168 -89
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/demo/src/App.d.ts +1 -1
- package/dist/cjs/types/demo/src/types/index.d.ts +6 -0
- package/dist/cjs/types/src/components/DiffViewer/components/LineCountDisplay.d.ts +7 -0
- package/dist/cjs/types/src/components/DiffViewer/components/ObjectCountDisplay.d.ts +7 -0
- package/dist/cjs/types/src/components/DiffViewer/components/SearchboxHolder.d.ts +1 -1
- package/dist/cjs/types/src/components/DiffViewer/components/VirtualDiffGrid.d.ts +3 -3
- package/dist/cjs/types/src/components/DiffViewer/types/index.d.ts +17 -0
- package/dist/cjs/types/src/components/DiffViewer/utils/diffComparisonOptions.d.ts +16 -0
- package/dist/cjs/types/src/components/DiffViewer/utils/json-diff/row-renderer-grid.d.ts +2 -2
- package/dist/cjs/types/src/components/DiffViewer/utils/lineCountUtils.d.ts +3 -0
- package/dist/cjs/types/src/components/DiffViewer/utils/objectCountUtils.d.ts +5 -0
- package/dist/cjs/types/src/components/SearchIcon.d.ts +1 -1
- package/dist/cjs/types/src/index.d.ts +2 -0
- package/dist/index.d.ts +27 -1
- package/package.json +4 -2
- package/dist/cjs/types/demo/vite.config.d.ts +0 -2
- package/dist/cjs/types/src/components/DiffViewer/components/ViewerRow.d.ts +0 -11
- package/dist/cjs/types/src/components/DiffViewer/components/VirtualDiffTable.d.ts +0 -19
- package/dist/cjs/types/src/components/DiffViewer/utils/json-diff/row-renderer.d.ts +0 -10
package/README.md
CHANGED
|
@@ -1,72 +1,83 @@
|
|
|
1
|
-
#
|
|
1
|
+
# virtual-react-json-diff
|
|
2
2
|
|
|
3
3
|
[![NPM version][npm-image]][npm-url]
|
|
4
4
|
[![Downloads][download-badge]][npm-url]
|
|
5
5
|

|
|
6
6
|
[](https://www.buymeacoffee.com/utkuakyuz)
|
|
7
7
|
|
|
8
|
-
π [Try it now](https://virtual-react-json-diff.netlify.app)
|
|
8
|
+
π [Try it now](https://virtual-react-json-diff.netlify.app)
|
|
9
9
|
|
|
10
|
-
A high-performance React
|
|
10
|
+
A high-performance React JSON diff viewer for **large, real-world JSON data**.
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
- Custom theming (Soon new themes will be available)
|
|
14
|
-
- Dual Mini Map
|
|
15
|
-
- π Search functionality
|
|
16
|
-
- βοΈ Optimized for React (uses `react-window`)
|
|
12
|
+
Built to handle **tens of thousands of lines without freezing the UI**, it uses virtualized rendering to stay fast and responsive even in production-scale scenarios.
|
|
17
13
|
|
|
18
|
-
|
|
14
|
+
Powered by [json-diff-kit](https://www.npmjs.com/package/json-diff-kit), it supports virtual scrolling, advanced comparison options, search, dual minimaps, and customizable theming.
|
|
19
15
|
|
|
20
|
-
##
|
|
16
|
+
## Why virtual-react-json-diff exists
|
|
21
17
|
|
|
22
|
-
|
|
23
|
-
- **Virtualized Rendering** β Efficient DOM updates using `react-window`
|
|
24
|
-
- **Search Highlighting** β Find matches and scroll directly to them
|
|
25
|
-
- **Mini Map** β Dual scrollable minimap of Json Diff, scaled to better see comparison result
|
|
26
|
-
- **Customizable Styles** β Add your own class names and styles easily (checkout JsonDiffCustomTheme.css)
|
|
18
|
+
Most JSON diff viewers work well for **small examples**, but start breaking down in real-world scenarios:
|
|
27
19
|
|
|
28
|
-
|
|
20
|
+
* Large JSON files cause the UI to freeze or crash
|
|
21
|
+
* Rendering thousands of DOM nodes makes scrolling unusable
|
|
22
|
+
* Array changes are hard to reason about without object-level comparison
|
|
23
|
+
* Itβs difficult to understand the *impact* of changes beyond raw diffs
|
|
29
24
|
|
|
30
|
-
|
|
25
|
+
**virtual-react-json-diff** was built to solve these problems.
|
|
31
26
|
|
|
32
|
-
|
|
27
|
+
It is designed for internal dashboards and developer tools that need to compare **large, deeply nested JSON objects** efficiently and interactively.
|
|
33
28
|
|
|
34
|
-
|
|
35
|
-
npm install virtual-react-json-diff
|
|
36
|
-
# or
|
|
37
|
-
yarn add virtual-react-json-diff
|
|
38
|
-
# or
|
|
39
|
-
pnpm add virtual-react-json-diff
|
|
40
|
-
```
|
|
29
|
+
## Key Features
|
|
41
30
|
|
|
42
|
-
|
|
31
|
+
virtual-react-json-diff is designed for scenarios where traditional diff viewers become unusable due to size or complexity.
|
|
43
32
|
|
|
44
|
-
|
|
33
|
+
### Built for Large JSONs
|
|
45
34
|
|
|
46
|
-
|
|
35
|
+
* **Virtualized rendering** powered by `react-window`
|
|
36
|
+
* Smooth scrolling and interaction even with very large diffs
|
|
47
37
|
|
|
48
|
-
|
|
38
|
+
### Navigate Complex Changes
|
|
49
39
|
|
|
50
|
-
|
|
40
|
+
* **Dual minimap** with visual change indicators
|
|
41
|
+
* Jump directly to changes using **search highlighting**
|
|
42
|
+
* Optional single minimap for compact layouts
|
|
51
43
|
|
|
52
|
-
|
|
44
|
+
### Understand Change Impact
|
|
53
45
|
|
|
54
|
-
|
|
46
|
+
* **Line count statistics** for added, removed, and modified lines
|
|
47
|
+
* **Object-level statistics** when using compare-key array diffs
|
|
48
|
+
* Quickly assess how big or risky a change really is
|
|
55
49
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
arrayDiffMethod: "lcs",
|
|
62
|
-
preserveKeyOrder: "before",
|
|
63
|
-
...differOptions,
|
|
64
|
-
}),
|
|
65
|
-
```
|
|
50
|
+
### Advanced Comparison Control
|
|
51
|
+
|
|
52
|
+
* Ignore specific keys or paths anywhere in the JSON tree
|
|
53
|
+
* Multiple comparison strategies (`strict`, `loose`, `type-aware`)
|
|
54
|
+
* Fine-grained control over how values are considered equal
|
|
66
55
|
|
|
67
|
-
|
|
56
|
+
### Customizable & Extensible
|
|
57
|
+
|
|
58
|
+
* Custom class names for theming
|
|
59
|
+
* Inline diff customization
|
|
60
|
+
* Access raw diff data for advanced use cases
|
|
61
|
+
|
|
62
|
+
## Demo
|
|
68
63
|
|
|
64
|
+
π [Try it now](https://virtual-react-json-diff.netlify.app) - Interactive demo with live examples
|
|
65
|
+
|
|
66
|
+

|
|
67
|
+
|
|
68
|
+
## Installation
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
npm install virtual-react-json-diff
|
|
72
|
+
# or
|
|
73
|
+
yarn add virtual-react-json-diff
|
|
74
|
+
# or
|
|
75
|
+
pnpm add virtual-react-json-diff
|
|
69
76
|
```
|
|
77
|
+
|
|
78
|
+
## Usage
|
|
79
|
+
|
|
80
|
+
```jsx
|
|
70
81
|
import { VirtualDiffViewer } from "virtual-react-json-diff";
|
|
71
82
|
|
|
72
83
|
const oldData = { name: "Alice", age: 25 };
|
|
@@ -78,86 +89,154 @@ export default function App() {
|
|
|
78
89
|
oldValue={oldData}
|
|
79
90
|
newValue={newData}
|
|
80
91
|
height={600}
|
|
81
|
-
|
|
92
|
+
showLineCount={true}
|
|
93
|
+
showObjectCountStats={false}
|
|
82
94
|
/>
|
|
83
95
|
);
|
|
84
96
|
}
|
|
85
97
|
```
|
|
86
98
|
|
|
87
|
-
|
|
99
|
+
## Understanding Diff Configuration
|
|
88
100
|
|
|
89
|
-
|
|
101
|
+
The viewer exposes **two different configuration layers**, each serving a distinct purpose.
|
|
90
102
|
|
|
91
|
-
|
|
92
|
-
import { type DiffResult, VirtualDiffViewer } from "virtual-react-json-diff";
|
|
103
|
+
### Quick Mental Model
|
|
93
104
|
|
|
94
|
-
|
|
105
|
+
* **`differOptions`** β Controls **how the diff is generated**
|
|
106
|
+
* **`comparisonOptions`** β Controls **what is compared and how values are matched**
|
|
95
107
|
|
|
96
|
-
|
|
108
|
+
### `differOptions` β *How the diff works*
|
|
109
|
+
|
|
110
|
+
These options are passed directly to the underlying diff engine.
|
|
111
|
+
|
|
112
|
+
Use them to:
|
|
113
|
+
|
|
114
|
+
* Choose how arrays are compared (`compare-key`, positional, etc.)
|
|
115
|
+
* Define comparison keys for object arrays
|
|
116
|
+
* Control depth, circular detection, and modification behavior
|
|
117
|
+
|
|
118
|
+
```jsx
|
|
119
|
+
differOptions={{
|
|
120
|
+
arrayDiffMethod: "compare-key",
|
|
121
|
+
compareKey: "id",
|
|
122
|
+
maxDepth: 999
|
|
123
|
+
}}
|
|
97
124
|
```
|
|
98
125
|
|
|
99
|
-
|
|
126
|
+
### `comparisonOptions` β *What is considered equal or ignored*
|
|
100
127
|
|
|
101
|
-
|
|
128
|
+
These options affect comparison behavior **without changing the diff structure**.
|
|
129
|
+
|
|
130
|
+
Use them to:
|
|
131
|
+
|
|
132
|
+
* Ignore volatile fields (timestamps, metadata)
|
|
133
|
+
* Exclude specific paths
|
|
134
|
+
* Compare values across types
|
|
135
|
+
|
|
136
|
+
```jsx
|
|
137
|
+
comparisonOptions={{
|
|
138
|
+
ignoreKeys: ["updatedAt", "__typename"],
|
|
139
|
+
ignorePaths: ["meta.timestamp"],
|
|
140
|
+
compareStrategy: "type-aware"
|
|
141
|
+
}}
|
|
142
|
+
```
|
|
102
143
|
|
|
144
|
+
### Using Both Together
|
|
145
|
+
|
|
146
|
+
```jsx
|
|
147
|
+
<VirtualDiffViewer
|
|
148
|
+
oldValue={oldData}
|
|
149
|
+
newValue={newData}
|
|
150
|
+
differOptions={{
|
|
151
|
+
arrayDiffMethod: "compare-key",
|
|
152
|
+
compareKey: "id"
|
|
153
|
+
}}
|
|
154
|
+
comparisonOptions={{
|
|
155
|
+
ignoreKeys: ["updatedAt"],
|
|
156
|
+
compareStrategy: "type-aware"
|
|
157
|
+
}}
|
|
158
|
+
/>
|
|
103
159
|
```
|
|
104
|
-
|
|
160
|
+
|
|
161
|
+
This separation keeps the diff engine flexible while allowing precise control over comparison behavior.
|
|
162
|
+
|
|
163
|
+
## Props
|
|
164
|
+
|
|
165
|
+
### Required
|
|
166
|
+
|
|
167
|
+
| Prop | Type | Description |
|
|
168
|
+
| ---------- | -------- | --------------------------------- |
|
|
169
|
+
| `oldValue` | `object` | Original JSON object (left side). |
|
|
170
|
+
| `newValue` | `object` | Updated JSON object (right side). |
|
|
171
|
+
|
|
105
172
|
---
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
173
|
+
|
|
174
|
+
### Layout & Display
|
|
175
|
+
|
|
176
|
+
| Prop | Type | Default | Description |
|
|
177
|
+
| ------------ | -------- | ------- | ----------------------------------------------- |
|
|
178
|
+
| `height` | `number` | β | Height of the diff viewer in pixels. |
|
|
179
|
+
| `leftTitle` | `string` | β | Optional title shown above the left panel. |
|
|
180
|
+
| `rightTitle` | `string` | β | Optional title shown above the right panel. |
|
|
181
|
+
| `className` | `string` | β | Custom CSS class applied to the root container. |
|
|
111
182
|
|
|
112
183
|
---
|
|
113
184
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
185
|
+
### Search & Navigation
|
|
186
|
+
|
|
187
|
+
| Prop | Type | Default | Description |
|
|
188
|
+
| ------------------- | ------------------------- | ------- | ----------------------------------------------- |
|
|
189
|
+
| `hideSearch` | `boolean` | `false` | Hides the search bar when set to `true`. |
|
|
190
|
+
| `searchTerm` | `string` | `""` | Initial search term to highlight in the diff. |
|
|
191
|
+
| `onSearchMatch` | `(index: number) => void` | β | Callback fired when a search match is found. |
|
|
192
|
+
| `showSingleMinimap` | `boolean` | `false` | Show a single minimap instead of dual minimaps. |
|
|
193
|
+
| `miniMapWidth` | `number` | `40` | Width of each minimap in pixels. |
|
|
117
194
|
|
|
118
195
|
---
|
|
119
196
|
|
|
120
|
-
|
|
197
|
+
### Statistics & Insights
|
|
121
198
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
199
|
+
| Prop | Type | Default | Description |
|
|
200
|
+
| ---------------------- | --------- | ------- | -------------------------------------------------------------------- |
|
|
201
|
+
| `showLineCount` | `boolean` | `false` | Display added, removed, and modified **line** counts. |
|
|
202
|
+
| `showObjectCountStats` | `boolean` | `false` | Display **object-level** stats (requires compare-key array diffing). |
|
|
125
203
|
|
|
126
|
-
|
|
204
|
+
> **Note:** `showObjectCountStats` only works when
|
|
205
|
+
> `differOptions.arrayDiffMethod = "compare-key"` and `compareKey` is provided.
|
|
127
206
|
|
|
128
|
-
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
### Diff Configuration
|
|
210
|
+
|
|
211
|
+
| Prop | Type | Default | Description |
|
|
212
|
+
| ------------------- | ----------------------- | ------------------ | ------------------------------------------------------------- |
|
|
213
|
+
| `differOptions` | `DifferOptions` | Engine defaults | Controls **how the diff is generated** (arrays, depth, keys). |
|
|
214
|
+
| `comparisonOptions` | `DiffComparisonOptions` | β | Controls **what is compared and how values match**. |
|
|
215
|
+
| `inlineDiffOptions` | `InlineDiffOptions` | `{ mode: "char" }` | Fine-tune inline diff rendering behavior. |
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
### Advanced & Utility
|
|
220
|
+
|
|
221
|
+
| Prop | Type | Default | Description |
|
|
222
|
+
| ------------- | -------------------------------------------------- | ------- | ----------------------------------------------------------- |
|
|
223
|
+
| `getDiffData` | `(diffData: [DiffResult[], DiffResult[]]) => void` | β | Access raw diff results for custom processing or analytics. |
|
|
224
|
+
|
|
225
|
+
## Styling
|
|
129
226
|
|
|
130
|
-
|
|
131
|
-
| ------------------- | -------------------------------------------------- | ------------------ | ---------------------------------------------------------------------- |
|
|
132
|
-
| `oldValue` | `object` | β | The original JSON object to compare (left side). |
|
|
133
|
-
| `newValue` | `object` | β | The updated JSON object to compare (right side). |
|
|
134
|
-
| `height` | `number` | β | Height of the diff viewer in pixels. |
|
|
135
|
-
| `hideSearch` | `boolean` | `false` | Hides the search bar if set to `true`. |
|
|
136
|
-
| `searchTerm` | `string` | `""` | Initial search keyword to highlight within the diff. |
|
|
137
|
-
| `leftTitle` | `string` | β | Optional title to display above the left diff panel. |
|
|
138
|
-
| `rightTitle` | `string` | β | Optional title to display above the right diff panel. |
|
|
139
|
-
| `onSearchMatch` | `(index: number) => void` | β | Callback fired when a search match is found. Receives the match index. |
|
|
140
|
-
| `differOptions` | `DifferOptions` | `Given Above` | Advanced options passed to the diffing engine. |
|
|
141
|
-
| `showSingleMinimap` | `boolean` | `false` | If `true`, shows only one minimap instead of two. |
|
|
142
|
-
| `className` | `string` | β | Custom CSS class for styling the viewer container. |
|
|
143
|
-
| `overScanCount` | `number` | `28` | Number of rendered rows outside of the viewport for virtualization |
|
|
144
|
-
| `miniMapWidth` | `number` | `40` | Width of each minimap in pixels. |
|
|
145
|
-
| `inlineDiffOptions` | `InlineDiffOptions` | `{'mode': 'char'}` | Options for fine-tuning inline diff rendering. |
|
|
146
|
-
| `getDiffData` | `(diffData: [DiffResult[], DiffResult[]]) => void` | - | Get difference data and make operations |
|
|
147
|
-
| `customDiffer` | `Differ` | - | Pass custom differ - not recommended |
|
|
227
|
+
The component exposes a root container with class `diff-viewer-container`. You can pass your own class name via the `className` prop to apply custom themes.
|
|
148
228
|
|
|
149
229
|
## π Acknowledgements
|
|
150
230
|
|
|
151
|
-
Built on top of the awesome json-diff-kit.
|
|
231
|
+
Built on top of the awesome [json-diff-kit](https://www.npmjs.com/package/json-diff-kit).
|
|
152
232
|
|
|
153
|
-
##
|
|
233
|
+
## License
|
|
154
234
|
|
|
155
235
|
MIT Β© Utku AkyΓΌz
|
|
156
236
|
|
|
157
|
-
##
|
|
237
|
+
## Contributing
|
|
158
238
|
|
|
159
239
|
Pull requests, suggestions, and issues are welcome!
|
|
160
|
-
Check out the issues or open a PR.
|
|
161
240
|
|
|
162
241
|
[npm-url]: https://npmjs.org/package/virtual-react-json-diff
|
|
163
242
|
[npm-image]: https://img.shields.io/npm/v/virtual-react-json-diff.svg
|