@@ -7,7 +7,12 @@ import {
77 capitalizeTerm ,
88 sourceControlClients ,
99} from "@t3tools/client-runtime/source-control-clients" ;
10- import type { CodeViewItem , DiffLineAnnotation , SelectedLineRange } from "@pierre/diffs" ;
10+ import type {
11+ CodeViewItem ,
12+ DiffLineAnnotation ,
13+ FileDiffMetadata ,
14+ SelectedLineRange ,
15+ } from "@pierre/diffs" ;
1116import type { CodeViewAnnotationArgs , CodeViewDiffItem } from "@pierre/diffs/react" ;
1217import type {
1318 EnvironmentId ,
@@ -20,6 +25,7 @@ import type {
2025 PullRequestReviewThread ,
2126 PullRequestThreadCommentsResult ,
2227} from "@t3tools/contracts" ;
28+ import { SOURCE_CONTROL_MEDIA_ASSET } from "@t3tools/contracts" ;
2329import {
2430 ChevronDownIcon ,
2531 ChevronRightIcon ,
@@ -64,6 +70,7 @@ import {
6470} from "@t3tools/client-runtime/pull-request-editing" ;
6571import { fileDiffRows } from "@t3tools/client-runtime/review-guide-tour" ;
6672import { isTestChangedFile } from "@t3tools/shared/changedFileKind" ;
73+ import { isWorkspaceImagePreviewPath } from "@t3tools/shared/mediaPreview" ;
6774import { orderDiffFiles } from "./pullRequestFileOrder.logic" ;
6875import {
6976 buildFileDiffRenderKey ,
@@ -88,6 +95,7 @@ import { pullRequestEnvironment } from "~/state/pullRequests";
8895import { useEnvironmentQuery } from "~/state/query" ;
8996import { useAtomCommand } from "~/state/use-atom-command" ;
9097
98+ import { ChatMarkdownAssetImage } from "../chat/ChatMarkdownMedia" ;
9199import { DiffPanelLoadingState } from "../DiffPanelShell" ;
92100import { useDiffWorkerPool } from "../DiffWorkerPoolProvider" ;
93101import { DiffCommentAnnotation } from "../diffs/DiffCommentAnnotation" ;
@@ -144,6 +152,7 @@ interface ReviewAnnotationGroup {
144152 readonly threads : ReadonlyArray < PullRequestReviewThread > ;
145153 readonly pending : ReadonlyArray < PendingReviewComment > ;
146154 readonly draft : boolean ;
155+ readonly image ?: { readonly url : string ; readonly path : string } ;
147156}
148157
149158type ReviewAnnotation = DiffLineAnnotation < ReviewAnnotationGroup > ;
@@ -637,6 +646,20 @@ function PullRequestCodeTab({
637646 return placed ;
638647 } ) ( ) ;
639648
649+ const imageRevision = commit ?? detail . headSha ;
650+ const rawFileUrl = sourceControlClients . find ( detail . provider ) ?. rawFileUrl ;
651+ const repositoryUrl = sourceControlClients . parseChangeRequestUrl ( detail . url ) ?. link . repositoryUrl ;
652+ // Hosts send no patch for an image, so its expanded row shows the file at this revision.
653+ const imagePreviewUrl = ( fileDiff : FileDiffMetadata , path : string ) =>
654+ fileDiff . hunks . length === 0 &&
655+ fileDiff . type !== "deleted" &&
656+ isWorkspaceImagePreviewPath ( path ) &&
657+ imageRevision !== undefined &&
658+ rawFileUrl !== undefined &&
659+ repositoryUrl !== undefined
660+ ? rawFileUrl ( { repositoryUrl, sha : imageRevision , path } )
661+ : null ;
662+
640663 const annotatedFiles = files . map ( ( fileDiff ) => {
641664 const fileKey = buildFileDiffRenderKey ( fileDiff ) ;
642665 const path = resolveFileDiffPath ( fileDiff ) ;
@@ -689,6 +712,14 @@ function PullRequestCodeTab({
689712 lineNumber : group . line ,
690713 metadata : { threads : group . threads , pending : group . pending , draft : group . draft } ,
691714 } ) ) ;
715+ const imageUrl = imagePreviewUrl ( fileDiff , path ) ;
716+ if ( imageUrl !== null ) {
717+ annotations . push ( {
718+ side : "additions" ,
719+ lineNumber : 0 ,
720+ metadata : { threads : [ ] , pending : [ ] , draft : false , image : { url : imageUrl , path } } ,
721+ } ) ;
722+ }
692723 return {
693724 fileKey,
694725 path,
@@ -699,7 +730,7 @@ function PullRequestCodeTab({
699730 annotations
700731 . map (
701732 ( { side, lineNumber, metadata } ) =>
702- `${ side } :${ lineNumber } :${ metadata . draft ? "d" : "" } :${ metadata . pending
733+ `${ side } :${ lineNumber } :${ metadata . image ?. url ?? "" } : ${ metadata . draft ? "d" : "" } :${ metadata . pending
703734 . map ( ( comment ) => `${ comment . id } :${ comment . body } ` )
704735 . join ( "," ) } :${ metadata . threads
705736 . map (
@@ -1085,6 +1116,20 @@ function PullRequestCodeTab({
10851116 const renderAnnotation = ( ...[ annotation ] : CodeViewAnnotationArgs < ReviewAnnotationGroup > ) => (
10861117 // Folded resolved conversations alone add no row, so the code reads straight through.
10871118 < div className = "relative font-sans text-foreground has-[>:not([data-resolved-threads])]:py-1" >
1119+ { annotation . metadata . image ? (
1120+ < div className = "flex justify-center p-3" >
1121+ < ChatMarkdownAssetImage
1122+ environmentId = { environmentId }
1123+ resource = { {
1124+ _tag : SOURCE_CONTROL_MEDIA_ASSET ,
1125+ cwd : detail . workspaceRoot ,
1126+ url : annotation . metadata . image . url ,
1127+ repository : detail . repository ,
1128+ } }
1129+ alt = { annotation . metadata . image . path }
1130+ />
1131+ </ div >
1132+ ) : null }
10881133 < InlineReviewThreads threads = { annotation . metadata . threads } renderThread = { renderThreadCard } />
10891134 { annotation . metadata . pending . map ( ( comment ) => (
10901135 < PendingReviewCommentCard
0 commit comments