react-diff-viewer-continued 4.0.0 → 4.0.2

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.
@@ -1,12 +1,31 @@
1
- name: Release
1
+ name: Test & Release
2
2
  on:
3
3
  push:
4
- branches:
5
- - master
6
- - next
4
+
7
5
  jobs:
6
+ test:
7
+ name: Unit tests
8
+ runs-on: ubuntu-latest
9
+ steps:
10
+ - name: Checkout
11
+ uses: actions/checkout@v3
12
+ with:
13
+ fetch-depth: 0
14
+ - name: Setup Node.js
15
+ uses: actions/setup-node@v3
16
+ with:
17
+ node-version: 'lts/*'
18
+ - uses: pnpm/action-setup@v2.2.4
19
+ with:
20
+ version: latest
21
+ - name: Install dependencies
22
+ run: pnpm i
23
+ - name: Run unit tests
24
+ run: pnpm run test
8
25
  release:
9
26
  name: Release
27
+ needs: test
28
+ if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/next'
10
29
  runs-on: ubuntu-latest
11
30
  steps:
12
31
  - name: Checkout
@@ -5,4 +5,7 @@
5
5
  <orderEntry type="inheritedJdk" />
6
6
  <orderEntry type="sourceFolder" forTests="false" />
7
7
  </component>
8
+ <component name="SonarLintModuleSettings">
9
+ <option name="uniqueId" value="5762f64b-7b0e-41a1-a2ec-f15fa70aa6a1" />
10
+ </component>
8
11
  </module>
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## [4.0.2](https://github.com/aeolun/react-diff-viewer-continued/compare/v4.0.1...v4.0.2) (2024-02-14)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * revert back to table based layout, add example image (fixes [#35](https://github.com/aeolun/react-diff-viewer-continued/issues/35), [#15](https://github.com/aeolun/react-diff-viewer-continued/issues/15), [#21](https://github.com/aeolun/react-diff-viewer-continued/issues/21)) ([a1571ab](https://github.com/aeolun/react-diff-viewer-continued/commit/a1571ab9940c8b917c2e845f537780e4b45efb01))
7
+
8
+ ## [4.0.1](https://github.com/aeolun/react-diff-viewer-continued/compare/v4.0.0...v4.0.1) (2023-11-01)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * publish files on 4.x ([650c249](https://github.com/aeolun/react-diff-viewer-continued/commit/650c249c5bf1d8b27d780b65555df5ae0f5d9e2b))
14
+
1
15
  # [4.0.0](https://github.com/aeolun/react-diff-viewer-continued/compare/v3.3.0...v4.0.0) (2023-10-19)
2
16
 
3
17
 
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2018 Pranesh Ravi
3
+ Copyright (c) 2023 Bart Riepe
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -12,6 +12,8 @@
12
12
 
