@@ -35,9 +35,11 @@ import type { DeviceScreenSize } from "../device/deviceStream";
3535import { previewBridge } from "./previewBridge" ;
3636import {
3737 clampPreviewMiniPlayerPosition ,
38+ NO_PREVIEW_MINI_PLAYER_OBSTACLES ,
3839 PREVIEW_MINI_PLAYER_CORNER_RADIUS ,
3940 PREVIEW_MINI_PLAYER_WEBVIEW_Z_INDEX ,
4041 type PreviewMiniPlayerFrame ,
42+ type PreviewMiniPlayerObstacles ,
4143 resizePreviewMiniPlayer ,
4244 resolveDeviceMiniPlayerCornerRadius ,
4345 resolveDeviceMiniPlayerSourceSize ,
@@ -56,7 +58,49 @@ interface PointerGesture {
5658interface Props {
5759 readonly threadRef : ScopedThreadRef ;
5860 readonly miniPlayer : PreviewMiniPlayerState ;
59- readonly bottomInset : number ;
61+ /** The docked composer overlay; null while the composer floats mid-screen. */
62+ readonly composerOverlayElement : HTMLElement | null ;
63+ }
64+
65+ interface Layout {
66+ readonly container : PreviewMiniPlayerSize ;
67+ readonly obstacles : PreviewMiniPlayerObstacles ;
68+ }
69+
70+ const sameLayout = ( a : Layout , b : Layout ) =>
71+ a . container . width === b . container . width &&
72+ a . container . height === b . container . height &&
73+ ( a . obstacles . composer === b . obstacles . composer ||
74+ ( a . obstacles . composer !== null &&
75+ b . obstacles . composer !== null &&
76+ a . obstacles . composer . left === b . obstacles . composer . left &&
77+ a . obstacles . composer . right === b . obstacles . composer . right &&
78+ a . obstacles . composer . height === b . obstacles . composer . height ) ) ;
79+
80+ /**
81+ * Measures the chat column and the composer in the column's coordinates. The
82+ * composer's columns come from its centered stack, not the full-width overlay,
83+ * so the margins beside it stay open to the player.
84+ */
85+ function measureLayout ( container : HTMLElement , composerOverlay : HTMLElement | null ) : Layout {
86+ const containerRect = container . getBoundingClientRect ( ) ;
87+ const stackRect = composerOverlay
88+ ?. querySelector ( '[data-chat-composer-stack="true"]' )
89+ ?. getBoundingClientRect ( ) ;
90+ const overlayRect = composerOverlay ?. getBoundingClientRect ( ) ;
91+ return {
92+ container : { width : container . clientWidth , height : container . clientHeight } ,
93+ obstacles : {
94+ composer :
95+ overlayRect && stackRect && overlayRect . height > 0
96+ ? {
97+ left : Math . floor ( stackRect . left - containerRect . left ) ,
98+ right : Math . ceil ( stackRect . right - containerRect . left ) ,
99+ height : Math . ceil ( overlayRect . height ) ,
100+ }
101+ : null ,
102+ } ,
103+ } ;
60104}
61105
62106const frameCornerRadius = ( ) => PREVIEW_MINI_PLAYER_CORNER_RADIUS ;
@@ -77,23 +121,23 @@ const RESIZE_HANDLES: ReadonlyArray<{
77121] ;
78122
79123/** Floats the thread's browser tab or device stream over chat. */
80- export function ThreadPreviewMiniPlayer ( { threadRef, miniPlayer, bottomInset } : Props ) {
124+ export function ThreadPreviewMiniPlayer ( { threadRef, miniPlayer, composerOverlayElement } : Props ) {
81125 const { source } = miniPlayer ;
82126 return source . kind === "browser" ? (
83127 < BrowserMiniPlayer
84128 key = { source . tabId }
85129 threadRef = { threadRef }
86130 tabId = { source . tabId }
87131 miniPlayer = { miniPlayer }
88- bottomInset = { bottomInset }
132+ composerOverlayElement = { composerOverlayElement }
89133 />
90134 ) : (
91135 < DeviceMiniPlayer
92136 key = { previewMiniPlayerSourceKey ( source ) }
93137 threadRef = { threadRef }
94138 source = { source }
95139 miniPlayer = { miniPlayer }
96- bottomInset = { bottomInset }
140+ composerOverlayElement = { composerOverlayElement }
97141 />
98142 ) ;
99143}
@@ -102,7 +146,7 @@ function BrowserMiniPlayer({
102146 threadRef,
103147 tabId,
104148 miniPlayer,
105- bottomInset ,
149+ composerOverlayElement ,
106150} : Props & { readonly tabId : string } ) {
107151 const previewState = useThreadPreviewState ( threadRef ) ;
108152 const snapshot = previewState . sessions [ tabId ] ?? null ;
@@ -143,7 +187,7 @@ function BrowserMiniPlayer({
143187 threadRef = { threadRef }
144188 miniPlayer = { miniPlayer }
145189 sourceSize = { sourceSize }
146- bottomInset = { bottomInset }
190+ composerOverlayElement = { composerOverlayElement }
147191 label = "Floating browser preview"
148192 onOpenInPanel = { openInPanel }
149193 pillActions = {
@@ -200,7 +244,7 @@ function DeviceMiniPlayer({
200244 threadRef,
201245 source,
202246 miniPlayer,
203- bottomInset ,
247+ composerOverlayElement ,
204248} : Props & { readonly source : Extract < PreviewMiniPlayerSource , { kind : "device" } > } ) {
205249 const { state : deviceState } = useDeviceState ( threadRef . environmentId ) ;
206250 const [ screen , setScreen ] = useState < DeviceScreenSize | null > ( null ) ;
@@ -230,7 +274,7 @@ function DeviceMiniPlayer({
230274 threadRef = { threadRef }
231275 miniPlayer = { miniPlayer }
232276 sourceSize = { sourceSize }
233- bottomInset = { bottomInset }
277+ composerOverlayElement = { composerOverlayElement }
234278 label = "Floating device preview"
235279 onOpenInPanel = { openInPanel }
236280 cornerRadius = { cornerRadius }
@@ -266,7 +310,7 @@ function MiniPlayerShell({
266310 threadRef,
267311 miniPlayer,
268312 sourceSize,
269- bottomInset ,
313+ composerOverlayElement ,
270314 label,
271315 onOpenInPanel,
272316 pillActions,
@@ -276,7 +320,7 @@ function MiniPlayerShell({
276320 readonly threadRef : ScopedThreadRef ;
277321 readonly miniPlayer : PreviewMiniPlayerState ;
278322 readonly sourceSize : PreviewMiniPlayerSize ;
279- readonly bottomInset : number ;
323+ readonly composerOverlayElement : HTMLElement | null ;
280324 readonly label : string ;
281325 readonly onOpenInPanel : ( ) => void ;
282326 readonly pillActions ?: ReactNode ;
@@ -286,15 +330,17 @@ function MiniPlayerShell({
286330} ) {
287331 const containerRef = useRef < HTMLDivElement | null > ( null ) ;
288332 const gestureRef = useRef < PointerGesture | null > ( null ) ;
289- const [ container , setContainer ] = useState < PreviewMiniPlayerSize | null > ( null ) ;
333+ const [ layout , setLayout ] = useState < Layout | null > ( null ) ;
334+ const container = layout ?. container ?? null ;
335+ const obstacles = layout ?. obstacles ?? NO_PREVIEW_MINI_PLAYER_OBSTACLES ;
290336 const sourceKey = previewMiniPlayerSourceKey ( miniPlayer . source ) ;
291337 const frame = container
292338 ? resolvePreviewMiniPlayerFrame ( {
293339 width : miniPlayer . width ,
294340 position : miniPlayer . position ,
295341 source : sourceSize ,
296342 container,
297- bottomInset ,
343+ obstacles ,
298344 } )
299345 : null ;
300346
@@ -306,22 +352,21 @@ function MiniPlayerShell({
306352 usePreviewMiniPlayerStore . getState ( ) . close ( threadRef ) ;
307353 } ;
308354
355+ // The composer grows on its own (drafts, banners), so it is observed alongside the column.
309356 useLayoutEffect ( ( ) => {
310357 const element = containerRef . current ;
311358 if ( ! element ) return ;
312359 const measure = ( ) => {
313- setContainer ( ( current ) =>
314- current ?. width === element . clientWidth && current . height === element . clientHeight
315- ? current
316- : { width : element . clientWidth , height : element . clientHeight } ,
317- ) ;
360+ const next = measureLayout ( element , composerOverlayElement ) ;
361+ setLayout ( ( current ) => ( current && sameLayout ( current , next ) ? current : next ) ) ;
318362 } ;
319363 measure ( ) ;
320364 if ( typeof ResizeObserver === "undefined" ) return ;
321365 const observer = new ResizeObserver ( measure ) ;
322366 observer . observe ( element ) ;
367+ if ( composerOverlayElement ) observer . observe ( composerOverlayElement ) ;
323368 return ( ) => observer . disconnect ( ) ;
324- } , [ ] ) ;
369+ } , [ composerOverlayElement ] ) ;
325370
326371 const beginGesture = (
327372 event : ReactPointerEvent < HTMLElement > ,
@@ -353,7 +398,7 @@ function MiniPlayerShell({
353398 { x : gesture . frame . x + delta . x , y : gesture . frame . y + delta . y } ,
354399 container ,
355400 gesture . frame ,
356- bottomInset ,
401+ obstacles ,
357402 ) ,
358403 ) ;
359404 return ;
@@ -364,7 +409,7 @@ function MiniPlayerShell({
364409 delta,
365410 source : sourceSize ,
366411 container,
367- bottomInset ,
412+ obstacles ,
368413 } ) ;
369414 store . resize ( threadRef , sourceKey , next . width ) ;
370415 store . move ( threadRef , sourceKey , { x : next . x , y : next . y } ) ;
0 commit comments