Skip to content

DiffViewer ​

A read-only code diff: one file's path, change counts, and hunks in unified or split view, with inline highlighting.

Import ​

ts
import { createDiffFile, DiffViewer, parseUnifiedDiff } from '@astryx-vue/lab'

Props ​

NameTypeDefaultDescription
fileDiffViewerFileRequiredThe file to render. Build it with parseUnifiedDiff or createDiffFile.
viewMode'unified' | 'split''unified'One column, or old and new side by side.
languagestringInferred from the extensionSyntax-highlighting language; unknown extensions render as plain text.
hasLineNumbersbooleantrueShows the old and new line-number gutters.
isWrappedbooleanfalseWraps long lines instead of scrolling sideways.
inlineHighlight'word' | 'char' | 'none''word'Highlights changed words (or characters) inside paired removed/added lines.
isCollapsiblebooleantrueMakes the file header a disclosure; needs a file path to name it.
isCollapsedbooleanUncontrolledControlled collapsed state.
defaultIsCollapsedbooleanfalseInitial collapsed state when uncontrolled.
maxHeightnumber | stringundefinedMaximum height of the hunk area before it scrolls.
syntaxThemeSyntaxThemeDefinitionundefinedPer-instance syntax theme.
labelstring'Diff'Accessible name for the hunk area when the file has no path.
renderLineAnnotation(ref) => VNodeChildundefinedRenders a full-width row under a line, e.g. a review comment; in split view it sits on the line's own side.

Events ​

NamePayloadDescription
collapsedChange(isCollapsed: boolean)The header disclosure was toggled.
update:isCollapsed(isCollapsed: boolean)Supports v-model:isCollapsed.
lineNumberClick(ref: DiffViewerLineRef, event: MouseEvent)A line number was clicked. Only the line's anchor side is a button.

Slots ​

NameDescription
headerEndContent at the end of the file header, e.g. a "Viewed" checkbox.

Utilities ​

ts
const files = parseUnifiedDiff(patch) // one record per file
const file = createDiffFile({
  path: 'src/app.ts',
  oldValue: before,
  newValue: after,
  contextLines: 3,
})

parseUnifiedDiff accepts git diff, diff -u, and bare hunks; unreadable input yields an empty array instead of throwing. createDiffFile computes a Myers line diff from two texts and returns the same DiffViewerFile shape. contextLines defaults to 3; pass oldPath: null or newPath: null to mark a file added or deleted.