Diff View
Headless Diff View; covers shadcn/ui, GitHub diff, Ant Design.
| Package | @vizejs/ui/diff-view |
| Maturity | stable |
| Quality gates | behavior contract, mounted dom, type inference, tree shaking, bundle size, ssr, hydration, dom compile, ssr compile, vapor compile |
| Bundle budget | 4,000 B JS gzip / 0 B CSS gzip |
| Own the source | vize lib pull diff-view |
| Requires | — |
| Aliases | diff, patch view, unified diff, code diff |
| Covers | shadcn/ui, GitHub diff, Ant Design |
Minimal setup
Use a Vue 3.5+ project with Vue SFC compilation configured (see Vite+ integration).
vp install @vizejs/ui
Add the public import below to <script setup lang="ts">. Components provide behavior without styles; the preview uses optional Paper styles.
import { DiffView } from "@vizejs/ui/diff-view";
Or copy the source into your project with vize lib pull diff-view (see Source Distribution).
Try it
This is the basic example maintained with the component source, using the public package imports. The preview adds the optional Paper styles.
Open the interactive example · Styling these components
Copy the example
<!-- Unified diff of a readme, with headers kept as metadata. -->
<script setup lang="ts">
import { DiffView } from "@vizejs/ui/diff-view";
const patch = `--- a/readme.md
+++ b/readme.md
@@ -1 +1 @@
-old
+new
`;
</script>
<template>
<DiffView label="readme.md" :patch />
</template>
Show the patch as a table
DiffView parses unified diffs. --- and +++ headers stay metadata, so they
are not reported as deletions or additions. Context lines keep their text
without the leading space. Pass lines when the application already
classified the edit.
<script setup lang="ts">
import { DiffView } from "@vizejs/ui/diff-view";
const patch = `--- a/readme.md
+++ b/readme.md
@@ -1 +1 @@
-old
+new
`;
</script>
<template>
<DiffView label="readme.md" :patch="patch" />
</template>
Rows expose data-kind="context|add|remove|meta". Color belongs to the consumer.
API
DiffView
Source: src/components/diff-view/diff-view.vue
Props
| Prop | Type | Default | Description |
|---|---|---|---|
label |
string |
"Diff" |
Accessible name of the table. |
patch |
string |
"" |
Unified diff text. Ignored when lines is set. |
lines |
readonly DiffLineInput[] |
undefined |
Structured lines. They win over patch. |
Behavior
Normative state × input → outcome table for src/components/diff-view/diff-view.vue.
Every row is proven by src/components/diff-view/tests/behavior.test.ts.
| # | State | Input | Outcome | Proven by |
|---|---|---|---|---|
| F1 | unified patch | parse | headers are meta, space lines are context, + adds, - removes |
parses a unified diff without treating headers as edits |
| F2 | patch prop | render | table named by label; each line is a row whose data-kind matches |
renders a patch as a named table |
| F3 | structured lines | render | lines wins over patch |
prefers structured lines over a patch |
| F4 | empty patch | render | a table with no cells | renders an empty patch as a table without cells |