react-diff-viewer-continued 4.0.4 → 4.0.6

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,18 @@
1
+ ## [4.0.6](https://github.com/aeolun/react-diff-viewer-continued/compare/v4.0.5...v4.0.6) (2025-05-13)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * allow non-string rendered contents ([a0ab52d](https://github.com/aeolun/react-diff-viewer-continued/commit/a0ab52d3d064297d1957c7fb65f9742f53a191a7))
7
+ * fixup [#68](https://github.com/aeolun/react-diff-viewer-continued/issues/68) for non-string wordDiff.value ([3678e02](https://github.com/aeolun/react-diff-viewer-continued/commit/3678e020855f0fec8f15084291cb5adc54a2c009))
8
+
9
+ ## [4.0.5](https://github.com/aeolun/react-diff-viewer-continued/compare/v4.0.4...v4.0.5) (2025-01-31)
10
+
11
+
12
+ ### Bug Fixes
13
+
14
+ * modify imports for proper esm resolution ([7fda63a](https://github.com/aeolun/react-diff-viewer-continued/commit/7fda63afae8bcd98547c8bdff569d02256821b2d))
15
+
1
16
  ## [4.0.4](https://github.com/aeolun/react-diff-viewer-continued/compare/v4.0.3...v4.0.4) (2025-01-28)
2
17
 
3
18
 
@@ -1,8 +1,8 @@
1
1
  import * as React from "react";
2
2
  import type { ReactElement } from "react";
3
3
  import type { Change } from "diff";
4
- import { type DiffInformation, DiffMethod, DiffType, type LineInformation } from "./compute-lines";
5
- import { type ReactDiffViewerStyles, type ReactDiffViewerStylesOverride } from "./styles";
4
+ import { type DiffInformation, DiffMethod, DiffType, type LineInformation } from "./compute-lines.js";
5
+ import { type ReactDiffViewerStyles, type ReactDiffViewerStylesOverride } from "./styles.js";
6
6
  export declare enum LineNumberPrefix {
7
7
  LEFT = "L",
8
8
  RIGHT = "R"
@@ -41,12 +41,12 @@ const jsx_runtime_1 = require("react/jsx-runtime");
41
41
  const classnames_1 = __importDefault(require("classnames"));
42
42
  const React = __importStar(require("react"));
43
43
  const memoize_one_1 = __importDefault(require("memoize-one"));
44
- const compute_hidden_blocks_1 = require("./compute-hidden-blocks");
45
- const compute_lines_1 = require("./compute-lines");
46
- Object.defineProperty(exports, "DiffMethod", { enumerable: true, get: function () { return compute_lines_1.DiffMethod; } });
47
- const expand_1 = require("./expand");
48
- const styles_1 = __importDefault(require("./styles"));
49
- const fold_1 = require("./fold");
44
+ const compute_hidden_blocks_js_1 = require("./compute-hidden-blocks.js");
45
+ const compute_lines_js_1 = require("./compute-lines.js");
46
+ Object.defineProperty(exports, "DiffMethod", { enumerable: true, get: function () { return compute_lines_js_1.DiffMethod; } });
47
+ const expand_js_1 = require("./expand.js");
48
+ const styles_js_1 = __importDefault(require("./styles.js"));
49
+ const fold_js_1 = require("./fold.js");
50
50
  var LineNumberPrefix;
51
51
  (function (LineNumberPrefix) {
52
52
  LineNumberPrefix["LEFT"] = "L";
@@ -85,7 +85,7 @@ class DiffViewer extends React.Component {
85
85
  *
86
86
  * @param styles User supplied style overrides.
87
87
  */
88
- this.computeStyles = (0, memoize_one_1.default)(styles_1.default);
88
+ this.computeStyles = (0, memoize_one_1.default)(styles_js_1.default);
89
89
  /**
90
90
  * Returns a function with clicked line number in the closure. Returns an no-op function when no
91
91
  * onLineNumberClick handler is supplied.
@@ -108,13 +108,14 @@ class DiffViewer extends React.Component {
108
108
  return diffArray.map((wordDiff, i) => {
109
109
  const content = renderer
110
110
  ? renderer(wordDiff.value)
111
- : wordDiff.value;
112
- if (typeof content !== "string")
113
- return;
114
- return wordDiff.type === compute_lines_1.DiffType.ADDED ? ((0, jsx_runtime_1.jsx)("ins", { className: (0, classnames_1.default)(this.styles.wordDiff, {
115
- [this.styles.wordAdded]: wordDiff.type === compute_lines_1.DiffType.ADDED,
116
- }), children: content }, i)) : wordDiff.type === compute_lines_1.DiffType.REMOVED ? ((0, jsx_runtime_1.jsx)("del", { className: (0, classnames_1.default)(this.styles.wordDiff, {
117
- [this.styles.wordRemoved]: wordDiff.type === compute_lines_1.DiffType.REMOVED,
111
+ : (typeof wordDiff.value === 'string'
112
+ ? wordDiff.value
113
+ // If wordDiff.value is DiffInformation, we don't handle it, unclear why. See c0c99f5712.
114
+ : undefined);
115
+ return wordDiff.type === compute_lines_js_1.DiffType.ADDED ? ((0, jsx_runtime_1.jsx)("ins", { className: (0, classnames_1.default)(this.styles.wordDiff, {
116
+ [this.styles.wordAdded]: wordDiff.type === compute_lines_js_1.DiffType.ADDED,
117
+ }), children: content }, i)) : wordDiff.type === compute_lines_js_1.DiffType.REMOVED ? ((0, jsx_runtime_1.jsx)("del", { className: (0, classnames_1.default)(this.styles.wordDiff, {
118
+ [this.styles.wordRemoved]: wordDiff.type === compute_lines_js_1.DiffType.REMOVED,
118
119
  }), children: content }, i)) : ((0, jsx_runtime_1.jsx)("span", { className: (0, classnames_1.default)(this.styles.wordDiff), children: content }, i));
119
120
  });
120
121
  };
@@ -136,9 +137,9 @@ class DiffViewer extends React.Component {
136
137
  const additionalLineNumberTemplate = `${additionalPrefix}-${additionalLineNumber}`;
137
138
  const highlightLine = this.props.highlightLines.includes(lineNumberTemplate) ||
138
139
  this.props.highlightLines.includes(additionalLineNumberTemplate);
139
- const added = type === compute_lines_1.DiffType.ADDED;
140
- const removed = type === compute_lines_1.DiffType.REMOVED;
141
- const changed = type === compute_lines_1.DiffType.CHANGED;
140
+ const added = type === compute_lines_js_1.DiffType.ADDED;
141
+ const removed = type === compute_lines_js_1.DiffType.REMOVED;
142
+ const changed = type === compute_lines_js_1.DiffType.CHANGED;
142
143
  let content;
143
144
  const hasWordDiff = Array.isArray(value);
144
145
  if (hasWordDiff) {
@@ -227,16 +228,16 @@ class DiffViewer extends React.Component {
227
228
  */
228
229
  this.renderInlineView = ({ left, right }, index) => {
229
230
  let content;
230
- if (left.type === compute_lines_1.DiffType.REMOVED && right.type === compute_lines_1.DiffType.ADDED) {
231
+ if (left.type === compute_lines_js_1.DiffType.REMOVED && right.type === compute_lines_js_1.DiffType.ADDED) {
231
232
  return ((0, jsx_runtime_1.jsxs)(React.Fragment, { children: [(0, jsx_runtime_1.jsx)("tr", { className: this.styles.line, children: this.renderLine(left.lineNumber, left.type, LineNumberPrefix.LEFT, left.value, null) }), (0, jsx_runtime_1.jsx)("tr", { className: this.styles.line, children: this.renderLine(null, right.type, LineNumberPrefix.RIGHT, right.value, right.lineNumber, LineNumberPrefix.RIGHT) })] }, index));
232
233
  }
233
- if (left.type === compute_lines_1.DiffType.REMOVED) {
234
+ if (left.type === compute_lines_js_1.DiffType.REMOVED) {
234
235
  content = this.renderLine(left.lineNumber, left.type, LineNumberPrefix.LEFT, left.value, null);
235
236
  }
236
- if (left.type === compute_lines_1.DiffType.DEFAULT) {
237
+ if (left.type === compute_lines_js_1.DiffType.DEFAULT) {
237
238
  content = this.renderLine(left.lineNumber, left.type, LineNumberPrefix.LEFT, left.value, right.lineNumber, LineNumberPrefix.RIGHT);
238
239
  }
239
- if (right.type === compute_lines_1.DiffType.ADDED) {
240
+ if (right.type === compute_lines_js_1.DiffType.ADDED) {
240
241
  content = this.renderLine(null, right.type, LineNumberPrefix.RIGHT, right.value, right.lineNumber);
241
242
  }
242
243
  return ((0, jsx_runtime_1.jsx)("tr", { className: this.styles.line, children: content }, index));
@@ -270,11 +271,11 @@ class DiffViewer extends React.Component {
270
271
  */
271
272
  this.renderDiff = () => {
272
273
  const { oldValue, newValue, splitView, disableWordDiff, compareMethod, linesOffset, } = this.props;
273
- const { lineInformation, diffLines } = (0, compute_lines_1.computeLineInformation)(oldValue, newValue, disableWordDiff, compareMethod, linesOffset, this.props.alwaysShowLines);
274
+ const { lineInformation, diffLines } = (0, compute_lines_js_1.computeLineInformation)(oldValue, newValue, disableWordDiff, compareMethod, linesOffset, this.props.alwaysShowLines);
274
275
  const extraLines = this.props.extraLinesSurroundingDiff < 0
275
276
  ? 0
276
277
  : Math.round(this.props.extraLinesSurroundingDiff);
277
- const { lineBlocks, blocks } = (0, compute_hidden_blocks_1.computeHiddenBlocks)(lineInformation, diffLines, extraLines);
278
+ const { lineBlocks, blocks } = (0, compute_hidden_blocks_js_1.computeHiddenBlocks)(lineInformation, diffLines, extraLines);
278
279
  const diffNodes = lineInformation.map((line, lineIndex) => {
279
280
  if (this.props.showDiffOnly) {
280
281
  const blockIndex = lineBlocks[lineIndex];
@@ -302,7 +303,7 @@ class DiffViewer extends React.Component {
302
303
  this.render = () => {
303
304
  const { oldValue, newValue, useDarkTheme, leftTitle, rightTitle, splitView, compareMethod, hideLineNumbers, nonce, } = this.props;
304
305
  if (typeof compareMethod === "string" &&
305
- compareMethod !== compute_lines_1.DiffMethod.JSON) {
306
+ compareMethod !== compute_lines_js_1.DiffMethod.JSON) {
306
307
  if (typeof oldValue !== "string" || typeof newValue !== "string") {
307
308
  throw Error('"oldValue" and "newValue" should be strings');
308
309
  }
@@ -322,16 +323,16 @@ class DiffViewer extends React.Component {
322
323
  let deletions = 0;
323
324
  let additions = 0;
324
325
  for (const l of nodes.lineInformation) {
325
- if (l.left.type === compute_lines_1.DiffType.ADDED) {
326
+ if (l.left.type === compute_lines_js_1.DiffType.ADDED) {
326
327
  additions++;
327
328
  }
328
- if (l.right.type === compute_lines_1.DiffType.ADDED) {
329
+ if (l.right.type === compute_lines_js_1.DiffType.ADDED) {
329
330
  additions++;
330
331
  }
331
- if (l.left.type === compute_lines_1.DiffType.REMOVED) {
332
+ if (l.left.type === compute_lines_js_1.DiffType.REMOVED) {
332
333
  deletions++;
333
334
  }
334
- if (l.right.type === compute_lines_1.DiffType.REMOVED) {
335
+ if (l.right.type === compute_lines_js_1.DiffType.REMOVED) {
335
336
  deletions++;
336
337
  }
337
338
  }
@@ -353,7 +354,7 @@ class DiffViewer extends React.Component {
353
354
  ? []
354
355
  : nodes.blocks.map((b) => b.index),
355
356
  });
356
- }, children: allExpanded ? (0, jsx_runtime_1.jsx)(fold_1.Fold, {}) : (0, jsx_runtime_1.jsx)(expand_1.Expand, {}) }), " ", totalChanges, (0, jsx_runtime_1.jsx)("div", { style: { display: "flex", gap: "1px" }, children: blocks }), this.props.summary ? (0, jsx_runtime_1.jsx)("span", { children: this.props.summary }) : null] }), (0, jsx_runtime_1.jsx)("table", { className: (0, classnames_1.default)(this.styles.diffContainer, {
357
+ }, children: allExpanded ? (0, jsx_runtime_1.jsx)(fold_js_1.Fold, {}) : (0, jsx_runtime_1.jsx)(expand_js_1.Expand, {}) }), " ", totalChanges, (0, jsx_runtime_1.jsx)("div", { style: { display: "flex", gap: "1px" }, children: blocks }), this.props.summary ? (0, jsx_runtime_1.jsx)("span", { children: this.props.summary }) : null] }), (0, jsx_runtime_1.jsx)("table", { className: (0, classnames_1.default)(this.styles.diffContainer, {
357
358
  [this.styles.splitView]: splitView,
358
359
  }), onMouseUp: () => {
359
360
  const elements = document.getElementsByClassName("right");
@@ -380,7 +381,7 @@ DiffViewer.defaultProps = {
380
381
  splitView: true,
381
382
  highlightLines: [],
382
383
  disableWordDiff: false,
383
- compareMethod: compute_lines_1.DiffMethod.CHARS,
384
+ compareMethod: compute_lines_js_1.DiffMethod.CHARS,
384
385
  styles: {},
385
386
  hideLineNumbers: false,
386
387
  extraLinesSurroundingDiff: 3,
@@ -2,11 +2,11 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
2
2
  import cn from "classnames";
3
3
  import * as React from "react";
4
4
  import memoize from "memoize-one";
5
- import { computeHiddenBlocks } from "./compute-hidden-blocks";
6
- import { DiffMethod, DiffType, computeLineInformation, } from "./compute-lines";
7
- import { Expand } from "./expand";
8
- import computeStyles from "./styles";
9
- import { Fold } from "./fold";
5
+ import { computeHiddenBlocks } from "./compute-hidden-blocks.js";
6
+ import { DiffMethod, DiffType, computeLineInformation, } from "./compute-lines.js";
7
+ import { Expand } from "./expand.js";
8
+ import computeStyles from "./styles.js";
9
+ import { Fold } from "./fold.js";
10
10
  export var LineNumberPrefix;
11
11
  (function (LineNumberPrefix) {
12
12
  LineNumberPrefix["LEFT"] = "L";
@@ -89,9 +89,10 @@ class DiffViewer extends React.Component {
89
89
  return diffArray.map((wordDiff, i) => {
90
90
  const content = renderer
91
91
  ? renderer(wordDiff.value)
92
- : wordDiff.value;
93
- if (typeof content !== "string")
94
- return;
92
+ : (typeof wordDiff.value === 'string'
93
+ ? wordDiff.value
94
+ // If wordDiff.value is DiffInformation, we don't handle it, unclear why. See c0c99f5712.
95
+ : undefined);
95
96
  return wordDiff.type === DiffType.ADDED ? (_jsx("ins", { className: cn(this.styles.wordDiff, {
96
97
  [this.styles.wordAdded]: wordDiff.type === DiffType.ADDED,
97
98
  }), children: content }, i)) : wordDiff.type === DiffType.REMOVED ? (_jsx("del", { className: cn(this.styles.wordDiff, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-diff-viewer-continued",
3
- "version": "4.0.4",
3
+ "version": "4.0.6",
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": [