Widgets
DiffView
A diff of two texts: unified and side by side, word by word.
A diff of two texts: unified and side by side, with word-level highlighting inside a line. Changes are gathered into hunks with context rather than shown against the whole file.
Installation
npx @toimetdev/pathlogs-ui add diff-viewExample
greet.ts+2−3
@@ -1,5 +1,4 @@
1−export function greet(name) {
2− const msg = "Привет, " + name;
3− console.log(msg);
1+export function greet(name: string) {
2+ const msg = `Привет, ${name}!`;
43 return msg;
54 }
<DiffView before={before} after={after} mode="unified" filename="greet.ts" />Switch to «Split» and changed lines line up opposite one another.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
before / after* | string | — | The original and changed text. |
mode | "unified" | "split" | "unified" | Unified, or two columns. |
inline | boolean | true | Highlight changes within a line, word by word. |
collapse | boolean | true | Collapse unchanged parts, keeping context (unified). |
context | number | 3 | How many context lines around changes. |
filename | string | — | The heading above the diff. |
before / after*stringThe original and changed text.
mode"unified" | "split"defaults to: "unified"
Unified, or two columns.
inlinebooleandefaults to: true
Highlight changes within a line, word by word.
collapsebooleandefaults to: true
Collapse unchanged parts, keeping context (unified).
contextnumberdefaults to: 3
How many context lines around changes.
filenamestringThe heading above the diff.
Word-level diffing
The algorithm, separately
import {
diffLines, // line diff (LCS with common edges trimmed)
diffWords, // in-line diff by words
buildHunks, // gathering changes into hunks with context
pairRows, // laying out two columns
} from "@/components/ui/diff-view/diffModel";