11const motionTiming = { duration : 150 , easing : "ease-out" } ;
2+ // Rows normally ride their displaced neighbour's travel. Absent a moving
3+ // neighbour, a row still travels on its own, clamped so a tall card does not
4+ // slide its full height.
5+ const rowTravel = ( height : number ) => Math . min ( height , 40 ) ;
26// A project filter change or a bulk snooze swaps a large part of the list at
37// once. Fades are the expensive part: every removed row gets a deep clone and
48// every clone and entering row gets its own animation, and the layout reads
@@ -39,7 +43,7 @@ export function createSidebarListMotion(parent: HTMLUListElement) {
3943 entering . clear ( ) ;
4044 exiting . clear ( ) ;
4145 } ;
42- const fadeOut = ( node : HTMLElement , position : RowPosition ) => {
46+ const fadeOut = ( node : HTMLElement , position : RowPosition , travel : number ) => {
4347 if ( position . height === 0 ) return ;
4448 // React owns the removed row; only a noninteractive copy stays for the fade.
4549 const clone = node . cloneNode ( true ) as HTMLElement ;
@@ -72,8 +76,12 @@ export function createSidebarListMotion(parent: HTMLUListElement) {
7276 } ) ;
7377 parent . append ( clone ) ;
7478 const entry = entering . get ( node ) ;
79+ const entryProgress = entry ? progress ( entry ) : 1 ;
7580 const animation = clone . animate (
76- [ { opacity : entry ? progress ( entry ) : 1 } , { opacity : 0 } ] ,
81+ [
82+ { opacity : entryProgress , transform : "translateY(0px)" } ,
83+ { opacity : 0 , transform : `translateY(${ travel } px)` } ,
84+ ] ,
7785 motionTiming ,
7886 ) ;
7987 exiting . set ( clone , animation ) ;
@@ -146,25 +154,59 @@ export function createSidebarListMotion(parent: HTMLUListElement) {
146154 fadeCount <= MAX_FADED_ROWS_PER_UPDATE ;
147155 if ( ! shouldAnimate ) clearFades ( ) ;
148156 else {
157+ // A shelf that opens above its collapsed anchor shifts every retained
158+ // row by the same amount. Entering rows take that same displacement so
159+ // the shelf arrives as one moving block instead of rows popping into
160+ // their final slots; exiting rows leave by it.
161+ const movedDelta = new Map < HTMLElement , number > ( ) ;
162+ for ( const [ node , position ] of next ) {
163+ const previousTop = positions ! . get ( node ) ?. top ;
164+ if ( previousTop === undefined || previousTop === position . top ) continue ;
165+ movedDelta . set ( node , previousTop + remainingOffset ( node ) - position . top ) ;
166+ }
167+ const nextOrder = [ ...next . keys ( ) ] ;
168+ const oldOrder = [ ...positions ! . keys ( ) ] ;
169+ const ridingDelta = (
170+ order : readonly HTMLElement [ ] ,
171+ index : number ,
172+ retained : ( node : HTMLElement ) => boolean ,
173+ ) => {
174+ for ( let cursor = index - 1 ; cursor >= 0 ; cursor -- ) {
175+ const node = order [ cursor ] ! ;
176+ const delta = movedDelta . get ( node ) ;
177+ if ( delta !== undefined ) return delta ;
178+ if ( retained ( node ) ) return 0 ;
179+ }
180+ return undefined ;
181+ } ;
149182 for ( const [ node , position ] of positions ! ) {
150- if ( ! next . has ( node ) ) fadeOut ( node , position ) ;
183+ if ( next . has ( node ) ) continue ;
184+ const delta = ridingDelta ( oldOrder , oldOrder . indexOf ( node ) , ( n ) => next . has ( n ) ) ;
185+ fadeOut ( node , position , delta === undefined ? rowTravel ( position . height ) : - delta ) ;
151186 }
152- }
153- for ( const [ node , animation ] of entering ) {
154- if ( ! next . has ( node ) ) {
155- animation . cancel ( ) ;
156- entering . delete ( node ) ;
187+ for ( const [ node , animation ] of entering ) {
188+ if ( ! next . has ( node ) ) {
189+ animation . cancel ( ) ;
190+ entering . delete ( node ) ;
191+ }
157192 }
158- }
159- for ( const node of running . keys ( ) ) {
160- if ( ! shouldAnimate || ! next . has ( node ) ) cancel ( node ) ;
161- }
162- if ( shouldAnimate ) {
163- for ( const [ node , position ] of next ) {
164- const previousTop = positions ?. get ( node ) ?. top ;
193+ for ( const node of running . keys ( ) ) {
194+ if ( ! shouldAnimate || ! next . has ( node ) ) cancel ( node ) ;
195+ }
196+ for ( const [ index , node ] of nextOrder . entries ( ) ) {
197+ const position = next . get ( node ) ! ;
198+ const previousTop = positions ! . get ( node ) ?. top ;
165199 if ( previousTop === undefined ) {
166200 if ( position . height > 0 ) {
167- const animation = node . animate ( [ { opacity : 0 } , { opacity : 1 } ] , motionTiming ) ;
201+ const delta = ridingDelta ( nextOrder , index , ( n ) => positions ! . has ( n ) ) ;
202+ const travel = delta === undefined ? - rowTravel ( position . height ) : delta ;
203+ const animation = node . animate (
204+ [
205+ { opacity : 0 , transform : `translateY(${ travel } px)` } ,
206+ { opacity : 1 , transform : "translateY(0px)" } ,
207+ ] ,
208+ motionTiming ,
209+ ) ;
168210 entering . set ( node , animation ) ;
169211 animation . addEventListener (
170212 "finish" ,
@@ -176,10 +218,10 @@ export function createSidebarListMotion(parent: HTMLUListElement) {
176218 }
177219 continue ;
178220 }
179- if ( previousTop === position . top ) continue ;
221+ const delta = movedDelta . get ( node ) ;
180222 // Computed progress includes the effect's easing. Only our own
181223 // translate is carried forward; dnd-kit's transforms are never read.
182- move ( node , previousTop + remainingOffset ( node ) - position . top ) ;
224+ if ( delta !== undefined ) move ( node , delta ) ;
183225 }
184226 }
185227 if ( released !== null ) {
0 commit comments