import { useMemo } from "react"; import { collapseUnchanged, diffStats, lineDiff } from "../../editor/embeds/line-diff"; interface CodeDiffProps { before: string; after: string; beforeLabel: string; afterLabel: string; } export function CodeDiff({ before, after, beforeLabel, afterLabel }: CodeDiffProps) { const lines = useMemo(() => lineDiff(before, after), [before, after]); if (!lines) { return

These versions are too large to compare line by line.

; } const { added, removed } = diffStats(lines); const shown = collapseUnchanged(lines); return (

{beforeLabel} to {afterLabel}: +{added}{" "} -{removed} lines

{added === 0 && removed === 0 ? (

No difference.

) : (
          {shown.map((l, i) =>
            l.type === "skip" ? (
              
... {l.count} unchanged line{l.count === 1 ? "" : "s"}
) : (
{l.text || " "}
), )}
)}
); }