@@ -12,9 +12,29 @@ interface UseFloatBoundarySyncProps {
1212const CONTENT_WINDOW_GAP = 8
1313
1414/**
15- * Hook to synchronize floats position with layout boundary changes.
16- * Keeps the float within bounds when sidebar, panel, or terminal resize.
17- * Uses requestAnimationFrame for smooth real-time updates
15+ * Layout dimensions a float must stay clear of. During a resize drag the live
16+ * value is an inline override on the consuming element (a scoped style recalc);
17+ * at rest it lives on `:root` (committed via the store / pre-hydration script).
18+ * Each entry pairs the element the drag writes to with its variable so the
19+ * float tracks the drag live and re-clamps at rest.
20+ */
21+ const BOUNDARY_DIMENSIONS = [
22+ { selector : '.sidebar-shell-outer' , cssVar : '--sidebar-width' } ,
23+ { selector : '.panel-container' , cssVar : '--panel-width' } ,
24+ { selector : '.terminal-container' , cssVar : '--terminal-height' } ,
25+ ] as const
26+
27+ /** Reads a boundary dimension, preferring the drag's scoped inline override. */
28+ function readBoundaryDimension ( selector : string , cssVar : string ) : number {
29+ const inline = document . querySelector < HTMLElement > ( selector ) ?. style . getPropertyValue ( cssVar )
30+ const value = inline || getComputedStyle ( document . documentElement ) . getPropertyValue ( cssVar )
31+ return Number . parseInt ( value || '0' )
32+ }
33+
34+ /**
35+ * Hook to synchronize a float's position with layout boundary changes.
36+ * Keeps the float within bounds when the sidebar, panel, or terminal resize.
37+ * Uses requestAnimationFrame for smooth real-time updates.
1838 */
1939export function useFloatBoundarySync ( {
2040 isOpen,
@@ -30,15 +50,9 @@ export function useFloatBoundarySync({
3050 positionRef . current = position
3151
3252 const checkAndUpdatePosition = useCallback ( ( ) => {
33- const sidebarWidth = Number . parseInt (
34- getComputedStyle ( document . documentElement ) . getPropertyValue ( '--sidebar-width' ) || '0'
35- )
36- const panelWidth = Number . parseInt (
37- getComputedStyle ( document . documentElement ) . getPropertyValue ( '--panel-width' ) || '0'
38- )
39- const terminalHeight = Number . parseInt (
40- getComputedStyle ( document . documentElement ) . getPropertyValue ( '--terminal-height' ) || '0'
41- )
53+ const sidebarWidth = readBoundaryDimension ( '.sidebar-shell-outer' , '--sidebar-width' )
54+ const panelWidth = readBoundaryDimension ( '.panel-container' , '--panel-width' )
55+ const terminalHeight = readBoundaryDimension ( '.terminal-container' , '--terminal-height' )
4256
4357 const prev = previousDimensionsRef . current
4458 if (
@@ -83,11 +97,17 @@ export function useFloatBoundarySync({
8397
8498 window . addEventListener ( 'resize' , handleResize )
8599
100+ /**
101+ * Watch both `:root` (at-rest commits, the pre-hydration script) and each
102+ * container the resize hooks write to mid-drag, so the float re-clamps live
103+ * throughout a drag rather than only on release.
104+ */
86105 const observer = new MutationObserver ( handleResize )
87- observer . observe ( document . documentElement , {
88- attributes : true ,
89- attributeFilter : [ 'style' ] ,
90- } )
106+ observer . observe ( document . documentElement , { attributes : true , attributeFilter : [ 'style' ] } )
107+ for ( const { selector } of BOUNDARY_DIMENSIONS ) {
108+ const el = document . querySelector ( selector )
109+ if ( el ) observer . observe ( el , { attributes : true , attributeFilter : [ 'style' ] } )
110+ }
91111
92112 checkAndUpdatePosition ( )
93113
0 commit comments