diff-view.tsx
This file
Path
apps/web/src/features/code/diff-view.tsx
71 lines · 2.4 KiB · TypeScript
Last changed by
Draw text, controls, prose and code from one set of tokensoscabrielbefore adoption60f862e
History of this fileTake it
Merge branch 'build/904-web-code-browser'oscabrielbefore adoption06e2229
lines 1–16why, one step back1/**2 * A commit's changes, drawn by `@pierre/diffs`: one `MultiFileDiff` per3 * changed file, stacked, each from the file's old and new text, unified4 * unless `split`. (Pierre's virtualized `CodeView` draws nothing until it5 * mounts, so it cannot be seen rendered outside a browser; the stacked6 * views can, and a commit's diff is capped at 300 files.) A binary7 * file, or one whose text the platform did not send, says so in a line.8 * Each view's section is the file tree's jump target (`diffAnchor`).9 *10 * Only the browser loads this module (`client-code.tsx`).11 */12import { MultiFileDiff } from "@pierre/diffs/react";13import type { FileDiffOptions } from "@pierre/diffs/react";14import type { ChangedFile } from "@repo/protocol/domain/code";1516import { diffAnchor } from "./paths.ts";Draw text, controls, prose and code from one set of tokensoscabrielbefore adoption60f862e
line 17why, one step back17import { diffsOptions, registerCodeTheme } from "./pierre.ts";Merge branch 'build/904-web-code-browser'oscabrielbefore adoption06e2229
line 18why, one step back18Draw text, controls, prose and code from one set of tokensoscabrielbefore adoption60f862e
lines 19–20why, one step back19registerCodeTheme();20Merge branch 'build/904-web-code-browser'oscabrielbefore adoption06e2229
line 21why, one step back21const optionsFor = (split: boolean): FileDiffOptions<undefined, undefined> => ({Draw text, controls, prose and code from one set of tokensoscabrielbefore adoption60f862e
line 22why, one step back22 ...diffsOptions,Merge branch 'build/904-web-code-browser'oscabrielbefore adoption06e2229
lines 23–56why, one step back23 diffStyle: split ? "split" : "unified",24 overflow: "wrap",25});2627export interface DiffCodeProps {28 readonly files: readonly ChangedFile[];29 readonly split: boolean;30}3132/** Whether the platform sent the text of both sides it has. */33const drawable = (file: ChangedFile) =>34 !file.binary && (file.oldText !== undefined || file.newText !== undefined);3536export const DiffCode = ({ files, split }: DiffCodeProps) => {37 const options = optionsFor(split);3839 return (40 <div className="flex min-w-0 flex-col gap-4" data-diff="pierre">41 {files.map((file) =>42 drawable(file) ? (43 <section44 aria-label={file.path}45 id={diffAnchor(file.path)}46 key={file.path}47 >48 <MultiFileDiff49 newFile={{ contents: file.newText ?? "", name: file.path }}50 oldFile={{ contents: file.oldText ?? "", name: file.path }}51 options={options}52 />53 </section>54 ) : (55 <section56 aria-label={file.path}Draw text, controls, prose and code from one set of tokensoscabrielbefore adoption60f862e
line 57why, one step back57 className="border-rule text-mono border border-dashed px-4 py-3 font-mono"Merge branch 'build/904-web-code-browser'oscabrielbefore adoption06e2229
lines 58–71why, one step back58 id={diffAnchor(file.path)}59 key={file.path}60 >61 {file.path}: {file.binary ? "a binary file" : "not shown"},{" "}62 {file.status}63 </section>64 )65 )}66 </div>67 );68};6970// `React.lazy` takes a module's default export.71export default DiffCode;