react-diff-viewer-continued 4.2.0 → 4.2.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.
- package/.claude/settings.local.json +2 -1
- package/.github/workflows/release.yml +2 -2
- package/CHANGELOG.md +17 -0
- package/lib/cjs/src/compute-lines.d.ts +4 -4
- package/lib/cjs/src/compute-lines.js +18 -23
- package/lib/cjs/src/index.d.ts +13 -4
- package/lib/cjs/src/index.js +112 -96
- package/lib/cjs/src/styles.d.ts +36 -32
- package/lib/cjs/src/styles.js +3 -7
- package/lib/cjs/src/workerBundle.d.ts +1 -1
- package/lib/cjs/src/workerBundle.js +1 -1
- package/lib/esm/src/compute-lines.js +18 -23
- package/lib/esm/src/index.js +99 -78
- package/lib/esm/src/styles.js +4 -8
- package/lib/esm/src/workerBundle.js +1 -1
- package/package.json +14 -14
- package/tsconfig.json +3 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 4.2.2 (2026-04-23)
|
|
4
|
+
|
|
5
|
+
### Bug Fixes
|
|
6
|
+
|
|
7
|
+
- strict typescript types, and visible loader
|
|
8
|
+
|
|
9
|
+
## 4.2.1 (2026-04-23)
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
- make overscan configurable
|
|
14
|
+
- handle ' HTML entity in diff view to prevent "undefined" suffix
|
|
15
|
+
- mousedown and mouseup
|
|
16
|
+
- do not show content while scrolling fast outside the overscan area
|
|
17
|
+
- update dependencies
|
|
18
|
+
- clean up old package-lock.json
|
|
19
|
+
|
|
3
20
|
## 4.2.0 (2026-03-10)
|
|
4
21
|
|
|
5
22
|
### Features
|
|
@@ -23,8 +23,8 @@ export interface DiffInformation {
|
|
|
23
23
|
rawValue?: string;
|
|
24
24
|
}
|
|
25
25
|
export interface LineInformation {
|
|
26
|
-
left
|
|
27
|
-
right
|
|
26
|
+
left: DiffInformation;
|
|
27
|
+
right: DiffInformation;
|
|
28
28
|
}
|
|
29
29
|
export interface ComputedLineInformation {
|
|
30
30
|
lineInformation: LineInformation[];
|
|
@@ -37,7 +37,7 @@ export interface ComputedDiffInformation {
|
|
|
37
37
|
export interface JsDiffChangeObject {
|
|
38
38
|
added?: boolean;
|
|
39
39
|
removed?: boolean;
|
|
40
|
-
value
|
|
40
|
+
value: string;
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
43
43
|
* Computes word diff information in the line.
|
|
@@ -64,5 +64,5 @@ declare const computeDiff: (oldValue: string | Record<string, unknown>, newValue
|
|
|
64
64
|
* @param showLines lines that are always shown, regardless of diff
|
|
65
65
|
*/
|
|
66
66
|
declare const computeLineInformation: (oldString: string | Record<string, unknown>, newString: string | Record<string, unknown>, disableWordDiff?: boolean, lineCompareMethod?: DiffMethod | ((oldStr: string, newStr: string) => diff.Change[]), linesOffset?: number, showLines?: string[], deferWordDiff?: boolean) => ComputedLineInformation;
|
|
67
|
-
declare const computeLineInformationWorker: (oldString: string | Record<string, unknown>, newString: string | Record<string, unknown>, disableWordDiff?: boolean, lineCompareMethod?: DiffMethod | ((oldStr: string, newStr: string) => diff.Change[]), linesOffset?: number, showLines?: string[], deferWordDiff?: boolean) => Promise<ComputedLineInformation>;
|
|
67
|
+
declare const computeLineInformationWorker: (oldString: string | Record<string, unknown>, newString: string | Record<string, unknown>, disableWordDiff?: boolean, lineCompareMethod?: DiffMethod | ((oldStr: string, newStr: string) => diff.Change[]), linesOffset?: number, showLines?: string[], deferWordDiff?: boolean, disableWorker?: boolean) => Promise<ComputedLineInformation>;
|
|
68
68
|
export { computeLineInformation, computeLineInformationWorker, computeDiff };
|
|
@@ -305,24 +305,17 @@ const computeDiff = (oldValue, newValue, compareMethod = DiffMethod.CHARS) => {
|
|
|
305
305
|
right: [],
|
|
306
306
|
};
|
|
307
307
|
diffArray.forEach(({ added, removed, value }) => {
|
|
308
|
-
const diffInformation = {};
|
|
309
308
|
if (added) {
|
|
310
|
-
|
|
311
|
-
diffInformation.value = value;
|
|
312
|
-
computedDiff.right.push(diffInformation);
|
|
309
|
+
computedDiff.right.push({ type: DiffType.ADDED, value });
|
|
313
310
|
}
|
|
314
|
-
if (removed) {
|
|
315
|
-
|
|
316
|
-
diffInformation.value = value;
|
|
317
|
-
computedDiff.left.push(diffInformation);
|
|
311
|
+
else if (removed) {
|
|
312
|
+
computedDiff.left.push({ type: DiffType.REMOVED, value });
|
|
318
313
|
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
computedDiff.
|
|
323
|
-
computedDiff.left.push(diffInformation);
|
|
314
|
+
else {
|
|
315
|
+
const info = { type: DiffType.DEFAULT, value };
|
|
316
|
+
computedDiff.right.push(info);
|
|
317
|
+
computedDiff.left.push(info);
|
|
324
318
|
}
|
|
325
|
-
return diffInformation;
|
|
326
319
|
});
|
|
327
320
|
return computedDiff;
|
|
328
321
|
};
|
|
@@ -477,7 +470,7 @@ const computeLineInformation = (oldString, newString, disableWordDiff = false, l
|
|
|
477
470
|
}
|
|
478
471
|
return { right, left };
|
|
479
472
|
})
|
|
480
|
-
.filter(
|
|
473
|
+
.filter((x) => x != null);
|
|
481
474
|
};
|
|
482
475
|
diffArray.forEach(({ added, removed, value }, index) => {
|
|
483
476
|
lineInformation = [
|
|
@@ -502,20 +495,21 @@ const computeLineInformation = (oldString, newString, disableWordDiff = false, l
|
|
|
502
495
|
* @param showLines lines that are always shown, regardless of diff
|
|
503
496
|
* @returns Promise<ComputedLineInformation> - Resolves with line-by-line diff data from the worker.
|
|
504
497
|
*/
|
|
505
|
-
// Import the bundled worker code (generated by scripts/build-worker.js)
|
|
506
|
-
import { WORKER_CODE } from './workerBundle.js';
|
|
507
498
|
// Cached Blob URL for the worker - created once and reused
|
|
508
499
|
let workerBlobUrl = null;
|
|
509
500
|
let workerAvailable = null;
|
|
510
|
-
//
|
|
511
|
-
const getWorkerBlobUrl = () => {
|
|
501
|
+
// Lazily import and create a Blob URL from the bundled worker code
|
|
502
|
+
const getWorkerBlobUrl = async () => {
|
|
512
503
|
if (workerBlobUrl !== null)
|
|
513
504
|
return workerBlobUrl;
|
|
505
|
+
if (workerAvailable === false)
|
|
506
|
+
return null;
|
|
514
507
|
if (typeof Worker === 'undefined' || typeof Blob === 'undefined' || typeof URL === 'undefined') {
|
|
515
508
|
workerAvailable = false;
|
|
516
509
|
return null;
|
|
517
510
|
}
|
|
518
511
|
try {
|
|
512
|
+
const { WORKER_CODE } = await import('./workerBundle.js');
|
|
519
513
|
const blob = new Blob([WORKER_CODE], { type: 'application/javascript' });
|
|
520
514
|
workerBlobUrl = URL.createObjectURL(blob);
|
|
521
515
|
workerAvailable = true;
|
|
@@ -526,9 +520,12 @@ const getWorkerBlobUrl = () => {
|
|
|
526
520
|
}
|
|
527
521
|
return workerBlobUrl;
|
|
528
522
|
};
|
|
529
|
-
const computeLineInformationWorker = (oldString, newString, disableWordDiff = false, lineCompareMethod = DiffMethod.CHARS, linesOffset = 0, showLines = [], deferWordDiff = false) => {
|
|
523
|
+
const computeLineInformationWorker = async (oldString, newString, disableWordDiff = false, lineCompareMethod = DiffMethod.CHARS, linesOffset = 0, showLines = [], deferWordDiff = false, disableWorker = false) => {
|
|
530
524
|
const fallback = () => computeLineInformation(oldString, newString, disableWordDiff, lineCompareMethod, linesOffset, showLines, deferWordDiff);
|
|
531
|
-
|
|
525
|
+
if (disableWorker) {
|
|
526
|
+
return Promise.resolve(fallback());
|
|
527
|
+
}
|
|
528
|
+
const blobUrl = await getWorkerBlobUrl();
|
|
532
529
|
if (!blobUrl) {
|
|
533
530
|
return Promise.resolve(fallback());
|
|
534
531
|
}
|
|
@@ -538,7 +535,6 @@ const computeLineInformationWorker = (oldString, newString, disableWordDiff = fa
|
|
|
538
535
|
worker = new Worker(blobUrl);
|
|
539
536
|
}
|
|
540
537
|
catch (_a) {
|
|
541
|
-
// Worker instantiation failed - fall back to synchronous computation
|
|
542
538
|
workerAvailable = false;
|
|
543
539
|
resolve(fallback());
|
|
544
540
|
return;
|
|
@@ -548,7 +544,6 @@ const computeLineInformationWorker = (oldString, newString, disableWordDiff = fa
|
|
|
548
544
|
worker.terminate();
|
|
549
545
|
};
|
|
550
546
|
worker.onerror = () => {
|
|
551
|
-
// Worker error - fall back and mark as unavailable for future calls
|
|
552
547
|
workerAvailable = false;
|
|
553
548
|
worker.terminate();
|
|
554
549
|
resolve(fallback());
|
package/lib/cjs/src/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export declare enum LineNumberPrefix {
|
|
|
11
11
|
export interface InfiniteLoadingProps {
|
|
12
12
|
pageSize: number;
|
|
13
13
|
containerHeight: string;
|
|
14
|
+
overscan?: number;
|
|
14
15
|
}
|
|
15
16
|
export interface ComputedDiffResult {
|
|
16
17
|
lineInformation: LineInformation[];
|
|
@@ -39,8 +40,8 @@ export interface ReactDiffViewerProps {
|
|
|
39
40
|
type: DiffType;
|
|
40
41
|
prefix: LineNumberPrefix;
|
|
41
42
|
value: string | DiffInformation[];
|
|
42
|
-
additionalLineNumber
|
|
43
|
-
additionalPrefix
|
|
43
|
+
additionalLineNumber?: number;
|
|
44
|
+
additionalPrefix?: LineNumberPrefix;
|
|
44
45
|
styles: ReactDiffViewerStyles;
|
|
45
46
|
}) => ReactElement;
|
|
46
47
|
highlightLines?: string[];
|
|
@@ -69,17 +70,23 @@ export interface ReactDiffViewerProps {
|
|
|
69
70
|
* Show debug overlay with virtualization info (for development)
|
|
70
71
|
*/
|
|
71
72
|
showDebugInfo?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Disable Web Worker for diff computation, using synchronous fallback instead.
|
|
75
|
+
* Useful when the worker bundle fails to load in certain bundler configurations.
|
|
76
|
+
*/
|
|
77
|
+
disableWorker?: boolean;
|
|
72
78
|
}
|
|
73
79
|
export interface ReactDiffViewerState {
|
|
74
|
-
expandedBlocks
|
|
80
|
+
expandedBlocks: number[];
|
|
75
81
|
noSelect?: "left" | "right";
|
|
76
|
-
scrollableContainerRef: RefObject<HTMLDivElement>;
|
|
82
|
+
scrollableContainerRef: RefObject<HTMLDivElement | null>;
|
|
77
83
|
computedDiffResult: Record<string, ComputedDiffResult>;
|
|
78
84
|
isLoading: boolean;
|
|
79
85
|
visibleStartRow: number;
|
|
80
86
|
contentColumnWidth: number | null;
|
|
81
87
|
charWidth: number | null;
|
|
82
88
|
cumulativeOffsets: number[] | null;
|
|
89
|
+
isScrolling: boolean;
|
|
83
90
|
}
|
|
84
91
|
declare class DiffViewer extends React.Component<ReactDiffViewerProps, ReactDiffViewerState> {
|
|
85
92
|
private styles;
|
|
@@ -88,6 +95,8 @@ declare class DiffViewer extends React.Component<ReactDiffViewerProps, ReactDiff
|
|
|
88
95
|
private charMeasureRef;
|
|
89
96
|
private stickyHeaderRef;
|
|
90
97
|
private resizeObserver;
|
|
98
|
+
private scrollDebounceTimer;
|
|
99
|
+
private lastRenderedRange;
|
|
91
100
|
static defaultProps: ReactDiffViewerProps;
|
|
92
101
|
constructor(props: ReactDiffViewerProps);
|
|
93
102
|
/**
|