Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 446ca9a

Browse files
refactor: handlers and logic code inside viewer component is splitted into different files and constant improvements
1 parent e482cde commit 446ca9a

File tree

6 files changed

+229
-207
lines changed

6 files changed

+229
-207
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import type { DiffResult } from "json-diff-kit";
2+
import type { ListChildComponentProps } from "react-window";
3+
4+
import { Viewer } from "json-diff-kit";
5+
6+
import type { DiffRowOrCollapsed } from "../types";
7+
8+
import { DIFF_VIEWER_CLASS, isCollapsed } from "../utils/constants";
9+
10+
function ViewerRow({
11+
index,
12+
style,
13+
data,
14+
}: ListChildComponentProps<{
15+
leftDiff: DiffRowOrCollapsed[];
16+
rightDiff: DiffRowOrCollapsed[];
17+
onExpand: (segmentIndex: number) => void;
18+
searchTerm?: string;
19+
}>) {
20+
const { onExpand, searchTerm } = data;
21+
const originalLeftLine = data.leftDiff[index];
22+
const originalRightLine = data.rightDiff[index];
23+
24+
if (isCollapsed(originalLeftLine)) {
25+
return (
26+
<div className="collapsed-button" style={style}>
27+
<button onClick={() => onExpand(originalLeftLine.segmentIndex)} className="text-blue-500 underline">
28+
Show Hidden Lines
29+
</button>
30+
</div>
31+
);
32+
}
33+
34+
const leftLine = { ...originalLeftLine } as DiffResult;
35+
const rightLine = { ...originalRightLine } as DiffResult;
36+
37+
return (
38+
<div style={style}>
39+
<Viewer
40+
indent={1}
41+
className={`${DIFF_VIEWER_CLASS} ${searchTerm ? "has-search" : ""}`}
42+
lineNumbers
43+
diff={[[leftLine], [rightLine]]}
44+
highlightInlineDiff
45+
inlineDiffOptions={{ mode: "word" }}
46+
syntaxHighlight={{ theme: "monokai" }}
47+
/>
48+
</div>
49+
);
50+
}
51+
52+
export default ViewerRow;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /