Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/components/DiffViewer/Diff.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ const meta: Meta<StoryProps> = {
category: "Main Configuration",
},
},
inlineDiffOptions: {
description: "Options for inline diff highlighting",
control: "text",
table: {
disable: true,
category: "Main Configuration",
},
},
className: {
description: "CSS class name for the diff viewer container",
control: "text",
Expand All @@ -58,6 +66,11 @@ const meta: Meta<StoryProps> = {
control: "text",
table: { category: "Main Configuration" },
},
miniMapWidth: {
description: "Width of Minimap (default 20)",
control: "number",
table: { category: "Main Configuration" },
},
hideSearch: {
description: "Whether to hide the search functionality",
control: "boolean",
Expand Down Expand Up @@ -189,6 +202,7 @@ export const Primary: Story = {
rightTitle: "Right Title",
hideSearch: false,
height: 500,
miniMapWidth: 20,
oldValue: json1,
newValue: json2,

Expand Down
9 changes: 5 additions & 4 deletions src/components/DiffViewer/components/ViewerRow.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { DiffResult } from "json-diff-kit";
import type { DiffResult, InlineDiffOptions } from "json-diff-kit";
import type { ListChildComponentProps } from "react-window";

import { Viewer } from "json-diff-kit";
Expand All @@ -16,8 +16,9 @@ function ViewerRow({
rightDiff: DiffRowOrCollapsed[];
onExpand: (segmentIndex: number) => void;
searchTerm?: string;
inlineDiffOptions?: InlineDiffOptions;
}>) {
const { onExpand, searchTerm } = data;
const { onExpand, searchTerm, inlineDiffOptions } = data;
const originalLeftLine = data.leftDiff[index];
const originalRightLine = data.rightDiff[index];

Expand All @@ -37,12 +38,12 @@ function ViewerRow({
return (
<div style={style}>
<Viewer
indent={1}
indent={4}
className={`${DIFF_VIEWER_CLASS} ${searchTerm ? "has-search" : ""}`}
lineNumbers
diff={[[leftLine], [rightLine]]}
highlightInlineDiff
inlineDiffOptions={{ mode: "word" }}
inlineDiffOptions={{ mode: "char", ...inlineDiffOptions }}
syntaxHighlight={{ theme: "monokai" }}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const VirtualizedDiffViewer: React.FC<VirtualizedDiffViewerProps> = ({
differOptions,
className,
miniMapWidth,
inlineDiffOptions,
}) => {
const listRef = useRef<List>(null);
const [scrollTop, setScrollTop] = useState(0);
Expand Down Expand Up @@ -149,8 +150,9 @@ export const VirtualizedDiffViewer: React.FC<VirtualizedDiffViewerProps> = ({
rightDiff: rightView,
onExpand: handleExpand,
searchTerm: searchState.term,
inlineDiffOptions,
}),
[leftView, rightView, handleExpand, searchState.term],
[leftView, rightView, handleExpand, searchState.term, inlineDiffOptions],
);

return (
Expand Down
67 changes: 42 additions & 25 deletions src/components/DiffViewer/styles/JsonDiffCustomTheme.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,25 @@
}
}

.diff-viewer-container {
button {
border-radius: 4px;
border: 1px solid transparent;
font-size: 1em;
font-weight: 500;
font-family: inherit;
color: white;
background-color: #1a1a1a;
cursor: pointer;
transition: border-color 0.25s;
}
button:hover {
border-color: #649dffab;
}
button:focus,
button:focus-visible {
outline: 4px auto -webkit-focus-ring-color;
}
.diff-viewer-container button {
border-radius: 4px;
border: 1px solid transparent;
font-size: 1em;
font-weight: 500;
font-family: inherit;
color: white;
background-color: #1a1a1a;
cursor: pointer;
transition: border-color 0.25s;
}

.diff-viewer-container button:hover {
border-color: #649dffab;
}

.diff-viewer-container button:focus,
.diff-viewer-container button:focus-visible {
outline: 4px auto -webkit-focus-ring-color;
}

.json-diff-header {
Expand Down Expand Up @@ -145,14 +145,14 @@
border-radius: 2px;
}

.json-diff-viewer.json-diff-viewer-theme-custom .line-number {
color: #999;
}

.json-diff-viewer.json-diff-viewer-theme-custom tr td {
max-width: 260px;
width: 300px !important;
vertical-align: unset;
padding: 0;
}

.json-diff-viewer.json-diff-viewer-theme-custom tr td.line-number {
color: #999;
padding: 2px;
}

.json-diff-viewer.json-diff-viewer-theme-custom tr td pre {
Expand All @@ -162,11 +162,23 @@
overflow: hidden;
margin: 0;
font-size: 12px;
min-width: 300px;
line-height: var(--diff-row-height);
white-space: pre-wrap;
word-break: break-all;
}

.json-diff-viewer.json-diff-viewer-theme-custom tr td pre span.inline-diff-add {
background: rgba(0, 0, 0, 0.08);
text-decoration: underline;
word-break: break-all;
}
.json-diff-viewer.json-diff-viewer-theme-custom tr td pre span.inline-diff-remove {
background: rgba(0, 0, 0, 0.08);
text-decoration: line-through;
word-break: break-all;
}

.json-diff-viewer.json-diff-viewer-theme-custom tr:hover {
background: #53535f54;
}
Expand All @@ -191,7 +203,12 @@
padding: 0 4px;
border-left: 0;
border-bottom: none;
}

.json-diff-viewer.json-diff-viewer-theme-custom tr td.line-number {
max-width: 30px;
min-width: 30px;
width: 30px !important;
}

.json-diff-viewer.json-diff-viewer-theme-custom tr.expand-line td {
Expand Down
3 changes: 2 additions & 1 deletion src/components/DiffViewer/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { DifferOptions, DiffResult } from "json-diff-kit";
import type { DifferOptions, DiffResult, InlineDiffOptions } from "json-diff-kit";

export type DiffRow = {
originalIndex: number;
Expand Down Expand Up @@ -44,6 +44,7 @@ export type VirtualizedDiffViewerProps = {
differOptions?: DifferOptions;
className?: string;
miniMapWidth?: number;
inlineDiffOptions?: InlineDiffOptions;
};

export type DiffMinimapProps = {
Expand Down