Render diffs and code, now with edit
@pierre/diffs is an open source diff and code rendering library. Rich syntax highlighting, edit mode, support for custom and Shiki themes, virtualization, and more. Made by The Pierre Computer Company.
Currently v1.7.2
Edit diffs and code
Enable edit mode in any File or FileDiff component with the EditProvider. Includes support for selection management, auto-indention, undo history, find-in-file, lint markers, and more. Pairs nicely with @pierre/trees for AUI style experiences. Learn more about edit mode.
16 unmodified lines1718192021222122232425 unmodified lines505152535654555657615859606165 unmodified lines12712812913013513113213313813413514013613713813914017 unmodified lines15815916016116616716816216316416516616716816917017117217317917417517617767 unmodified lines24524624724825525625725825924925025126126226325225325425525617 unmodified lines27427527627728927827928028128225 unmodified lines30830931031132331231331431531649 unmodified lines3663673683693813703713723733 unmodified lines16 unmodified lines getSessionGitStatus, getSessionPaths,} from './mockData';
export type ThemeType = 'light' | 'dark';
// The editor's stylesheet flattens every line number to one neutral colour// (`--diffs-editor-line-number-fg`) and is injected as an unlayered <style>,// so it overrides the library's per-line colouring (which lives in @layer// base). We adopt this extra, higher-specificity unlayered sheet into the25 unmodified lines// component, so it's created in an effect and torn down on session change.function ChangesTree({ session, activePath, themeType, onSelect,}: { session: AuiSession; activePath: string | null; themeType: ThemeType; onSelect: (path: string) => void;}) { const containerRef = useRef<HTMLDivElement | null>(null); const treeRef = useRef<FileTree | null>(null);65 unmodified lines }; }, [session]);
// Inline color-scheme beats the tree's `:host { color-scheme: light dark }`, // flipping its light-dark() colours with our toggle. // pinning its light-dark() colours to the demo's dark mode. useEffect(() => { if (containerRef.current != null) { containerRef.current.style.colorScheme = themeType; containerRef.current.style.colorScheme = 'dark'; } }, [themeType, session]); }, [session]);
// Keep the highlighted row matched to the active file. useEffect(() => { const tree = treeRef.current;17 unmodified lines return <div ref={containerRef} className="aui-tree" />;}
export interface AgentUiProps { // Theme is controlled by the parent so the toggle can live outside the // component (the homepage section renders its own button group). themeType: ThemeType; // Highlight themes the surrounding worker pool was initialized with. Defaults // to the shared homepage pool's themes. theme?: { dark: string; light: string }; // Server-rendered diff HTML keyed by file path. When present the matching // FileDiff hydrates from this markup (already syntax-highlighted) instead of // waiting on the client worker, which also avoids an SSR/client mismatch. prerenderedDiffs?: Record<string, string>;}
// The demo is always dark: the snapshot is prerendered dark and matching it// avoids theme flashing, so there is no light/dark toggle.export function AgentUi({ themeType, theme = DEFAULT_THEMES, prerenderedDiffs,}: AgentUiProps) { const session = AUI_SESSIONS[0];67 unmodified lines : null, [activeFile, editKey