@@ -27,6 +27,7 @@ import { TimelineTrackRow } from "./TimelineTrackRow";
2727import { isTimelineClipActive } from "./useTimelineActiveClips" ;
2828import { queryTimelineClipIndex } from "../lib/timelineClipIndex" ;
2929import { getTimelineElementIdentity } from "../lib/timelineElementHelpers" ;
30+ import { useTimelineLogicalRows } from "./useTimelineLogicalRows" ;
3031
3132interface TimelineLanesProps extends TimelineLaneBaseProps {
3233 /** Live-derived by TimelineCanvas from {@link TimelineLaneBaseProps.draggedClip}. */
@@ -99,14 +100,19 @@ export function TimelineLanes({
99100 onRazorSplit,
100101 onRazorSplitAll,
101102} : TimelineLanesProps ) {
102- // Per-INSTANCE, so two timelines on one page (a mini-timeline in a modal
103- // beside the main one) cannot both mint `...-track-0` and have every caret's
104- // aria-controls resolve to whichever mounted first. React's useId embeds
105- // colons, which are legal in an id and in aria-controls but need escaping in
106- // a CSS `#id` selector, so they come out here and the prefix stays plain.
103+ // One stable id namespace per timeline instance links sticky headers to canvas lanes.
107104 const lanesIdPrefix = `timeline-lanes${ useId ( ) . replaceAll ( ":" , "" ) } ` ;
108105 const expandedClipIds = usePlayerStore ( ( s ) => s . expandedClipIds ) ;
109106 const toggleClipExpanded = usePlayerStore ( ( s ) => s . toggleClipExpanded ) ;
107+ const { logicalRows, logicalRowsByTrack } = useTimelineLogicalRows ( {
108+ tracks,
109+ displayTrackOrder,
110+ laneCounts,
111+ selectedElementId,
112+ selectedElementIds,
113+ expandedClipIds,
114+ gsapAnimations,
115+ } ) ;
110116 const toggleClipExpandedTracked = ( key : string ) => {
111117 const willExpand = ! expandedClipIds . has ( key ) ;
112118 trackStudioKeyframeLaneExpand ( { expanded : willExpand } ) ;
@@ -130,8 +136,10 @@ export function TimelineLanes({
130136 : [ ] ;
131137 return (
132138 < div
133- role = "list "
139+ role = "treegrid "
134140 aria-label = "Timeline tracks"
141+ aria-multiselectable = "true"
142+ aria-rowcount = { logicalRows . length }
135143 className = { rowsVirtualized ? "absolute inset-0" : undefined }
136144 >
137145 {
@@ -140,6 +148,9 @@ export function TimelineLanes({
140148 const trackNum = displayTrackOrder [ row ] ;
141149 if ( trackNum === undefined ) return null ;
142150 const displayNumber = trackDisplayNumber ( displayTrackOrder , trackNum ) ;
151+ const trackLogicalRows = logicalRowsByTrack . get ( trackNum ) ?? [ ] ;
152+ const logicalRow = trackLogicalRows [ 0 ] ;
153+ if ( ! logicalRow ) return null ;
143154 const rowHeight = rowGeometry . getRowHeight ( row ) ;
144155 const els = tracks . find ( ( [ t ] ) => t === trackNum ) ?. [ 1 ] ?? [ ] ;
145156 const renderElements = rowsVirtualized
@@ -156,19 +167,15 @@ export function TimelineLanes({
156167 draggedClip ?. started === true && ! trackOrder . includes ( trackNum ) && els . length === 0 ;
157168 // All lanes use the same uniform color — no alternating stripes.
158169 const rowBackground = theme . rowBackground ;
159- // The beat-dot strip occupies the top of this track's lane (active track,
160- // or the music track when nothing is selected). When shown, keyframe
161- // diamonds shrink + drop to the bottom half so they don't collide with it.
170+ // Keep diamonds below the beat strip on the active/music track.
162171 const beatStripOnTrack =
163172 ( beatAnalysis ?. beatTimes ?. length ?? 0 ) >= 2 &&
164173 ( selectedElementId
165174 ? els . some ( ( e ) => ( e . key ?? e . id ) === selectedElementId )
166175 : els . some ( isMusicTrack ) ) ;
167176 const isTrackHidden = els . length > 0 && els . every ( ( element ) => element . hidden === true ) ;
168177 const isAudioTrack = els . length > 0 && els . some ( isAudioTimelineElement ) ;
169- // The one keyframed element this track shows lanes for (selected, else
170- // most lanes). A track can hold several elements; scoping to one keeps
171- // their keyframes from cramming into a single row.
178+ // Only the selected/most-keyframed clip owns expanded lanes on a shared track.
172179 const keyframeClip = resolveTrackKeyframeClip (
173180 els ,
174181 laneCounts ,
@@ -178,17 +185,15 @@ export function TimelineLanes({
178185 const keyframeClipKey = keyframeClip ?. key ?? keyframeClip ?. id ;
179186 const keyframeClipExpanded =
180187 keyframeClipKey != null && expandedClipIds . has ( keyframeClipKey ) ;
181- // Minted here because this is the only place that sees BOTH ends of
182- // the disclosure: the caret in the sticky header and the diamond lanes
183- // on the canvas. Keyed by display row, not by `trackNum`, which is a
184- // fractional sort key and would mint ids like `...-0.16666666666666666`.
188+ // Link the sticky caret to the canvas lanes with a stable display-row id.
185189 const lanesId = `${ lanesIdPrefix } -track-${ row } ` ;
186190 return (
187191 < TimelineTrackRow
188192 key = { rowKey }
189193 index = { row }
190194 rowKey = { rowKey }
191- rowCount = { displayTrackOrder . length }
195+ logicalRow = { logicalRow }
196+ propertyRows = { trackLogicalRows . slice ( 1 ) }
192197 top = { rowGeometry . getRowTop ( row ) }
193198 height = { rowHeight }
194199 virtualized = { rowsVirtualized }
@@ -226,6 +231,7 @@ export function TimelineLanes({
226231 onSeek = { onSeek }
227232 />
228233 < div
234+ role = "gridcell"
229235 style = { {
230236 width : trackContentWidth ,
231237 marginLeft : contentGutter , // room for a 0% diamond left of t=0
@@ -502,12 +508,8 @@ export function TimelineLanes({
502508 ) }
503509 </ TimelineClip >
504510 ) ;
505- // Mounted for the track's keyframe clip in BOTH disclosure
506- // states, so the header caret's aria-controls resolves while
507- // collapsed too; collapsed just feeds it no animations, so
508- // the wrapper renders empty. The key is stable across a
509- // multi-drag: without it the passenger branch below remounts
510- // this subtree and interrupts the gesture.
511+ // Keep this shell mounted while collapsed so aria-controls stays valid
512+ // and multi-drag cannot remount the subtree mid-gesture.
511513 const propertyLanes = isTrackKeyframeClip && (
512514 < TimelinePropertyLanes
513515 key = { `${ clipKey } -property-lanes` }
@@ -544,10 +546,7 @@ export function TimelineLanes({
544546 suppressClickRef = { suppressClickRef }
545547 />
546548 ) ;
547- // Keep one keyed top-level child per element. Returning an
548- // array here makes React reconcile the outer array by
549- // position, so a window shift remounts otherwise stable
550- // clip keys and can tear down focus mid-reveal.
549+ // One keyed child prevents window shifts from remounting focused clips.
551550 if ( ! isPassenger ) {
552551 return (
553552 < Fragment key = { clipKey } >
0 commit comments