react-diff-viewer-continued 3.2.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/.eslintrc +13 -0
- package/.github/FUNDING.yml +0 -0
- package/.github/workflows/release.yml +30 -0
- package/.idea/modules.xml +8 -0
- package/.idea/react-diff-viewer-continued.iml +8 -0
- package/.prettierrc +4 -0
- package/.travis.yml +13 -0
- package/CHANGELOG.md +6 -0
- package/LICENSE +21 -0
- package/README.md +365 -0
- package/babel.config.js +7 -0
- package/jest.config.js +5 -0
- package/lib/compute-lines.d.ts +52 -0
- package/lib/compute-lines.js +178 -0
- package/lib/index.d.ts +148 -0
- package/lib/index.js +331 -0
- package/lib/styles.d.ts +77 -0
- package/lib/styles.js +276 -0
- package/logo-standalone.png +0 -0
- package/logo.png +0 -0
- package/logo.png~ +0 -0
- package/logo_dark.png +0 -0
- package/package.json +100 -0
- package/publish-examples.sh +10 -0
- package/release.config.js +18 -0
- package/tsconfig.examples.json +14 -0
- package/tsconfig.json +16 -0
- package/webpack.config.js +60 -0
package/.eslintrc
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": ["airbnb-base", "plugin:@typescript-eslint/recommended"],
|
|
3
|
+
"rules": {
|
|
4
|
+
"@typescript-eslint/indent": ["error", 2],
|
|
5
|
+
"arrow-body-style": "off",
|
|
6
|
+
"import/extensions": "off"
|
|
7
|
+
},
|
|
8
|
+
"env": {
|
|
9
|
+
"mocha": true,
|
|
10
|
+
"node": true,
|
|
11
|
+
"browser": true
|
|
12
|
+
}
|
|
13
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
branches:
|
|
5
|
+
- master
|
|
6
|
+
jobs:
|
|
7
|
+
release:
|
|
8
|
+
name: Release
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
steps:
|
|
11
|
+
- name: Checkout
|
|
12
|
+
uses: actions/checkout@v2
|
|
13
|
+
with:
|
|
14
|
+
fetch-depth: 0
|
|
15
|
+
- name: Setup Node.js
|
|
16
|
+
uses: actions/setup-node@v2
|
|
17
|
+
with:
|
|
18
|
+
node-version: "lts/*"
|
|
19
|
+
- uses: pnpm/action-setup@v2.2.2
|
|
20
|
+
with:
|
|
21
|
+
version: latest
|
|
22
|
+
- name: Install dependencies
|
|
23
|
+
run: pnpm i
|
|
24
|
+
- name: Build application
|
|
25
|
+
run: pnpm run build
|
|
26
|
+
- name: Release
|
|
27
|
+
env:
|
|
28
|
+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
|
|
29
|
+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
30
|
+
run: pnpm dlx semantic-release
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="ProjectModuleManager">
|
|
4
|
+
<modules>
|
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/react-diff-viewer-continued.iml" filepath="$PROJECT_DIR$/.idea/react-diff-viewer-continued.iml" />
|
|
6
|
+
</modules>
|
|
7
|
+
</component>
|
|
8
|
+
</project>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<module type="WEB_MODULE" version="4">
|
|
3
|
+
<component name="NewModuleRootManager">
|
|
4
|
+
<content url="file://$MODULE_DIR$" />
|
|
5
|
+
<orderEntry type="inheritedJdk" />
|
|
6
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
|
7
|
+
</component>
|
|
8
|
+
</module>
|
package/.prettierrc
ADDED
package/.travis.yml
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
language: node_js
|
|
2
|
+
node_js: 12
|
|
3
|
+
before_script: yarn build
|
|
4
|
+
after_success: './publish-examples.sh'
|
|
5
|
+
deploy:
|
|
6
|
+
skip_cleanup: true
|
|
7
|
+
provider: npm
|
|
8
|
+
email: praneshpranesh@gmail.com
|
|
9
|
+
api_key:
|
|
10
|
+
secure: ytHogDV6wWZKY3eCgdJ5TFCz57llxTe6W1EuLBbg3TvHfpAmcL5XzT77T0lNTYY95XmABwGpf4qvqui1fXVoFqqSXVPSVt9I1aQ4gxBzxPKHGPV++wwgVOBfZErIlYPW4kcYJQvfemBDBfAMQS2u/0si5mZbeyVkvlnhHLnylsc1sJUGGnq9PJxwCagBd/DAhYYCU5d4a9psOwo6GnAwzs37rgVIb5oNhbtex0r1u5D4irweVz4V1TkwhMczw3v8t0d+I2REqjGkqLdKJOt9Q/Uqc7v34wIAy4Xng8zla7PKlzVNDlsA19en4DezJ/YRU3o6JxsMICRDyIRcwaebX2S7S35cif2gJRSF+LRCq2XdHvDAXPt6trQoeo9mSdq6+dL4/uYbhliUOyhzw84CRdY3+VrST1h7h8LAGODQzYJbQs20PkVL2527Bk+eS+tNCNpr/jSWG/iDO477j9jTGNVloF2IRHikbnZDFcF4ZrKE5RHEWSbQzyHkOOTgo5k+p6Doyv4jSgdLlnck2+f5n4Ocs/xh1c0UAphdW/mw/8lAv0+gpoL8f3rfN4AD5LYjjQ7xK5yO6RfIzsmAOqs7WCyY0ewXaPaP6Nz+Ne5Q2CKwVZiqj3qvd4o3aJodnquJ1iKzxbNHd/LFScEQxYSslyRluHrM+7DASPfccA7ePnE=
|
|
11
|
+
on:
|
|
12
|
+
tags: true
|
|
13
|
+
repo: praneshr/react-diff-viewer
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# [3.2.0](https://github.com/aeolun/react-diff-viewer-continued/compare/v3.1.1...v3.2.0) (2022-07-07)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* update library for react 17, and add custom gutters ([7193350](https://github.com/aeolun/react-diff-viewer-continued/commit/7193350187ed5b13989e6d5e5ade40f3a45c943b))
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 Pranesh Ravi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
<img src='https://github.com/Aeolun/react-diff-viewer-continued/raw/master/logo_dark.png' width="100%" alt='React Diff Viewer' />
|
|
2
|
+
<br/>
|
|
3
|
+
|
|
4
|
+
[](https://badge.fury.io/js/react-diff-viewer-continued)
|
|
5
|
+
[](https://github.com/aeolun/react-diff-viewer-continued/blob/master/LICENSE)
|
|
6
|
+
|
|
7
|
+
A simple and beautiful text diff viewer component made with [Diff](https://github.com/kpdecker/jsdiff) and [React](https://reactjs.org).
|
|
8
|
+
|
|
9
|
+
Inspired from Github diff viewer, it includes features like split view, inline view, word diff, line highlight and more. It is highly customizable and it supports almost all languages.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
yarn add react-diff-viewer-continued
|
|
15
|
+
|
|
16
|
+
# or
|
|
17
|
+
|
|
18
|
+
npm i react-diff-viewer-continued
|
|
19
|
+
|
|
20
|
+
# or
|
|
21
|
+
|
|
22
|
+
pnpm add react-diff-viewer-continued
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
```javascript
|
|
28
|
+
import React, { PureComponent } from 'react';
|
|
29
|
+
import ReactDiffViewer from 'react-diff-viewer-continued';
|
|
30
|
+
|
|
31
|
+
const oldCode = `
|
|
32
|
+
const a = 10
|
|
33
|
+
const b = 10
|
|
34
|
+
const c = () => console.log('foo')
|
|
35
|
+
|
|
36
|
+
if(a > 10) {
|
|
37
|
+
console.log('bar')
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
console.log('done')
|
|
41
|
+
`;
|
|
42
|
+
const newCode = `
|
|
43
|
+
const a = 10
|
|
44
|
+
const boo = 10
|
|
45
|
+
|
|
46
|
+
if(a === 10) {
|
|
47
|
+
console.log('bar')
|
|
48
|
+
}
|
|
49
|
+
`;
|
|
50
|
+
|
|
51
|
+
class Diff extends PureComponent {
|
|
52
|
+
render = () => {
|
|
53
|
+
return (
|
|
54
|
+
<ReactDiffViewer oldValue={oldCode} newValue={newCode} splitView={true} />
|
|
55
|
+
);
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Props
|
|
61
|
+
|
|
62
|
+
| Prop | Type | Default | Description |
|
|
63
|
+
|---------------------------|---------------------------|--------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
64
|
+
| oldValue | `string` | `''` | Old value as string. |
|
|
65
|
+
| newValue | `string` | `''` | New value as string. |
|
|
66
|
+
| splitView | `boolean` | `true` | Switch between `unified` and `split` view. |
|
|
67
|
+
| disableWordDiff | `boolean` | `false` | Show and hide word diff in a diff line. |
|
|
68
|
+
| compareMethod | `DiffMethod` | `DiffMethod.CHARS` | JsDiff text diff method used for diffing strings. Check out the [guide](https://github.com/praneshr/react-diff-viewer/tree/v3.0.0#text-block-diff-comparison) to use different methods. |
|
|
69
|
+
| renderGutter | `(diffData) => ReactNode` | `undefined` | Function that can be used to render an extra gutter with various information next to the line number. |
|
|
70
|
+
| hideLineNumbers | `boolean` | `false` | Show and hide line numbers. |
|
|
71
|
+
| renderContent | `function` | `undefined` | Render Prop API to render code in the diff viewer. Helpful for [syntax highlighting](#syntax-highlighting) |
|
|
72
|
+
| onLineNumberClick | `function` | `undefined` | Event handler for line number click. `(lineId: string) => void` |
|
|
73
|
+
| highlightLines | `array[string]` | `[]` | List of lines to be highlighted. Works together with `onLineNumberClick`. Line number are prefixed with `L` and `R` for the left and right section of the diff viewer, respectively. For example, `L-20` means 20th line in the left pane. To highlight a range of line numbers, pass the prefixed line number as an array. For example, `[L-2, L-3, L-4, L-5]` will highlight the lines `2-5` in the left pane. |
|
|
74
|
+
| showDiffOnly | `boolean` | `true` | Shows only the diffed lines and folds the unchanged lines |
|
|
75
|
+
| extraLinesSurroundingDiff | `number` | `3` | Number of extra unchanged lines surrounding the diff. Works along with `showDiffOnly`. |
|
|
76
|
+
| codeFoldMessageRenderer | `function` | `Expand {number} of lines ...` | Render Prop API to render code fold message. |
|
|
77
|
+
| styles | `object` | `{}` | To override style variables and styles. Learn more about [overriding styles](#overriding-styles) |
|
|
78
|
+
| useDarkTheme | `boolean` | `true` | To enable/disable dark theme. |
|
|
79
|
+
| leftTitle | `string` | `undefined` | Column title for left section of the diff in split view. This will be used as the only title in inline view. |
|
|
80
|
+
| rightTitle | `string` | `undefined` | Column title for right section of the diff in split view. This will be ignored in inline view. |
|
|
81
|
+
| linesOffset | `number` | `0` | Number to start count code lines from. |
|
|
82
|
+
|
|
83
|
+
## Instance Methods
|
|
84
|
+
|
|
85
|
+
`resetCodeBlocks()` - Resets the expanded code blocks to it's initial state. Return `true` on successful reset and `false` during unsuccessful reset.
|
|
86
|
+
|
|
87
|
+
## Syntax Highlighting
|
|
88
|
+
|
|
89
|
+
Syntax highlighting is a bit tricky when combined with diff. Here, React Diff Viewer provides a simple render prop API to handle syntax highlighting. Use `renderContent(content: string) => JSX.Element` and your favorite syntax highlighting library to achieve this.
|
|
90
|
+
|
|
91
|
+
An example using [Prism JS](https://prismjs.com)
|
|
92
|
+
|
|
93
|
+
```html
|
|
94
|
+
// Load Prism CSS
|
|
95
|
+
<link
|
|
96
|
+
href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.15.0/prism.min.css"
|
|
97
|
+
/>
|
|
98
|
+
|
|
99
|
+
// Load Prism JS
|
|
100
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.15.0/prism.min.js"></script>
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
```javascript
|
|
104
|
+
import React, { PureComponent } from 'react';
|
|
105
|
+
import ReactDiffViewer from 'react-diff-viewer';
|
|
106
|
+
|
|
107
|
+
const oldCode = `
|
|
108
|
+
const a = 10
|
|
109
|
+
const b = 10
|
|
110
|
+
const c = () => console.log('foo')
|
|
111
|
+
|
|
112
|
+
if(a > 10) {
|
|
113
|
+
console.log('bar')
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
console.log('done')
|
|
117
|
+
`;
|
|
118
|
+
const newCode = `
|
|
119
|
+
const a = 10
|
|
120
|
+
const boo = 10
|
|
121
|
+
|
|
122
|
+
if(a === 10) {
|
|
123
|
+
console.log('bar')
|
|
124
|
+
}
|
|
125
|
+
`;
|
|
126
|
+
|
|
127
|
+
class Diff extends PureComponent {
|
|
128
|
+
highlightSyntax = (str) => (
|
|
129
|
+
<pre
|
|
130
|
+
style={{ display: 'inline' }}
|
|
131
|
+
dangerouslySetInnerHTML={{
|
|
132
|
+
__html: Prism.highlight(str, Prism.languages.javascript),
|
|
133
|
+
}}
|
|
134
|
+
/>
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
render = () => {
|
|
138
|
+
return (
|
|
139
|
+
<ReactDiffViewer
|
|
140
|
+
oldValue={oldCode}
|
|
141
|
+
newValue={newCode}
|
|
142
|
+
splitView={true}
|
|
143
|
+
renderContent={this.highlightSyntax}
|
|
144
|
+
/>
|
|
145
|
+
);
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## Text block diff comparison
|
|
151
|
+
|
|
152
|
+
Different styles of text block diffing are possible by using the enums corresponding to variou JsDiff methods ([learn more](https://github.com/kpdecker/jsdiff/tree/v4.0.1#api)). The supported methods are as follows.
|
|
153
|
+
|
|
154
|
+
```javascript
|
|
155
|
+
enum DiffMethod {
|
|
156
|
+
CHARS = 'diffChars',
|
|
157
|
+
WORDS = 'diffWords',
|
|
158
|
+
WORDS_WITH_SPACE = 'diffWordsWithSpace',
|
|
159
|
+
LINES = 'diffLines',
|
|
160
|
+
TRIMMED_LINES = 'diffTrimmedLines',
|
|
161
|
+
SENTENCES = 'diffSentences',
|
|
162
|
+
CSS = 'diffCss',
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
```javascript
|
|
167
|
+
import React, { PureComponent } from 'react';
|
|
168
|
+
import ReactDiffViewer, { DiffMethod } from 'react-diff-viewer';
|
|
169
|
+
|
|
170
|
+
const oldCode = `
|
|
171
|
+
{
|
|
172
|
+
"name": "Original name",
|
|
173
|
+
"description": null
|
|
174
|
+
}
|
|
175
|
+
`;
|
|
176
|
+
const newCode = `
|
|
177
|
+
{
|
|
178
|
+
"name": "My updated name",
|
|
179
|
+
"description": "Brand new description",
|
|
180
|
+
"status": "running"
|
|
181
|
+
}
|
|
182
|
+
`;
|
|
183
|
+
|
|
184
|
+
class Diff extends PureComponent {
|
|
185
|
+
render = () => {
|
|
186
|
+
return (
|
|
187
|
+
<ReactDiffViewer
|
|
188
|
+
oldValue={oldCode}
|
|
189
|
+
newValue={newCode}
|
|
190
|
+
compareMethod={DiffMethod.WORDS}
|
|
191
|
+
splitView={true}
|
|
192
|
+
/>
|
|
193
|
+
);
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
## Overriding Styles
|
|
199
|
+
|
|
200
|
+
React Diff Viewer uses [emotion](https://emotion.sh/) for styling. It also offers a simple way to override styles and style variables. You can supply different variables for both light and dark themes. Styles will be common for both themes.
|
|
201
|
+
|
|
202
|
+
Below are the default style variables and style object keys.
|
|
203
|
+
|
|
204
|
+
```javascript
|
|
205
|
+
|
|
206
|
+
// Default variables and style keys
|
|
207
|
+
|
|
208
|
+
const defaultStyles = {
|
|
209
|
+
variables: {
|
|
210
|
+
light: {
|
|
211
|
+
diffViewerBackground: '#fff',
|
|
212
|
+
diffViewerColor: '#212529',
|
|
213
|
+
addedBackground: '#e6ffed',
|
|
214
|
+
addedColor: '#24292e',
|
|
215
|
+
removedBackground: '#ffeef0',
|
|
216
|
+
removedColor: '#24292e',
|
|
217
|
+
wordAddedBackground: '#acf2bd',
|
|
218
|
+
wordRemovedBackground: '#fdb8c0',
|
|
219
|
+
addedGutterBackground: '#cdffd8',
|
|
220
|
+
removedGutterBackground: '#ffdce0',
|
|
221
|
+
gutterBackground: '#f7f7f7',
|
|
222
|
+
gutterBackgroundDark: '#f3f1f1',
|
|
223
|
+
highlightBackground: '#fffbdd',
|
|
224
|
+
highlightGutterBackground: '#fff5b1',
|
|
225
|
+
codeFoldGutterBackground: '#dbedff',
|
|
226
|
+
codeFoldBackground: '#f1f8ff',
|
|
227
|
+
emptyLineBackground: '#fafbfc',
|
|
228
|
+
gutterColor: '#212529',
|
|
229
|
+
addedGutterColor: '#212529',
|
|
230
|
+
removedGutterColor: '#212529',
|
|
231
|
+
codeFoldContentColor: '#212529',
|
|
232
|
+
diffViewerTitleBackground: '#fafbfc',
|
|
233
|
+
diffViewerTitleColor: '#212529',
|
|
234
|
+
diffViewerTitleBorderColor: '#eee',
|
|
235
|
+
},
|
|
236
|
+
dark: {
|
|
237
|
+
diffViewerBackground: '#2e303c',
|
|
238
|
+
diffViewerColor: '#FFF',
|
|
239
|
+
addedBackground: '#044B53',
|
|
240
|
+
addedColor: 'white',
|
|
241
|
+
removedBackground: '#632F34',
|
|
242
|
+
removedColor: 'white',
|
|
243
|
+
wordAddedBackground: '#055d67',
|
|
244
|
+
wordRemovedBackground: '#7d383f',
|
|
245
|
+
addedGutterBackground: '#034148',
|
|
246
|
+
removedGutterBackground: '#632b30',
|
|
247
|
+
gutterBackground: '#2c2f3a',
|
|
248
|
+
gutterBackgroundDark: '#262933',
|
|
249
|
+
highlightBackground: '#2a3967',
|
|
250
|
+
highlightGutterBackground: '#2d4077',
|
|
251
|
+
codeFoldGutterBackground: '#21232b',
|
|
252
|
+
codeFoldBackground: '#262831',
|
|
253
|
+
emptyLineBackground: '#363946',
|
|
254
|
+
gutterColor: '#464c67',
|
|
255
|
+
addedGutterColor: '#8c8c8c',
|
|
256
|
+
removedGutterColor: '#8c8c8c',
|
|
257
|
+
codeFoldContentColor: '#555a7b',
|
|
258
|
+
diffViewerTitleBackground: '#2f323e',
|
|
259
|
+
diffViewerTitleColor: '#555a7b',
|
|
260
|
+
diffViewerTitleBorderColor: '#353846',
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
diffContainer?: {}, // style object
|
|
264
|
+
diffRemoved?: {}, // style object
|
|
265
|
+
diffAdded?: {}, // style object
|
|
266
|
+
marker?: {}, // style object
|
|
267
|
+
emptyGutter?: {}, // style object
|
|
268
|
+
highlightedLine?: {}, // style object
|
|
269
|
+
lineNumber?: {}, // style object
|
|
270
|
+
highlightedGutter?: {}, // style object
|
|
271
|
+
contentText?: {}, // style object
|
|
272
|
+
gutter?: {}, // style object
|
|
273
|
+
line?: {}, // style object
|
|
274
|
+
wordDiff?: {}, // style object
|
|
275
|
+
wordAdded?: {}, // style object
|
|
276
|
+
wordRemoved?: {}, // style object
|
|
277
|
+
codeFoldGutter?: {}, // style object
|
|
278
|
+
codeFold?: {}, // style object
|
|
279
|
+
emptyLine?: {}, // style object
|
|
280
|
+
content?: {}, // style object
|
|
281
|
+
titleBlock?: {}, // style object
|
|
282
|
+
splitView?: {}, // style object
|
|
283
|
+
}
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
To override any style, just pass the new style object to the `styles` prop. New style will be computed using `Object.assign(default, override)`.
|
|
287
|
+
|
|
288
|
+
For keys other than `variables`, the value can either be an object or string interpolation.
|
|
289
|
+
|
|
290
|
+
```javascript
|
|
291
|
+
import React, { PureComponent } from 'react';
|
|
292
|
+
import ReactDiffViewer from 'react-diff-viewer';
|
|
293
|
+
|
|
294
|
+
const oldCode = `
|
|
295
|
+
const a = 10
|
|
296
|
+
const b = 10
|
|
297
|
+
const c = () => console.log('foo')
|
|
298
|
+
|
|
299
|
+
if(a > 10) {
|
|
300
|
+
console.log('bar')
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
console.log('done')
|
|
304
|
+
`;
|
|
305
|
+
const newCode = `
|
|
306
|
+
const a = 10
|
|
307
|
+
const boo = 10
|
|
308
|
+
|
|
309
|
+
if(a === 10) {
|
|
310
|
+
console.log('bar')
|
|
311
|
+
}
|
|
312
|
+
`;
|
|
313
|
+
|
|
314
|
+
class Diff extends PureComponent {
|
|
315
|
+
highlightSyntax = (str) => (
|
|
316
|
+
<span
|
|
317
|
+
style={{ display: 'inline' }}
|
|
318
|
+
dangerouslySetInnerHTML={{
|
|
319
|
+
__html: Prism.highlight(str, Prism.languages.javascript),
|
|
320
|
+
}}
|
|
321
|
+
/>
|
|
322
|
+
);
|
|
323
|
+
|
|
324
|
+
render = () => {
|
|
325
|
+
const newStyles = {
|
|
326
|
+
variables: {
|
|
327
|
+
dark: {
|
|
328
|
+
highlightBackground: '#fefed5',
|
|
329
|
+
highlightGutterBackground: '#ffcd3c',
|
|
330
|
+
},
|
|
331
|
+
},
|
|
332
|
+
line: {
|
|
333
|
+
padding: '10px 2px',
|
|
334
|
+
'&:hover': {
|
|
335
|
+
background: '#a26ea1',
|
|
336
|
+
},
|
|
337
|
+
},
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
return (
|
|
341
|
+
<ReactDiffViewer
|
|
342
|
+
styles={newStyles}
|
|
343
|
+
oldValue={oldCode}
|
|
344
|
+
newValue={newCode}
|
|
345
|
+
splitView={true}
|
|
346
|
+
renderContent={this.highlightSyntax}
|
|
347
|
+
/>
|
|
348
|
+
);
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
## Local Development
|
|
354
|
+
|
|
355
|
+
```bash
|
|
356
|
+
pnpm install
|
|
357
|
+
pnpm build # or use yarn build:watch
|
|
358
|
+
pnpm start:examples
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
Check package.json for more build scripts.
|
|
362
|
+
|
|
363
|
+
## License
|
|
364
|
+
|
|
365
|
+
MIT
|
package/babel.config.js
ADDED
package/jest.config.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export declare enum DiffType {
|
|
2
|
+
DEFAULT = 0,
|
|
3
|
+
ADDED = 1,
|
|
4
|
+
REMOVED = 2
|
|
5
|
+
}
|
|
6
|
+
export declare enum DiffMethod {
|
|
7
|
+
CHARS = "diffChars",
|
|
8
|
+
WORDS = "diffWords",
|
|
9
|
+
WORDS_WITH_SPACE = "diffWordsWithSpace",
|
|
10
|
+
LINES = "diffLines",
|
|
11
|
+
TRIMMED_LINES = "diffTrimmedLines",
|
|
12
|
+
SENTENCES = "diffSentences",
|
|
13
|
+
CSS = "diffCss"
|
|
14
|
+
}
|
|
15
|
+
export interface DiffInformation {
|
|
16
|
+
value?: string | DiffInformation[];
|
|
17
|
+
lineNumber?: number;
|
|
18
|
+
type?: DiffType;
|
|
19
|
+
}
|
|
20
|
+
export interface LineInformation {
|
|
21
|
+
left?: DiffInformation;
|
|
22
|
+
right?: DiffInformation;
|
|
23
|
+
}
|
|
24
|
+
export interface ComputedLineInformation {
|
|
25
|
+
lineInformation: LineInformation[];
|
|
26
|
+
diffLines: number[];
|
|
27
|
+
}
|
|
28
|
+
export interface ComputedDiffInformation {
|
|
29
|
+
left?: DiffInformation[];
|
|
30
|
+
right?: DiffInformation[];
|
|
31
|
+
}
|
|
32
|
+
export interface JsDiffChangeObject {
|
|
33
|
+
added?: boolean;
|
|
34
|
+
removed?: boolean;
|
|
35
|
+
value?: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* [TODO]: Think about moving common left and right value assignment to a
|
|
39
|
+
* common place. Better readability?
|
|
40
|
+
*
|
|
41
|
+
* Computes line wise information based in the js diff information passed. Each
|
|
42
|
+
* line contains information about left and right section. Left side denotes
|
|
43
|
+
* deletion and right side denotes addition.
|
|
44
|
+
*
|
|
45
|
+
* @param oldString Old string to compare.
|
|
46
|
+
* @param newString New string to compare with old string.
|
|
47
|
+
* @param disableWordDiff Flag to enable/disable word diff.
|
|
48
|
+
* @param compareMethod JsDiff text diff method from https://github.com/kpdecker/jsdiff/tree/v4.0.1#api
|
|
49
|
+
* @param linesOffset line number to start counting from
|
|
50
|
+
*/
|
|
51
|
+
declare const computeLineInformation: (oldString: string, newString: string, disableWordDiff?: boolean, compareMethod?: string, linesOffset?: number) => ComputedLineInformation;
|
|
52
|
+
export { computeLineInformation };
|