| ... | ... | @@ -19,99 +19,59 @@ import { DiffStatLabel, hasNonZeroStat } from "./DiffStatLabel"; |
| 19 | 19 | import { PierreEntryIcon } from "./PierreEntryIcon"; |
| 20 | 20 | import { Button } from "../ui/button"; |
| 21 | 21 | import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip"; |
| 22 | | import { |
| 23 | | changedFileName, |
| 24 | | selectChangedFilePreview, |
| 25 | | summarizeChangedFileScopes, |
| 26 | | } from "./changedFilesPresentation"; |
| 27 | 22 | |
| 28 | 23 | const EMPTY_DIRECTORY_OVERRIDES: Record<string, boolean> = {}; |
| 29 | 24 | |
| 30 | 25 | export const ChangedFilesCard = memo(function ChangedFilesCard(props: { |
| 31 | 26 | turnId: TurnId; |
| 32 | 27 | files: ReadonlyArray<TurnDiffFileChange>; |
| 33 | | expanded: boolean; |
| 34 | | showCompactPreview: boolean; |
| 35 | 28 | allDirectoriesExpanded: boolean; |
| 36 | 29 | resolvedTheme: "light" | "dark"; |
| 37 | | onExpandedChange: (expanded: boolean) => void; |
| 38 | 30 | onToggleAllDirectories: () => void; |
| 39 | 31 | onOpenTurnDiff: (turnId: TurnId, filePath?: string) => void; |
| 40 | 32 | }) { |
| 41 | 33 | const { |
| 42 | 34 | turnId, |
| 43 | 35 | files, |
| 44 | | expanded, |
| 45 | | showCompactPreview, |
| 46 | 36 | allDirectoriesExpanded, |
| 47 | 37 | resolvedTheme, |
| 48 | | onExpandedChange, |
| 49 | 38 | onToggleAllDirectories, |
| 50 | 39 | onOpenTurnDiff, |
| 51 | 40 | } = props; |
| 52 | 41 | const summaryStat = useMemo(() => summarizeTurnDiffStats(files), [files]); |
| 53 | | const scopeSummary = useMemo(() => summarizeChangedFileScopes(files), [files]); |
| 54 | | const previewFiles = useMemo(() => selectChangedFilePreview(files), [files]); |
| 55 | | const compactPreviewVisible = showCompactPreview && !expanded; |
| 42 | const hasDirectories = files.some((file) => /[/\\]/.test(file.path)); |
| 56 | 43 | |
| 57 | 44 | return ( |
| 58 | 45 | <div |
| 59 | | className="@container/changed-files mt-4 rounded-2xl border border-border/70 bg-secondary p-2 dark:border-transparent dark:bg-input/32" |
| 60 | | data-changed-files-state={ |
| 61 | | expanded ? "expanded" : compactPreviewVisible ? "preview" : "collapsed" |
| 62 | | } |
| 46 | className="@container/changed-files mt-4 rounded-lg bg-secondary dark:bg-input/20" |
| 47 | data-changed-files-state="tree" |
| 63 | 48 | > |
| 64 | 49 | <div |
| 65 | 50 | data-changed-files-header="" |
| 66 | | className={cn( |
| 67 | | "flex items-center justify-between gap-2 rounded-xl", |
| 68 | | expanded && |
| 69 | | "sticky top-2 z-10 mb-2 bg-secondary dark:bg-[color-mix(in_srgb,var(--contrast-foreground)_2.5%,var(--background))]", |
| 70 | | )} |
| 51 | className="sticky top-2 z-10 flex items-center justify-between gap-2 rounded-t-lg bg-secondary px-3 py-2 dark:bg-[color-mix(in_srgb,var(--input)_20%,var(--background))]" |
| 71 | 52 | > |
| 72 | | <button |
| 73 | | type="button" |
| 74 | | aria-expanded={expanded} |
| 75 | | data-scroll-anchor-ignore |
| 76 | | className="group flex min-w-0 flex-1 items-center rounded-xl px-2 py-1.5 text-left transition-colors hover:bg-accent/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring" |
| 77 | | onClick={() => onExpandedChange(!expanded)} |
| 78 | | > |
| 79 | | <span className="flex min-w-0 flex-1 items-center gap-1.5 overflow-hidden"> |
| 80 | | <ChevronRightIcon |
| 81 | | aria-hidden="true" |
| 82 | | className={cn( |
| 83 | | "size-3.5 shrink-0 text-muted-foreground transition-transform", |
| 84 | | expanded && "rotate-90", |
| 85 | | )} |
| 86 | | /> |
| 87 | | <span className="flex shrink-0 items-center gap-1 whitespace-nowrap font-medium text-foreground text-xs leading-4"> |
| 88 | | <span> |
| 89 | | {files.length} changed file{files.length === 1 ? "" : "s"} |
| 90 | | </span> |
| 91 | | {hasNonZeroStat(summaryStat) && ( |
| 92 | | <DiffStatLabel |
| 93 | | additions={summaryStat.additions} |
| 94 | | className="text-xs leading-4" |
| 95 | | deletions={summaryStat.deletions} |
| 96 | | layout="inline" |
| 97 | | /> |
| 98 | | )} |
| 99 | | </span> |
| 100 | | <span className="ml-1 hidden min-w-0 flex-1 truncate text-[11px] text-muted-foreground group-hover:text-foreground/80 @[24rem]/changed-files:inline"> |
| 101 | | {expanded ? "Hide files" : "Show files"} |
| 102 | | </span> |
| 53 | <div className="flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1 text-xs font-medium text-foreground"> |
| 54 | <span> |
| 55 | {files.length} changed file{files.length === 1 ? "" : "s"} |
| 103 | 56 | </span> |
| 104 | | </button> |
| 105 | | <div className="flex shrink-0 items-center gap-1.5 pr-1"> |
| 106 | | {expanded ? ( |
| 57 | {hasNonZeroStat(summaryStat) && ( |
| 58 | <DiffStatLabel |
| 59 | additions={summaryStat.additions} |
| 60 | deletions={summaryStat.deletions} |
| 61 | layout="inline" |
| 62 | className="text-xs leading-4" |
| 63 | /> |
| 64 | )} |
| 65 | </div> |
| 66 | <div className="flex shrink-0 items-center gap-1"> |
| 67 | {hasDirectories && ( |
| 107 | 68 | <Tooltip> |
| 108 | 69 | <TooltipTrigger |
| 109 | 70 | render={ |
| 110 | 71 | <Button |
| 111 | 72 | type="button" |
| 112 | 73 | size="icon-xs" |
| 113 | | variant="outline" |
| 114 | | className="!size-[22px]" |
| 74 | variant="ghost-muted" |
| 115 | 75 | aria-label={ |
| 116 | 76 | allDirectoriesExpanded ? "Collapse all folders" : "Expand all folders" |
| 117 | 77 | } |
| ... | ... | @@ -130,14 +90,14 @@ export const ChangedFilesCard = memo(function ChangedFilesCard(props: { |
| 130 | 90 | {allDirectoriesExpanded ? "Collapse all folders" : "Expand all folders"} |
| 131 | 91 | </TooltipPopup> |
| 132 | 92 | </Tooltip> |
| 133 | | ) : null} |
| 93 | )} |
| 134 | 94 | <Tooltip> |
| 135 | 95 | <TooltipTrigger |
| 136 | 96 | render={ |
| 137 | 97 | <Button |
| 138 | 98 | type="button" |
| 139 | 99 | size="xs" |
| 140 | | variant="outline" |
| 100 | variant="ghost-muted" |
| 141 | 101 | aria-label="Open diff" |
| 142 | 102 | onClick={() => onOpenTurnDiff(turnId, files[0]?.path)} |
| 143 | 103 | /> |
| ... | ... | @@ -150,61 +110,14 @@ export const ChangedFilesCard = memo(function ChangedFilesCard(props: { |
| 150 | 110 | </Tooltip> |
| 151 | 111 | </div> |
| 152 | 112 | </div> |
| 153 | | {expanded ? ( |
| 154 | | <ChangedFilesTree |
| 155 | | key={`changed-files-tree:${turnId}`} |
| 156 | | turnId={turnId} |
| 157 | | files={files} |
| 158 | | allDirectoriesExpanded={allDirectoriesExpanded} |
| 159 | | resolvedTheme={resolvedTheme} |
| 160 | | onOpenTurnDiff={onOpenTurnDiff} |
| 161 | | /> |
| 162 | | ) : compactPreviewVisible ? ( |
| 163 | | <div className="px-2 pb-1.5 pt-1"> |
| 164 | | <p className="flex flex-wrap items-center gap-x-1.5 gap-y-0.5 text-[11px] text-muted-foreground"> |
| 165 | | {scopeSummary.map((scope, index) => ( |
| 166 | | <span key={scope.label} className="inline-flex items-center gap-1"> |
| 167 | | {index > 0 ? <span aria-hidden="true">·</span> : null} |
| 168 | | <span className="font-mono text-foreground/75">{scope.label}</span> |
| 169 | | <span> |
| 170 | | {scope.fileCount} file{scope.fileCount === 1 ? "" : "s"} |
| 171 | | </span> |
| 172 | | </span> |
| 173 | | ))} |
| 174 | | </p> |
| 175 | | <div className="mt-2 flex flex-wrap items-center gap-1.5"> |
| 176 | | {previewFiles.map((file) => ( |
| 177 | | <Tooltip key={file.path}> |
| 178 | | <TooltipTrigger |
| 179 | | render={ |
| 180 | | <button |
| 181 | | type="button" |
| 182 | | className="inline-flex max-w-48 items-center gap-1 rounded-md border border-border/70 bg-background/45 px-1.5 py-1 font-mono text-[10px] text-muted-foreground transition-colors hover:bg-accent/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring" |
| 183 | | onClick={() => onOpenTurnDiff(turnId, file.path)} |
| 184 | | /> |
| 185 | | } |
| 186 | | > |
| 187 | | <PierreEntryIcon |
| 188 | | pathValue={file.path} |
| 189 | | kind="file" |
| 190 | | theme={resolvedTheme} |
| 191 | | className="size-3 shrink-0 text-muted-foreground/70" |
| 192 | | /> |
| 193 | | <span className="truncate">{changedFileName(file.path)}</span> |
| 194 | | </TooltipTrigger> |
| 195 | | <TooltipPopup side="top">{file.path}</TooltipPopup> |
| 196 | | </Tooltip> |
| 197 | | ))} |
| 198 | | <button |
| 199 | | type="button" |
| 200 | | className="rounded-md px-1.5 py-1 text-[11px] font-medium text-muted-foreground transition-colors hover:bg-accent/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring" |
| 201 | | onClick={() => onExpandedChange(true)} |
| 202 | | > |
| 203 | | Show all {files.length} files |
| 204 | | </button> |
| 205 | | </div> |
| 206 | | </div> |
| 207 | | ) : null} |
| 113 | <ChangedFilesTree |
| 114 | key={`${turnId}:${allDirectoriesExpanded}`} |
| 115 | turnId={turnId} |
| 116 | files={files} |
| 117 | allDirectoriesExpanded={allDirectoriesExpanded} |
| 118 | resolvedTheme={resolvedTheme} |
| 119 | onOpenTurnDiff={onOpenTurnDiff} |
| 120 | /> |
| 208 | 121 | </div> |
| 209 | 122 | ); |
| 210 | 123 | }); |
| ... | ... | @@ -261,7 +174,8 @@ export const ChangedFilesTree = memo(function ChangedFilesTree(props: { |
| 261 | 174 | <button |
| 262 | 175 | type="button" |
| 263 | 176 | data-scroll-anchor-ignore |
| 264 | | className="group flex w-full items-center gap-1.5 rounded-xl py-1 pr-3 text-left transition-colors hover:bg-accent/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background" |
| 177 | aria-expanded={isExpanded} |
| 178 | className="group flex w-full items-center gap-2 rounded-md py-1.5 pr-2 text-left transition-colors hover:bg-accent/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background" |
| 265 | 179 | style={{ paddingLeft: `${leftPadding}px` }} |
| 266 | 180 | onClick={() => toggleDirectory(node.path)} |
| 267 | 181 | > |
| ... | ... | @@ -287,9 +201,7 @@ export const ChangedFilesTree = memo(function ChangedFilesTree(props: { |
| 287 | 201 | )} |
| 288 | 202 | </button> |
| 289 | 203 | {isExpanded && ( |
| 290 | | <div className="space-y-0.5"> |
| 291 | | {node.children.map((childNode) => renderTreeNode(childNode, depth + 1))} |
| 292 | | </div> |
| 204 | <div>{node.children.map((childNode) => renderTreeNode(childNode, depth + 1))}</div> |
| 293 | 205 | )} |
| 294 | 206 | </div> |
| 295 | 207 | ); |
| ... | ... | @@ -299,7 +211,7 @@ export const ChangedFilesTree = memo(function ChangedFilesTree(props: { |
| 299 | 211 | <button |
| 300 | 212 | key={`file:${node.path}`} |
| 301 | 213 | type="button" |
| 302 | | className="group flex w-full items-center gap-1.5 rounded-xl py-1 pr-3 text-left transition-colors hover:bg-accent/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background" |
| 214 | className="group flex w-full items-center gap-2 rounded-md py-1.5 pr-2 text-left transition-colors hover:bg-accent/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background" |
| 303 | 215 | style={{ paddingLeft: `${leftPadding}px` }} |
| 304 | 216 | onClick={() => onOpenTurnDiff(turnId, node.path)} |
| 305 | 217 | > |
| ... | ... | @@ -312,7 +224,7 @@ export const ChangedFilesTree = memo(function ChangedFilesTree(props: { |
| 312 | 224 | theme={resolvedTheme} |
| 313 | 225 | className="size-3.5 text-muted-foreground/70" |
| 314 | 226 | /> |
| 315 | | <span className="truncate font-mono text-[11px] text-muted-foreground/80 group-hover:text-foreground/90"> |
| 227 | <span className="truncate font-mono text-xs text-foreground/85 group-hover:text-foreground"> |
| 316 | 228 | {node.name} |
| 317 | 229 | </span> |
| 318 | 230 | {node.stat && ( |
| ... | ... | @@ -324,7 +236,7 @@ export const ChangedFilesTree = memo(function ChangedFilesTree(props: { |
| 324 | 236 | ); |
| 325 | 237 | }; |
| 326 | 238 | |
| 327 | | return <div className="space-y-0.5">{treeNodes.map((node) => renderTreeNode(node, 0))}</div>; |
| 239 | return <div className="p-2">{treeNodes.map((node) => renderTreeNode(node, 0))}</div>; |
| 328 | 240 | }); |
| 329 | 241 | |
| 330 | 242 | function collectDirectoryPaths(nodes: ReadonlyArray<TurnDiffTreeNode>): string[] { |