virtual-react-json-diff 1.0.14 β†’ 1.0.15

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
@@ -5,31 +5,26 @@
5
5
  ![bundle size](https://badgen.net/bundlephobia/minzip/virtual-react-json-diff)
6
6
  [![BuyMeACoffee](https://raw.githubusercontent.com/pachadotdev/buymeacoffee-badges/main/bmc-yellow.svg)](https://www.buymeacoffee.com/utkuakyuz)
7
7
 
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)
9
9
 
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.
19
11
 
20
12
  ## Features
21
13
 
22
- - **Compare Large JSON Objects** – Handles big files without freezing the UI
23
14
  - **Virtualized Rendering** – Efficient DOM updates using `react-window`
24
15
  - **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
27
20
 
28
21
  ## Demo
29
22
 
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
31
24
 
32
- ## πŸ“¦ Installation
25
+ ![Example Screenshot](https://raw.githubusercontent.com/utkuakyuz/virtual-react-json-diff/main/public/image-1.0.15.png)
26
+
27
+ ## Installation
33
28
 
34
29
  ```bash
35
30
  npm install virtual-react-json-diff
@@ -39,34 +34,9 @@ yarn add virtual-react-json-diff
39
34
  pnpm add virtual-react-json-diff
40
35
  ```
41
36
 
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
-
48
37
  ## Usage
49
38
 
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
70
40
  import { VirtualDiffViewer } from "virtual-react-json-diff";
71
41
 
72
42
  const oldData = { name: "Alice", age: 25 };
@@ -78,77 +48,106 @@ export default function App() {
78
48
  oldValue={oldData}
79
49
  newValue={newData}
80
50
  height={600}
81
- className="my-custom-diff"
51
+ showLineCount={true}
52
+ showObjectCountStats={false}
82
53
  />
83
54
  );
84
55
  }
85
56
  ```
86
57
 
87
- ---
58
+ ## Line Count Statistics
88
59
 
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}`:
90
61
 
62
+ ```jsx
63
+ <VirtualDiffViewer
64
+ oldValue={oldData}
65
+ newValue={newData}
66
+ showLineCount={true}
67
+ />;
91
68
  ```
92
- import { type DiffResult, VirtualDiffViewer } from "virtual-react-json-diff";
93
69
 
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
95
73
 
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
+ />;
97
86
  ```
98
87
 
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`
100
89
 
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`.
102
91
 
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
+ />;
116
133
  ```
117
134
 
118
- ---
135
+ ### Utility Functions
119
136
 
120
- The component exposes a root container with the class:
137
+ ```jsx
138
+ import { calculateObjectCountStats } from "virtual-react-json-diff";
121
139
 
140
+ const stats = calculateObjectCountStats(oldValue, newValue, "userId");
141
+ // Returns: { added: 2, removed: 1, modified: 3, total: 6 }
122
142
  ```
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.
127
143
 
128
- ## Props
144
+ ## Styling
129
145
 
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.
148
147
 
149
148
  ## πŸ™Œ Acknowledgements
150
149
 
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).
152
151
 
153
152
  ## πŸ“„ License
154
153
 
@@ -157,7 +156,6 @@ MIT Β© Utku AkyΓΌz
157
156
  ## πŸ› οΈ Contributing
158
157
 
159
158
  Pull requests, suggestions, and issues are welcome!
160
- Check out the issues or open a PR.
161
159
 
162
160
  [npm-url]: https://npmjs.org/package/virtual-react-json-diff
163
161
  [npm-image]: https://img.shields.io/npm/v/virtual-react-json-diff.svg