1- import { Component , Listen , h , Host , State , Prop , Event , EventEmitter } from '@stencil/core' ;
1+ import { Component , Listen , h , Host , State , Prop , Event , EventEmitter , Element , Watch } from '@stencil/core' ;
22
33import { ItemReorderEventDetail } from '@ionic/core' ;
44
@@ -13,6 +13,8 @@ import {SlideUtils} from '../../../../utils/editor/slide.utils';
1313 styleUrl : 'app-slides-aside.scss'
1414} )
1515export class AppSlidesAside {
16+ @Element ( ) el : HTMLElement ;
17+
1618 @State ( )
1719 private slides : HTMLElement [ ] = [ ] ;
1820
@@ -22,6 +24,9 @@ export class AppSlidesAside {
2224 @Prop ( )
2325 deckRef ! : HTMLDeckgoDeckElement ;
2426
27+ private hostRef ! : HTMLAppSlidesAsideElement ;
28+ private asideRef ! : HTMLElement ;
29+
2530 @Event ( )
2631 private reorder : EventEmitter < ItemReorderEventDetail > ;
2732
@@ -56,6 +61,20 @@ export class AppSlidesAside {
5661 } , 250 ) ;
5762 }
5863
64+ @Watch ( 'activeIndex' )
65+ onActiveIndexChange ( ) {
66+ const nextThumbnail : HTMLElement | null = this . el . querySelector ( `app-slide-thumbnail:nth-child(${ this . activeIndex + 1 } )` ) ;
67+
68+ const rect : DOMRect | undefined = nextThumbnail ?. getBoundingClientRect ( ) ;
69+
70+ if ( rect ?. top > this . hostRef ?. scrollHeight || rect ?. top < this . hostRef ?. scrollTop ) {
71+ this . asideRef ?. scrollTo ( {
72+ top : rect . top ,
73+ behavior : 'smooth'
74+ } ) ;
75+ }
76+ }
77+
5978 @Listen ( 'deckDidLoad' , { target : 'document' } )
6079 onDeckDidLoad ( ) {
6180 this . debounceUpdateAllSlides ( ) ;
@@ -170,7 +189,7 @@ export class AppSlidesAside {
170189
171190 render ( ) {
172191 return (
173- < Host >
192+ < Host ref = { ( el ) => ( this . hostRef = el as HTMLAppSlidesAsideElement ) } >
174193 { this . renderSlides ( ) }
175194
176195 { this . renderActions ( ) }
@@ -181,6 +200,7 @@ export class AppSlidesAside {
181200 private renderSlides ( ) {
182201 return (
183202 < aside
203+ ref = { ( el ) => ( this . asideRef = el as HTMLElement ) }
184204 onDrop = { ( ) => this . onDrop ( ) }
185205 onDragOver = { ( $event : DragEvent ) => $event . preventDefault ( ) }
186206 onDragLeave = { ( ) => this . onDragLeave ( ) }
0 commit comments