13
13
  A simple and beautiful text diff viewer component made with [Diff](https://github.com/kpdecker/jsdiff) and [React](https://reactjs.org).
14
14
 
15
+ ![example image](./example.jpg)
16
+
15
17
  Inspired by the 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.
16
18
 
17
19
  Most credit goes to [Pranesh Ravi](https://praneshravi.in) who created the [original diff viewer](https://github.com/praneshr/react-diff-viewer). I've just made a few modifications and updated the dependencies so they work with modern stacks.
package/example.jpg ADDED
Binary file
@@ -0,0 +1,13 @@
1
+ import { LineInformation } from "./compute-lines";
2
+ export interface Block {
3
+ index: number;
4
+ startLine: number;
5
+ endLine: number;
6
+ lines: number;
7
+ }
8
+ interface HiddenBlocks {
9
+ lineBlocks: Record<number, number>;
10
+ blocks: Block[];
11
+ }
12
+ export declare function computeHiddenBlocks(lineInformation: LineInformation[], diffLines: number[], extraLines: number): HiddenBlocks;
13
+ export {};
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.computeHiddenBlocks = void 0;
4
+ function computeHiddenBlocks(lineInformation, diffLines, extraLines) {
5
+ let newBlockIndex = 0;
6
+ let currentBlock;
7
+ let lineBlocks = {};
8
+ let blocks = [];
9
+ lineInformation.forEach((line, lineIndex) => {
10
+ const isDiffLine = diffLines.some(diffLine => diffLine >= lineIndex - extraLines && diffLine <= lineIndex + extraLines);
11
+ if (!isDiffLine && currentBlock == undefined) {
12
+ // block begins
13
+ currentBlock = {
14
+ index: newBlockIndex,
15
+ startLine: lineIndex,
16
+ endLine: lineIndex,
17
+ lines: 1
18
+ };
19
+ blocks.push(currentBlock);
20
+ lineBlocks[lineIndex] = currentBlock.index;
21
+ newBlockIndex++;
22
+ }
23
+ else if (!isDiffLine) {
24
+ // block continues
25
+ currentBlock.endLine = lineIndex;
26
+ currentBlock.lines++;
27
+ lineBlocks[lineIndex] = currentBlock.index;
28
+ }
29
+ else {
30
+ // not a block anymore
31
+ currentBlock = undefined;
32
+ }
33
+ });
34
+ return {
35
+ lineBlocks,
36
+ blocks: blocks
37
+ };
38
+ }
39
+ exports.computeHiddenBlocks = computeHiddenBlocks;
@@ -0,0 +1,55 @@
1
+ export declare enum DiffType {
2
+ DEFAULT = 0,
3
+ ADDED = 1,
4
+ REMOVED = 2,
5
+ CHANGED = 3
6
+ }
7
+ export declare enum DiffMethod {
8
+ CHARS = "diffChars",
9
+ WORDS = "diffWords",
10
+ WORDS_WITH_SPACE = "diffWordsWithSpace",
11
+ LINES = "diffLines",
12
+ TRIMMED_LINES = "diffTrimmedLines",
13
+ SENTENCES = "diffSentences",
14
+ CSS = "diffCss",
15
+ JSON = "diffJson"
16
+ }
17
+ export interface DiffInformation {
18
+ value?: string | DiffInformation[];
19
+ lineNumber?: number;
20
+ type?: DiffType;
21
+ }
22
+ export interface LineInformation {
23
+ left?: DiffInformation;
24
+ right?: DiffInformation;
25
+ }
26
+ export interface ComputedLineInformation {
27
+ lineInformation: LineInformation[];
28
+ diffLines: number[];
29
+ }
30
+ export interface ComputedDiffInformation {
31
+ left?: DiffInformation[];
32
+ right?: DiffInformation[];
33
+ }
34
+ export interface JsDiffChangeObject {
35
+ added?: boolean;
36
+ removed?: boolean;
37
+ value?: string;
38
+ }
39
+ /**
40
+ * [TODO]: Think about moving common left and right value assignment to a
41
+ * common place. Better readability?
42
+ *
43
+ * Computes line wise information based in the js diff information passed. Each
44
+ * line contains information about left and right section. Left side denotes
45
+ * deletion and right side denotes addition.
46
+ *
47
+ * @param oldString Old string to compare.
48
+ * @param newString New string to compare with old string.
49
+ * @param disableWordDiff Flag to enable/disable word diff.
50
+ * @param lineCompareMethod JsDiff text diff method from https://github.com/kpdecker/jsdiff/tree/v4.0.1#api
51
+ * @param linesOffset line number to start counting from
52
+ * @param showLines lines that are always shown, regardless of diff
53
+ */
54
+ declare const computeLineInformation: (oldString: string | Object, newString: string | Object, disableWordDiff?: boolean, lineCompareMethod?: string, linesOffset?: number, showLines?: string[]) => ComputedLineInformation;
55
+ export { computeLineInformation };
@@ -0,0 +1,228 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.computeLineInformation = exports.DiffMethod = exports.DiffType = void 0;
27
+ const diff = __importStar(require("diff"));
28
+ const jsDiff = diff;
29
+ var DiffType;
30
+ (function (DiffType) {
31
+ DiffType[DiffType["DEFAULT"] = 0] = "DEFAULT";
32
+ DiffType[DiffType["ADDED"] = 1] = "ADDED";
33
+ DiffType[DiffType["REMOVED"] = 2] = "REMOVED";
34
+ DiffType[DiffType["CHANGED"] = 3] = "CHANGED";
35
+ })(DiffType || (exports.DiffType = DiffType = {}));
36
+ // See https://github.com/kpdecker/jsdiff/tree/v4.0.1#api for more info on the below JsDiff methods
37
+ var DiffMethod;
38
+ (function (DiffMethod) {
39
+ DiffMethod["CHARS"] = "diffChars";
40
+ DiffMethod["WORDS"] = "diffWords";
41
+ DiffMethod["WORDS_WITH_SPACE"] = "diffWordsWithSpace";
42
+ DiffMethod["LINES"] = "diffLines";
43
+ DiffMethod["TRIMMED_LINES"] = "diffTrimmedLines";
44
+ DiffMethod["SENTENCES"] = "diffSentences";
45
+ DiffMethod["CSS"] = "diffCss";
46
+ DiffMethod["JSON"] = "diffJson";
47
+ })(DiffMethod || (exports.DiffMethod = DiffMethod = {}));
48
+ /**
49
+ * Splits diff text by new line and computes final list of diff lines based on
50
+ * conditions.
51
+ *
52
+ * @param value Diff text from the js diff module.
53
+ */
54
+ const constructLines = (value) => {
55
+ if (value === '')
56
+ return [];
57
+ const lines = value.replace(/\n$/, '').split('\n');
58
+ return lines;
59
+ };
60
+ /**
61
+ * Computes word diff information in the line.
62
+ * [TODO]: Consider adding options argument for JsDiff text block comparison
63
+ *
64
+ * @param oldValue Old word in the line.
65
+ * @param newValue New word in the line.
66
+ * @param compareMethod JsDiff text diff method from https://github.com/kpdecker/jsdiff/tree/v4.0.1#api
67
+ */
68
+ const computeDiff = (oldValue, newValue, compareMethod = DiffMethod.CHARS) => {
69
+ const diffArray = jsDiff[compareMethod](oldValue, newValue);
70
+ const computedDiff = {
71
+ left: [],
72
+ right: [],
73
+ };
74
+ diffArray.forEach(({ added, removed, value }) => {
75
+ const diffInformation = {};
76
+ if (added) {
77
+ diffInformation.type = DiffType.ADDED;
78
+ diffInformation.value = value;
79
+ computedDiff.right.push(diffInformation);
80
+ }
81
+ if (removed) {
82
+ diffInformation.type = DiffType.REMOVED;
83
+ diffInformation.value = value;
84
+ computedDiff.left.push(diffInformation);
85
+ }
86
+ if (!removed && !added) {
87
+ diffInformation.type = DiffType.DEFAULT;
88
+ diffInformation.value = value;
89
+ computedDiff.right.push(diffInformation);
90
+ computedDiff.left.push(diffInformation);
91
+ }
92
+ return diffInformation;
93
+ });
94
+ return computedDiff;
95
+ };
96
+ /**
97
+ * [TODO]: Think about moving common left and right value assignment to a
98
+ * common place. Better readability?
99
+ *
100
+ * Computes line wise information based in the js diff information passed. Each
101
+ * line contains information about left and right section. Left side denotes
102
+ * deletion and right side denotes addition.
103
+ *
104
+ * @param oldString Old string to compare.
105
+ * @param newString New string to compare with old string.
106
+ * @param disableWordDiff Flag to enable/disable word diff.
107
+ * @param lineCompareMethod JsDiff text diff method from https://github.com/kpdecker/jsdiff/tree/v4.0.1#api
108
+ * @param linesOffset line number to start counting from
109
+ * @param showLines lines that are always shown, regardless of diff
110
+ */
111
+ const computeLineInformation = (oldString, newString, disableWordDiff = false, lineCompareMethod = DiffMethod.CHARS, linesOffset = 0, showLines = []) => {
112
+ let diffArray = [];
113
+ // Use diffLines for strings, and diffJson for objects...
114
+ if (typeof oldString === 'string' && typeof newString === 'string') {
115
+ diffArray = diff.diffLines(oldString, newString, {
116
+ newlineIsToken: false,
117
+ ignoreWhitespace: false,
118
+ ignoreCase: false,
119
+ });
120
+ }
121
+ else {
122
+ diffArray = diff.diffJson(oldString, newString);
123
+ }
124
+ let rightLineNumber = linesOffset;
125
+ let leftLineNumber = linesOffset;
126
+ let lineInformation = [];
127
+ let counter = 0;
128
+ const diffLines = [];
129
+ const ignoreDiffIndexes = [];
130
+ const getLineInformation = (value, diffIndex, added, removed, evaluateOnlyFirstLine) => {
131
+ const lines = constructLines(value);
132
+ return lines
133
+ .map((line, lineIndex) => {
134
+ const left = {};
135
+ const right = {};
136
+ if (ignoreDiffIndexes.includes(`${diffIndex}-${lineIndex}`) ||
137
+ (evaluateOnlyFirstLine && lineIndex !== 0)) {
138
+ return undefined;
139
+ }
140
+ if (added || removed) {
141
+ let countAsChange = true;
142
+ if (removed) {
143
+ leftLineNumber += 1;
144
+ left.lineNumber = leftLineNumber;
145
+ left.type = DiffType.REMOVED;
146
+ left.value = line || ' ';
147
+ // When the current line is of type REMOVED, check the next item in
148
+ // the diff array whether it is of type ADDED. If true, the current
149
+ // diff will be marked as both REMOVED and ADDED. Meaning, the
150
+ // current line is a modification.
151
+ const nextDiff = diffArray[diffIndex + 1];
152
+ if (nextDiff && nextDiff.added) {
153
+ const nextDiffLines = constructLines(nextDiff.value)[lineIndex];
154
+ if (nextDiffLines) {
155
+ const nextDiffLineInfo = getLineInformation(nextDiffLines, diffIndex, true, false, true);
156
+ const { value: rightValue, lineNumber, type, } = nextDiffLineInfo[0].right;
157
+ // When identified as modification, push the next diff to ignore
158
+ // list as the next value will be added in this line computation as
159
+ // right and left values.
160
+ ignoreDiffIndexes.push(`${diffIndex + 1}-${lineIndex}`);
161
+ right.lineNumber = lineNumber;
162
+ if (left.value === rightValue) {
163
+ // The new value is exactly the same as the old
164
+ countAsChange = false;
165
+ right.type = 0;
166
+ left.type = 0;
167
+ right.value = rightValue;
168
+ }
169
+ else {
170
+ right.type = type;
171
+ // Do char level diff and assign the corresponding values to the
172
+ // left and right diff information object.
173
+ if (disableWordDiff) {
174
+ right.value = rightValue;
175
+ }
176
+ else {
177
+ const computedDiff = computeDiff(line, rightValue, lineCompareMethod);
178
+ right.value = computedDiff.right;
179
+ left.value = computedDiff.left;
180
+ }
181
+ }
182
+ }
183
+ }
184
+ }
185
+ else {
186
+ rightLineNumber += 1;
187
+ right.lineNumber = rightLineNumber;
188
+ right.type = DiffType.ADDED;
189
+ right.value = line;
190
+ }
191
+ if (countAsChange && !evaluateOnlyFirstLine) {
192
+ if (!diffLines.includes(counter)) {
193
+ diffLines.push(counter);
194
+ }
195
+ }
196
+ }
197
+ else {
198
+ leftLineNumber += 1;
199
+ rightLineNumber += 1;
200
+ left.lineNumber = leftLineNumber;
201
+ left.type = DiffType.DEFAULT;
202
+ left.value = line;
203
+ right.lineNumber = rightLineNumber;
204
+ right.type = DiffType.DEFAULT;
205
+ right.value = line;
206
+ }
207
+ if ((showLines === null || showLines === void 0 ? void 0 : showLines.includes(`L-${left.lineNumber}`)) || (showLines === null || showLines === void 0 ? void 0 : showLines.includes(`R-${right.lineNumber}`)) && !diffLines.includes(counter)) {
208
+ diffLines.push(counter);
209
+ }
210
+ if (!evaluateOnlyFirstLine) {
211
+ counter += 1;
212
+ }
213
+ return { right, left };
214
+ })
215
+ .filter(Boolean);
216
+ };
217
+ diffArray.forEach(({ added, removed, value }, index) => {
218
+ lineInformation = [
219
+ ...lineInformation,
220
+ ...getLineInformation(value, index, added, removed),
221
+ ];
222
+ });
223
+ return {
224
+ lineInformation,
225
+ diffLines,
226
+ };
227
+ };
228
+ exports.computeLineInformation = computeLineInformation;
@@ -0,0 +1 @@
1
+ export declare function Expand(): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Expand = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ function Expand() {
6
+ return (0, jsx_runtime_1.jsx)("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 16 16", width: "16", height: "16", children: (0, jsx_runtime_1.jsx)("path", { d: "m8.177.677 2.896 2.896a.25.25 0 0 1-.177.427H8.75v1.25a.75.75 0 0 1-1.5 0V4H5.104a.25.25 0 0 1-.177-.427L7.823.677a.25.25 0 0 1 .354 0ZM7.25 10.75a.75.75 0 0 1 1.5 0V12h2.146a.25.25 0 0 1 .177.427l-2.896 2.896a.25.25 0 0 1-.354 0l-2.896-2.896A.25.25 0 0 1 5.104 12H7.25v-1.25Zm-5-2a.75.75 0 0 0 0-1.5h-.5a.75.75 0 0 0 0 1.5h.5ZM6 8a.75.75 0 0 1-.75.75h-.5a.75.75 0 0 1 0-1.5h.5A.75.75 0 0 1 6 8Zm2.25.75a.75.75 0 0 0 0-1.5h-.5a.75.75 0 0 0 0 1.5h.5ZM12 8a.75.75 0 0 1-.75.75h-.5a.75.75 0 0 1 0-1.5h.5A.75.75 0 0 1 12 8Zm2.25.75a.75.75 0 0 0 0-1.5h-.5a.75.75 0 0 0 0 1.5h.5Z" }) });
7
+ }
8
+ exports.Expand = Expand;
@@ -0,0 +1 @@
1
+ export declare function Fold(): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Fold = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ function Fold() {
6
+ return (0, jsx_runtime_1.jsx)("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 16 16", width: "16", height: "16", children: (0, jsx_runtime_1.jsx)("path", { d: "M10.896 2H8.75V.75a.75.75 0 0 0-1.5 0V2H5.104a.25.25 0 0 0-.177.427l2.896 2.896a.25.25 0 0 0 .354 0l2.896-2.896A.25.25 0 0 0 10.896 2ZM8.75 15.25a.75.75 0 0 1-1.5 0V14H5.104a.25.25 0 0 1-.177-.427l2.896-2.896a.25.25 0 0 1 .354 0l2.896 2.896a.25.25 0 0 1-.177.427H8.75v1.25Zm-6.5-6.5a.75.75 0 0 0 0-1.5h-.5a.75.75 0 0 0 0 1.5h.5ZM6 8a.75.75 0 0 1-.75.75h-.5a.75.75 0 0 1 0-1.5h.5A.75.75 0 0 1 6 8Zm2.25.75a.75.75 0 0 0 0-1.5h-.5a.75.75 0 0 0 0 1.5h.5ZM12 8a.75.75 0 0 1-.75.75h-.5a.75.75 0 0 1 0-1.5h.5A.75.75 0 0 1 12 8Zm2.25.75a.75.75 0 0 0 0-1.5h-.5a.75.75 0 0 0 0 1.5h.5Z" }) });
7
+ }
8
+ exports.Fold = Fold;
@@ -0,0 +1,141 @@
1
+ import * as React from 'react';
2
+ import { ReactElement } from 'react';
3
+ import { DiffInformation, DiffMethod, DiffType, LineInformation } from './compute-lines';
4
+ import { ReactDiffViewerStyles, ReactDiffViewerStylesOverride } from './styles';
5
+ export declare enum LineNumberPrefix {
6
+ LEFT = "L",
7
+ RIGHT = "R"
8
+ }
9
+ export interface ReactDiffViewerProps {
10
+ oldValue: string | Object;
11
+ newValue: string | Object;
12
+ splitView?: boolean;
13
+ linesOffset?: number;
14
+ disableWordDiff?: boolean;
15
+ compareMethod?: DiffMethod;
16
+ extraLinesSurroundingDiff?: number;
17
+ hideLineNumbers?: boolean;
18
+ /**
19
+ * Show the lines indicated here. Specified as L20 or R18 for respectively line 20 on the left or line 18 on the right.
20
+ */
21
+ alwaysShowLines?: string[];
22
+ showDiffOnly?: boolean;
23
+ renderContent?: (source: string) => ReactElement;
24
+ codeFoldMessageRenderer?: (totalFoldedLines: number, leftStartLineNumber: number, rightStartLineNumber: number) => ReactElement;
25
+ onLineNumberClick?: (lineId: string, event: React.MouseEvent<HTMLTableCellElement>) => void;
26
+ renderGutter?: (data: {
27
+ lineNumber: number;
28
+ type: DiffType;
29
+ prefix: LineNumberPrefix;
30
+ value: string | DiffInformation[];
31
+ additionalLineNumber: number;
32
+ additionalPrefix: LineNumberPrefix;
33
+ styles: ReactDiffViewerStyles;
34
+ }) => ReactElement;
35
+ highlightLines?: string[];
36
+ styles?: ReactDiffViewerStylesOverride;
37
+ useDarkTheme?: boolean;
38
+ /**
39
+ * Used to describe the thing being diffed
40
+ */
41
+ summary?: string | ReactElement;
42
+ leftTitle?: string | ReactElement;
43
+ rightTitle?: string | ReactElement;
44
+ nonce?: string;
45
+ }
46
+ export interface ReactDiffViewerState {
47
+ expandedBlocks?: number[];
48
+ noSelect?: 'left' | 'right';
49
+ }
50
+ declare class DiffViewer extends React.Component<ReactDiffViewerProps, ReactDiffViewerState> {
51
+ private styles;
52
+ static defaultProps: ReactDiffViewerProps;
53
+ constructor(props: ReactDiffViewerProps);
54
+ /**
55
+ * Resets code block expand to the initial stage. Will be exposed to the parent component via
56
+ * refs.
57
+ */
58
+ resetCodeBlocks: () => boolean;
59
+ /**
60
+ * Pushes the target expanded code block to the state. During the re-render,
61
+ * this value is used to expand/fold unmodified code.
62
+ */
63
+ private onBlockExpand;
64
+ /**
65
+ * Computes final styles for the diff viewer. It combines the default styles with the user
66
+ * supplied overrides. The computed styles are cached with performance in mind.
67
+ *
68
+ * @param styles User supplied style overrides.
69
+ */
70
+ private computeStyles;
71
+ /**
72
+ * Returns a function with clicked line number in the closure. Returns an no-op function when no
73
+ * onLineNumberClick handler is supplied.
74
+ *
75
+ * @param id Line id of a line.
76
+ */
77
+ private onLineNumberClickProxy;
78
+ /**
79
+ * Maps over the word diff and constructs the required React elements to show word diff.
80
+ *
81
+ * @param diffArray Word diff information derived from line information.
82
+ * @param renderer Optional renderer to format diff words. Useful for syntax highlighting.
83
+ */
84
+ private renderWordDiff;
85
+ /**
86
+ * Maps over the line diff and constructs the required react elements to show line diff. It calls
87
+ * renderWordDiff when encountering word diff. This takes care of both inline and split view line
88
+ * renders.
89
+ *
90
+ * @param lineNumber Line number of the current line.
91
+ * @param type Type of diff of the current line.
92
+ * @param prefix Unique id to prefix with the line numbers.
93
+ * @param value Content of the line. It can be a string or a word diff array.
94
+ * @param additionalLineNumber Additional line number to be shown. Useful for rendering inline
95
+ * diff view. Right line number will be passed as additionalLineNumber.
96
+ * @param additionalPrefix Similar to prefix but for additional line number.
97
+ */
98
+ private renderLine;
99
+ /**
100
+ * Generates lines for split view.
101
+ *
102
+ * @param obj Line diff information.
103
+ * @param obj.left Life diff information for the left pane of the split view.
104
+ * @param obj.right Life diff information for the right pane of the split view.
105
+ * @param index React key for the lines.
106
+ */
107
+ private renderSplitView;
108
+ /**
109
+ * Generates lines for inline view.
110
+ *
111
+ * @param obj Line diff information.
112
+ * @param obj.left Life diff information for the added section of the inline view.
113
+ * @param obj.right Life diff information for the removed section of the inline view.
114
+ * @param index React key for the lines.
115
+ */
116
+ renderInlineView: ({ left, right }: LineInformation, index: number) => ReactElement;
117
+ /**
118
+ * Returns a function with clicked block number in the closure.
119
+ *
120
+ * @param id Cold fold block id.
121
+ */
122
+ private onBlockClickProxy;
123
+ /**
124
+ * Generates cold fold block. It also uses the custom message renderer when available to show
125
+ * cold fold messages.
126
+ *
127
+ * @param num Number of skipped lines between two blocks.
128
+ * @param blockNumber Code fold block id.
129
+ * @param leftBlockLineNumber First left line number after the current code fold block.
130
+ * @param rightBlockLineNumber First right line number after the current code fold block.
131
+ */
132
+ private renderSkippedLineIndicator;
133
+ /**
134
+ * Generates the entire diff view.
135
+ */
136
+ private renderDiff;
137
+ render: () => ReactElement;
138
+ }
139
+ export default DiffViewer;
140
+ export { DiffMethod };
141
+ export type { ReactDiffViewerStylesOverride };