import { type Component, createMemo, createSignal, onMount } from "solid-js" import { diffLines, type ChangeObject } from "diff" import CodeBlock from "./CodeBlock" import styles from "./diffview.module.css" type DiffRow = { left: string right: string type: "added" | "removed" | "unchanged" } interface DiffViewProps { changes: ChangeObject[] lang?: string class?: string } const DiffView: Component = (props) => { const rows = createMemo(() => { const diffRows: DiffRow[] = [] for (const item of props.changes) { const lines = item.value.split(/\r?\n/) if (lines.at(-1) === "") lines.pop() for (const line of lines) { diffRows.push({ left: item.removed ? line : item.added ? "" : line, right: item.added ? line : item.removed ? "" : line, type: item.added ? "added" : item.removed ? "removed" : "unchanged", }) } } return diffRows }) return (
{rows().map((r) => ( ))}
{rows().map((r) => ( ))}
) } export default DiffView