@@ -45,13 +45,42 @@ export class VirtualList extends HTMLElement {
4545
4646 #loadElements( ) {
4747 const height = this . offsetHeight ;
48+ const visibleRange = this . #sizeManager. getVisibleRange ( 0 , height ) ;
49+ const totalHeight = this . #sizeManager. totalSize ;
50+
51+ if ( height <= totalHeight ) {
52+ this . #createElements( visibleRange ) ;
53+ }
54+ }
55+
56+ #createElements( visibleRange ) {
57+ const fragment = document . createDocumentFragment ( ) ;
58+ const { start, end } = visibleRange ;
59+
60+ for ( let i = start ; i <= end ; i ++ ) {
61+ const item = this . #data[ i ] ;
62+ const element = this . #template. content . cloneNode ( true ) ;
63+ this . #inflateFn( element , item ) ;
64+ fragment . appendChild ( element ) ;
65+ }
66+
67+ const container = this . shadowRoot . querySelector ( "#container" ) ;
68+ container . innerHTML = "" ;
69+ container . appendChild ( fragment ) ;
4870 }
4971
5072 /**
5173 * Method to update the list items.
5274 * @param {Array } items - The list items to display.
5375 */
54- async load ( items , template , height , inflateFn ) {
76+ async load ( items , template , height , inflateFn , styles = [ ] ) {
77+ for ( const style of styles ) {
78+ const link = document . createElement ( "link" ) ;
79+ link . rel = "stylesheet" ;
80+ link . href = style ;
81+ this . shadowRoot . appendChild ( link ) ;
82+ }
83+
5584 this . #template = template ;
5685 this . #inflateFn = inflateFn ;
5786
0 commit comments