react-diff-viewer-continued 4.0.2 → 4.0.3

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/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [4.0.3](https://github.com/aeolun/react-diff-viewer-continued/compare/v4.0.2...v4.0.3) (2024-05-23)
2
+
3
+
4
+ ### Reverts
5
+
6
+ * Revert "refactoring attempt" ([6a9789b](https://github.com/aeolun/react-diff-viewer-continued/commit/6a9789b0af0221bf32be11d1af9d4db3337008f4))
7
+
1
8
  ## [4.0.2](https://github.com/aeolun/react-diff-viewer-continued/compare/v4.0.1...v4.0.2) (2024-02-14)
2
9
 
3
10
 
package/README.md CHANGED
@@ -71,11 +71,11 @@ class Diff extends PureComponent {
71
71
 
72
72
  | Prop | Type | Default | Description |
73
73
  |---------------------------|---------------------------|--------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
74
- | oldValue | `string | Object` | `''` | Old value as string (or Object if using `diffJson`). |
75
- | newValue | `string | Object` | `''` | New value as string (or Object if using `diffJson`). |
74
+ | oldValue | `string \| Object` | `''` | Old value as string (or Object if using `diffJson`). |
75
+ | newValue | `string \| Object` | `''` | New value as string (or Object if using `diffJson`). |
76
76
  | splitView | `boolean` | `true` | Switch between `unified` and `split` view. |
77
77
  | disableWordDiff | `boolean` | `false` | Show and hide word diff in a diff line. |
78
- | 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. |
78
+ | compareMethod | `DiffMethod \| (string, string) => diff.Change[]` | `DiffMethod.CHARS` | Uses an existing diff method when a `DiffMethod` enum is passed. If a function is passed, that function is used as the diff method. <br /> <br /> 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. |
79
79
  | renderGutter | `(diffData) => ReactNode` | `undefined` | Function that can be used to render an extra gutter with various information next to the line number. |
80
80
  | hideLineNumbers | `boolean` | `false` | Show and hide line numbers. |
81
81
  | alwaysShowLines | `string[]` | `[]` | List of lines to always be shown, regardless of diff status. 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. `extraLinesSurroundingDiff` applies to these lines as well. |
@@ -1,3 +1,4 @@
1
+ import * as diff from 'diff';
1
2
  export declare enum DiffType {
2
3
  DEFAULT = 0,
3
4
  ADDED = 1,
@@ -51,5 +52,5 @@ export interface JsDiffChangeObject {
51
52
  * @param linesOffset line number to start counting from
52
53
  * @param showLines lines that are always shown, regardless of diff
53
54
  */
54
- declare const computeLineInformation: (oldString: string | Object, newString: string | Object, disableWordDiff?: boolean, lineCompareMethod?: string, linesOffset?: number, showLines?: string[]) => ComputedLineInformation;
55
+ declare const computeLineInformation: (oldString: string | Object, newString: string | Object, disableWordDiff?: boolean, lineCompareMethod?: DiffMethod | ((oldStr: string, newStr: string) => diff.Change[]), linesOffset?: number, showLines?: string[]) => ComputedLineInformation;
55
56
  export { computeLineInformation };
@@ -66,7 +66,8 @@ const constructLines = (value) => {
66
66
  * @param compareMethod JsDiff text diff method from https://github.com/kpdecker/jsdiff/tree/v4.0.1#api
67
67
  */
68
68
  const computeDiff = (oldValue, newValue, compareMethod = DiffMethod.CHARS) => {
69
- const diffArray = jsDiff[compareMethod](oldValue, newValue);
69
+ const compareFunc = (typeof (compareMethod) === 'string') ? jsDiff[compareMethod] : compareMethod;
70
+ const diffArray = compareFunc(oldValue, newValue);
70
71
  const computedDiff = {
71
72
  left: [],
72
73
  right: [],
@@ -1,6 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import { ReactElement } from 'react';
3
3
  import { DiffInformation, DiffMethod, DiffType, LineInformation } from './compute-lines';
4
+ import { Change } from 'diff';
4
5
  import { ReactDiffViewerStyles, ReactDiffViewerStylesOverride } from './styles';
5
6
  export declare enum LineNumberPrefix {
6
7
  LEFT = "L",
@@ -12,7 +13,7 @@ export interface ReactDiffViewerProps {
12
13
  splitView?: boolean;
13
14
  linesOffset?: number;
14
15
  disableWordDiff?: boolean;
15
- compareMethod?: DiffMethod;
16
+ compareMethod?: DiffMethod | ((oldStr: string, newStr: string) => Change[]);
16
17
  extraLinesSurroundingDiff?: number;
17
18
  hideLineNumbers?: boolean;
18
19
  /**
@@ -285,8 +285,8 @@ class DiffViewer extends React.Component {
285
285
  };
286
286
  };
287
287
  this.render = () => {
288
- const { oldValue, newValue, useDarkTheme, leftTitle, rightTitle, splitView, hideLineNumbers, nonce, } = this.props;
289
- if (this.props.compareMethod !== compute_lines_1.DiffMethod.JSON) {
288
+ const { oldValue, newValue, useDarkTheme, leftTitle, rightTitle, splitView, compareMethod, hideLineNumbers, nonce, } = this.props;
289
+ if (typeof (compareMethod) === 'string' && compareMethod !== compute_lines_1.DiffMethod.JSON) {
290
290
  if (typeof oldValue !== 'string' || typeof newValue !== 'string') {
291
291
  throw Error('"oldValue" and "newValue" should be strings');
292
292
  }
@@ -40,7 +40,8 @@ const constructLines = (value) => {
40
40
  * @param compareMethod JsDiff text diff method from https://github.com/kpdecker/jsdiff/tree/v4.0.1#api
41
41
  */
42
42
  const computeDiff = (oldValue, newValue, compareMethod = DiffMethod.CHARS) => {
43
- const diffArray = jsDiff[compareMethod](oldValue, newValue);
43
+ const compareFunc = (typeof (compareMethod) === 'string') ? jsDiff[compareMethod] : compareMethod;
44
+ const diffArray = compareFunc(oldValue, newValue);
44
45
  const computedDiff = {
45
46
  left: [],
46
47
  right: [],
@@ -276,8 +276,8 @@ class DiffViewer extends React.Component {
276
276
  };
277
277
  };
278
278
  render = () => {
279
- const { oldValue, newValue, useDarkTheme, leftTitle, rightTitle, splitView, hideLineNumbers, nonce, } = this.props;
280
- if (this.props.compareMethod !== DiffMethod.JSON) {
279
+ const { oldValue, newValue, useDarkTheme, leftTitle, rightTitle, splitView, compareMethod, hideLineNumbers, nonce, } = this.props;
280
+ if (typeof (compareMethod) === 'string' && compareMethod !== DiffMethod.JSON) {
281
281
  if (typeof oldValue !== 'string' || typeof newValue !== 'string') {
282
282
  throw Error('"oldValue" and "newValue" should be strings');
283
283
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-diff-viewer-continued",
3
- "version": "4.0.2",
3
+ "version": "4.0.3",
4
4
  "private": false,
5
5
  "description": "Continuation of a simple and beautiful text diff viewer component made with diff and React",
6
6
  "keywords": [
@@ -49,7 +49,7 @@
49
49
  "@types/node": "^20.11.17",
50
50
  "@types/react": "^18.2.55",
51
51
  "@types/react-dom": "^18.2.19",
52
- "gh-pages": "^4.0.0",
52
+ "gh-pages": "^5.0.0",
53
53
  "happy-dom": "^13.3.8",
54
54
  "react": "^18.2.0",
55
55
  "react-dom": "^18.2.0",