Diff

Diff views for lit-material: line diff of two texts (unified or side by side), a list of changes by path, and a three-way merge view.

  • 4.7 KB gzipped
  • @lit-material/diff 0.0.0
  • Renders on the server

Example

Install

npm install @lit-material/diff @lit-material/tokens
import "@lit-material/diff";

Link @lit-material/tokens/css/index.css once per page for the colour, type and shape tokens. Install guide

API

<lit-material-change-list>

A list of changes by path: what was added, removed or changed, with the old and new values. For structured data (JSON fields, headers, settings) where a line diff would be noise.

Properties

PropertyAttributeTypeDefaultDescription
changeschangesChange[][]The changes, in the order to show them.
labellabelstring"Changes"Accessible name of the list.

CSS parts

PartDescription
listThe <ul>.
itemEach change.
pathThe path of each change.

<lit-material-diff>

Shows how one text changed into another, line by line: one column with + and - lines (unified), or the two texts side by side (split).

Properties

PropertyAttributeTypeDefaultDescription
originaloriginalstring""The text before the change.
modifiedmodifiedstring""The text after the change.
modemodeDiffMode"unified"unified (one column) or split (side by side).
contextcontextnumber3Unchanged lines kept around each change; -1 keeps every line.
labellabelstring"Changes"Accessible name of the table, such as "Changes to config.yaml".
originalLabeloriginal-labelstring"Before"Column heading for the original side.
modifiedLabelmodified-labelstring"After"Column heading for the modified side.
hideStatshide-statsbooleanfalseHides the added and removed counts.
diffproperty onlyDiffLine[]noneThe diff as lines, for code that wants it without rendering.

CSS parts

PartDescription
tableThe table of lines.
statsThe added and removed counts.

CSS custom properties

PropertyDescription
--lit-material-diff-added-backgroundBackground of added lines.
--lit-material-diff-added-colorText colour of added lines.
--lit-material-diff-removed-backgroundBackground of removed lines.
--lit-material-diff-removed-colorText colour of removed lines.
--lit-material-diff-fontFont of the lines (a monospace stack).
--lit-material-diff-max-heightHeight after which the lines scroll (default none).

<lit-material-merge-view>

Two or more versions of one text side by side, each compared with a common base: lines a version added or changed are highlighted, and lines it dropped are counted. For sync conflicts and three-way merges ("mine", "theirs", "before both changes").

Properties

PropertyAttributeTypeDefaultDescription
sidessidesMergeSide[][]The versions, each with a label and its text.
basebasenumber0Index of the side the others are compared with.

Slots

SlotDescription
side-0Actions under the first side's heading; side-1, side-2 and so on for the others.

CSS parts

PartDescription
sideEach column.
headingEach column's heading.
linesEach column's lines.

CSS custom properties

PropertyDescription
--lit-material-diff-max-heightHeight after which each column scrolls (default 24rem).

Source on GitHub npm