Skip to content

Commit 50c80e6

Browse files
committed
chore: version update
1 parent 18809ca commit 50c80e6

File tree

3 files changed

+90
-91
lines changed

3 files changed

+90
-91
lines changed

README.md

Lines changed: 87 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,26 @@
55
![bundle size](https://badgen.net/bundlephobia/minzip/virtual-react-json-diff)
66
[![BuyMeACoffee](https://raw.githubusercontent.com/pachadotdev/buymeacoffee-badges/main/bmc-yellow.svg)](https://www.buymeacoffee.com/utkuakyuz)
77

8-
👉 [Try it now](https://virtual-react-json-diff.netlify.app) (See the New Demo Page Including AceEditor)
8+
👉 [Try it now](https://virtual-react-json-diff.netlify.app)
99

10-
A high-performance React component for visually comparing large JSON objects. Built on top of [json-diff-kit](https://www.npmjs.com/package/json-diff-kit), this viewer supports:
11-
12-
- Virtual scrolling for better performance (especially for large diffs)
13-
- Custom theming (Soon new themes will be available)
14-
- Dual Mini Map
15-
- 🔍 Search functionality
16-
- ⚛️ Optimized for React (uses `react-window`)
17-
18-
This component is developed for dealing with thousands of lines of Json Files, and seamlessly compare then render them on UI. Json Compare is a concept that has insufficient FE components available. This component brings solution to the issues of current diff viewers. Virtualized scroll gives a smooth experience while dual minimap and search ability simplifies the process of comparing JSON objects.
10+
A high-performance React component for visually comparing large JSON objects. Built on top of [json-diff-kit](https://www.npmjs.com/package/json-diff-kit), this viewer supports virtual scrolling, search functionality, dual minimap, and customizable theming.
1911

2012
## Features
2113

22-
- **Compare Large JSON Objects** – Handles big files without freezing the UI
2314
- **Virtualized Rendering** – Efficient DOM updates using `react-window`
2415
- **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)
16+
- **Dual Mini Map** – Scrollable minimap for better navigation
17+
- **Line Count Statistics** – Display added, removed, and modified line counts
18+
- **Object Count Statistics** – Count objects when using compare-key method
19+
- **Customizable Styles** – Add your own class names and themes
2720

2821
## Demo
2922

30-
To see how it works, demo available here: https://virtual-react-json-diff.netlify.app
23+
👉 [Try it now](https://virtual-react-json-diff.netlify.app) - Interactive demo with live examples
3124

32-
## 📦 Installation
25+
![Example Screenshot](https://raw.githubusercontent.com/utkuakyuz/virtual-react-json-diff/main/public/image-1.0.15.png)
26+
27+
## Installation
3328

3429
```bash
3530
npm install virtual-react-json-diff
@@ -39,34 +34,9 @@ yarn add virtual-react-json-diff
3934
pnpm add virtual-react-json-diff
4035
```
4136

42-
## Example Screenshot
43-
44-
The theme is fully customizable, all colors can be changed. (And soon new themes will be available)
45-
46-
![ExampleScreenshot](https://raw.githubusercontent.com/utkuakyuz/virtual-react-json-diff/main/public/image-1.0.11.png)
47-
4837
## Usage
4938

50-
Modify DifferOptions and InlineDiffOptions and see the output.
51-
52-
Dual Minimap is defaultly shown, to hide middle minimap, just pass `ShowSingleMinimap` prop to Viewer.
53-
54-
To change Diff methods please see `DifferOptions`. By default `virtual-react-json-diff` uses following configuration.
55-
56-
```
57-
new Differ({
58-
detectCircular: true,
59-
maxDepth: 20,
60-
showModifications: true,
61-
arrayDiffMethod: "lcs",
62-
preserveKeyOrder: "before",
63-
...differOptions,
64-
}),
65-
```
66-
67-
Simply pass your json objects into Viewer Component. It will find differences and show.
68-
69-
```
39+
```jsx
7040
import { VirtualDiffViewer } from "virtual-react-json-diff";
7141

7242
const oldData = { name: "Alice", age: 25 };
@@ -78,77 +48,106 @@ export default function App() {
7848
oldValue={oldData}
7949
newValue={newData}
8050
height={600}
81-
className="my-custom-diff"
51+
showLineCount={true}
52+
showObjectCountStats={false}
8253
/>
8354
);
8455
}
8556
```
8657

87-
---
58+
## Line Count Statistics
8859

89-
If you need to see or make some calculations on difference objects, you can get the diff data using `getDifferData` callback prop
60+
Enable line-level statistics with `showLineCount={true}`:
9061

62+
```jsx
63+
<VirtualDiffViewer
64+
oldValue={oldData}
65+
newValue={newData}
66+
showLineCount={true}
67+
/>;
9168
```
92-
import { type DiffResult, VirtualDiffViewer } from "virtual-react-json-diff";
9369

94-
const [differData, setDifferData] = useState<[DiffResult[], DiffResult[]]>();
70+
Displays: `+5 added lines, -3 removed lines, ~2 modified lines, 10 total line changes`
71+
72+
## Object Count Statistics
9573

96-
<VirtualDiffViewer {...props} getDiffData={diffData => setDifferData(diffData)} />
74+
Enable object-level counting when using compare-key method:
75+
76+
```jsx
77+
<VirtualDiffViewer
78+
oldValue={oldData}
79+
newValue={newData}
80+
showObjectCountStats={true}
81+
differOptions={{
82+
arrayDiffMethod: "compare-key",
83+
compareKey: "id"
84+
}}
85+
/>;
9786
```
9887

99-
Or if you have a custom Differ or a custom viewer, you can import `Differ` class to create diff objects using your own differ. Moreover you can pass that differ to `VirtualizedDiffViewer`.
88+
Displays: `+2 added objects, -1 removed objects, ~3 modified objects, 6 total object changes`
10089

101-
p.s. This is not recommended because you can modify all variables in Differ using `differOptions` prop in Viewer.
90+
**Requirements:** Only works with `arrayDiffMethod: "compare-key"` and requires a valid `compareKey`.
10291

103-
```
104-
import { Differ, VirtualDiffViewer } from "virtual-react-json-diff";
105-
---
106-
const differOptions: DifferOptions = {
107-
showModifications: config.showModifications,
108-
arrayDiffMethod: config.arrayDiffMethod,
109-
};
110-
const differ = new Differ(differOptions);
111-
112-
---
113-
114-
// Pass it into Viewer with 'customDiffer' prop
115-
<VirtualDiffViewer {...props} customDiffer={differ} />
92+
## Props
93+
94+
| Prop | Type | Default | Description |
95+
| ---------------------- | -------------------------------------------------- | ------------------ | ---------------------------------------------------------------------- |
96+
| `oldValue` | `object` || The original JSON object to compare (left side). |
97+
| `newValue` | `object` || The updated JSON object to compare (right side). |
98+
| `height` | `number` || Height of the diff viewer in pixels. |
99+
| `hideSearch` | `boolean` | `false` | Hides the search bar if set to `true`. |
100+
| `searchTerm` | `string` | `""` | Initial search keyword to highlight within the diff. |
101+
| `leftTitle` | `string` || Optional title to display above the left diff panel. |
102+
| `rightTitle` | `string` || Optional title to display above the right diff panel. |
103+
| `onSearchMatch` | `(index: number) => void` || Callback fired when a search match is found. Receives the match index. |
104+
| `differOptions` | `DifferOptions` | `Default config` | Advanced options passed to the diffing engine. |
105+
| `showSingleMinimap` | `boolean` | `false` | If `true`, shows only one minimap instead of two. |
106+
| `className` | `string` || Custom CSS class for styling the viewer container. |
107+
| `miniMapWidth` | `number` | `40` | Width of each minimap in pixels. |
108+
| `inlineDiffOptions` | `InlineDiffOptions` | `{'mode': 'char'}` | Options for fine-tuning inline diff rendering. |
109+
| `showLineCount` | `boolean` | `false` | Display line count statistics (added, removed, modified lines). |
110+
| `showObjectCountStats` | `boolean` | `false` | Display object count statistics when using compare-key method. |
111+
| `getDiffData` | `(diffData: [DiffResult[], DiffResult[]]) => void` | - | Get difference data and make operations |
112+
113+
## Advanced Usage
114+
115+
### Custom Differ Options
116+
117+
```jsx
118+
const differOptions = {
119+
detectCircular: true,
120+
maxDepth: 999,
121+
showModifications: true,
122+
arrayDiffMethod: "compare-key",
123+
compareKey: "userId",
124+
ignoreCase: false,
125+
recursiveEqual: false,
126+
};
127+
128+
<VirtualDiffViewer
129+
oldValue={oldData}
130+
newValue={newData}
131+
differOptions={differOptions}
132+
/>;
116133
```
117134

118-
---
135+
### Utility Functions
119136

120-
The component exposes a root container with the class:
137+
```jsx
138+
import { calculateObjectCountStats } from "virtual-react-json-diff";
121139

140+
const stats = calculateObjectCountStats(oldValue, newValue, "userId");
141+
// Returns: { added: 2, removed: 1, modified: 3, total: 6 }
122142
```
123-
<div class="diff-viewer-container">...</div>
124-
```
125-
126-
You can pass your own class name via the className prop to apply custom themes.
127143

128-
## Props
144+
## Styling
129145

130-
| Prop | Type | Default | Description |
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 |
146+
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.
148147

149148
## 🙌 Acknowledgements
150149

151-
Built on top of the awesome json-diff-kit.
150+
Built on top of the awesome [json-diff-kit](https://www.npmjs.com/package/json-diff-kit).
152151

153152
## 📄 License
154153

@@ -157,7 +156,6 @@ MIT © Utku Akyüz
157156
## 🛠️ Contributing
158157

159158
Pull requests, suggestions, and issues are welcome!
160-
Check out the issues or open a PR.
161159

162160
[npm-url]: https://npmjs.org/package/virtual-react-json-diff
163161
[npm-image]: https://img.shields.io/npm/v/virtual-react-json-diff.svg

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "virtual-react-json-diff",
33
"type": "module",
4-
"version": "1.0.14",
4+
"version": "1.0.15",
55
"description": "Fast, virtualized React component for visually comparing large JSON objects. Includes search, theming, and minimap.",
66
"author": {
77
"name": "Utku Akyüz"
@@ -85,6 +85,7 @@
8585
"pre-commit": "pnpm lint-staged"
8686
},
8787
"lint-staged": {
88-
"*.{js,jsx,ts,tsx,vue,html,md,json,yaml,css,scss}": "eslint --fix"
88+
"*.{js,jsx,ts,tsx,vue,html,json,yaml,css,scss}": "eslint --fix",
89+
"*.md": "echo 'Skipping markdown files in lint-staged'"
8990
}
9091
}

public/image-1.0.15.png

57.4 KB
Loading

0 commit comments

Comments
 (0)