@@ -81,6 +81,10 @@ import {
8181import { UserMessageContextReferenceChip } from "./UserMessageContextChips" ;
8282import { resolvePreviewAnnotationImage } from "./TimelineUserMessageRow.logic" ;
8383
84+ // Drawn inside the media so dark screenshots keep an edge on the dark background.
85+ const MEDIA_EDGE_CLASS_NAME =
86+ "relative after:pointer-events-none after:absolute after:inset-0 after:z-10 after:rounded-[inherit] after:ring-1 after:ring-inset after:ring-black/9 dark:after:ring-white/12" ;
87+
8488const BUBBLE_CHIP_CLASS_NAME =
8589 "[&_[data-slot=context-chip]]:[--context-chip-ink:var(--context-chip-message,var(--context-chip-accent))]" ;
8690
@@ -327,9 +331,7 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
327331 : null ,
328332 ) ;
329333 const senderLabel = senderShell ?. title . trim ( ) || "Agent" ;
330- const resolvedContext = resolveUserMessageContext (
331- userMessage . attribution === "guest" ? { ...row . message , text : userMessage . text } : row . message ,
332- ) ;
334+ const resolvedContext = resolveUserMessageContext ( { ...row . message , text : userMessage . text } ) ;
333335 const previewImages = userImages . filter ( ( image ) => image . name . startsWith ( "preview-annotation-" ) ) ;
334336 const revertTurnCount = row . revertTurnCount ;
335337 const chippedAttachmentIds = new Set (
@@ -340,6 +342,27 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
340342 ) ;
341343 const regularImages = userImages . filter ( ( image ) => ! image . name . startsWith ( "preview-annotation-" ) ) ;
342344 const unchippedFiles = otherUserFiles . filter ( ( file ) => ! chippedAttachmentIds . has ( file . id ) ) ;
345+ // Images or videos sent without words show as media, not as a bubble around them.
346+ const mediaOnly =
347+ ! folded &&
348+ userMessage . attribution !== "guest" &&
349+ resolvedContext . text . trim ( ) === "" &&
350+ userAudio . length === 0 &&
351+ unchippedFiles . length === 0 &&
352+ unknownAttachments . length === 0 &&
353+ regularImages . length + userVideos . length > 0 ;
354+ // A lone image keeps its own shape; a 4:3 crop hides most of a wide screenshot.
355+ const loneImage =
356+ mediaOnly &&
357+ userVideos . length === 0 &&
358+ regularImages . length === 1 &&
359+ regularImages [ 0 ] ! . source ?. kind !== "snap-shot" ;
360+ // Several images sent without words share one rounded shape, split by hairlines.
361+ const collage =
362+ mediaOnly &&
363+ userVideos . length === 0 &&
364+ regularImages . length > 1 &&
365+ regularImages . every ( ( image ) => image . source ?. kind !== "snap-shot" ) ;
343366 const annotationRecordIds = resolvedContext . records
344367 . filter ( ( record ) => record . kind === "preview-annotation" )
345368 . map ( ( record ) => record . contextId ) ;
@@ -469,8 +492,10 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
469492 className = { cn (
470493 "relative min-w-0 max-w-[80%] rounded-2xl text-message-foreground" ,
471494 BUBBLE_CHIP_CLASS_NAME ,
472- userMessage . attribution === "guest" ? guestBubbleClassName ( false ) : "bg-message" ,
473- ! folded && "p-3" ,
495+ userMessage . attribution === "guest"
496+ ? guestBubbleClassName ( false )
497+ : ! mediaOnly && "bg-message" ,
498+ ! folded && ! mediaOnly && "p-3" ,
474499 folded && expanded && "w-full" ,
475500 ) }
476501 >
@@ -502,15 +527,45 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
502527 ) }
503528 >
504529 { ( regularImages . length > 0 || userVideos . length > 0 ) && (
505- < div className = "mb-2 grid max-w-[210px] grid-cols-2 gap-2" >
506- { regularImages . map ( ( image ) => (
530+ < div
531+ className = { cn (
532+ "grid" ,
533+ ! mediaOnly
534+ ? "mb-2 max-w-[210px] grid-cols-2 gap-2"
535+ : loneImage
536+ ? "max-w-full"
537+ : collage
538+ ? cn (
539+ MEDIA_EDGE_CLASS_NAME ,
540+ "w-80 max-w-full gap-px overflow-hidden rounded-2xl bg-black/9 dark:bg-white/12" ,
541+ regularImages . length === 2
542+ ? "auto-rows-[12rem] grid-cols-2"
543+ : regularImages . length === 3
544+ ? "auto-rows-[calc(6rem-0.5px)] grid-cols-[3fr_2fr]"
545+ : "auto-rows-[6rem] grid-cols-2" ,
546+ )
547+ : "w-80 max-w-full grid-cols-2 gap-2" ,
548+ ) }
549+ >
550+ { regularImages . map ( ( image , index ) => (
507551 < div
508552 key = { image . id }
509553 className = { cn (
510554 "bg-background/70" ,
511555 image . source ?. kind === "snap-shot" && image . previewUrl
512556 ? cn ( SNAP_SHOT_ATTACHMENT_FRAME_CLASS , "col-span-2" )
513- : "aspect-[4/3] overflow-hidden rounded-lg border border-border/80" ,
557+ : loneImage
558+ ? cn ( MEDIA_EDGE_CLASS_NAME , "overflow-hidden rounded-2xl" )
559+ : collage
560+ ? cn (
561+ "overflow-hidden bg-background" ,
562+ regularImages . length === 3 && index === 0 && "row-span-2" ,
563+ regularImages . length > 3 &&
564+ regularImages . length % 2 === 1 &&
565+ index === regularImages . length - 1 &&
566+ "col-span-2" ,
567+ )
568+ : "aspect-[4/3] overflow-hidden rounded-lg border border-border/80" ,
514569 ) }
515570 >
516571 { image . previewUrl ? (
@@ -532,11 +587,23 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
532587 alt = { image . name }
533588 decoding = "async"
534589 loading = "lazy"
535- className = "block size-full transform-gpu object-cover"
590+ className = { cn (
591+ "block transform-gpu" ,
592+ // A fixed height keeps the row from growing when the image loads.
593+ loneImage
594+ ? "h-48 w-auto min-w-24 max-w-full object-cover"
595+ : "size-full object-cover" ,
596+ ) }
536597 />
537598 </ button >
538599 ) : (
539- < div className = "flex min-h-[72px] items-center justify-center px-2 py-3 text-center text-2xs text-muted-foreground/70" >
600+ < div
601+ className = { cn (
602+ "flex min-h-[72px] items-center justify-center px-2 py-3 text-center text-2xs text-muted-foreground/70" ,
603+ loneImage && "h-48 w-64 max-w-full" ,
604+ collage && "h-full" ,
605+ ) }
606+ >
540607 { image . name }
541608 </ div >
542609 ) }
0 commit comments