1- import { ICollectionObserverSplice , ObserverLocator , OverrideContext , Scope } from 'aurelia-binding' ;
1+ import { ICollectionObserverSplice , InternalCollectionObserver , ObserverLocator , OverrideContext , Scope } from 'aurelia-binding' ;
22import { Container } from 'aurelia-dependency-injection' ;
33import { BoundViewFactory , TargetInstruction , View , ViewResources , ViewSlot } from 'aurelia-templating' ;
4- import { AbstractRepeater , Repeat , RepeatStrategy , RepeatStrategyLocator } from 'aurelia-templating-resources' ;
4+ import { AbstractRepeater , RepeatStrategy } from 'aurelia-templating-resources' ;
55
6- declare class DomHelper {
7- getElementDistanceToTopOfDocument ( element : Element ) : number ;
8- hasOverflowScroll ( element : HTMLElement ) : boolean ;
9- }
106export interface IScrollNextScrollContext {
117 topIndex : number ;
128 isAtBottom : boolean ;
@@ -16,57 +12,122 @@ export interface IVirtualRepeatStrategy extends RepeatStrategy {
1612 /**
1713 * create first item to calculate the heights
1814 */
19- createFirstItem ( repeat : IVirtualRepeat ) : void ;
15+ createFirstItem ( repeat : VirtualRepeat ) : IView ;
2016 /**
21- * Handle the repeat's collection instance changing.
22- * @param repeat The repeater instance.
23- * @param items The new array instance.
24- */
25- instanceChanged ( repeat : IVirtualRepeat , items : Array < any > , ...rest : any [ ] ) : void ;
26- }
27- export interface IVirtualRepeat extends Repeat {
28- items : any [ ] ;
29- itemHeight : number ;
30- strategy : IVirtualRepeatStrategy ;
31- templateStrategy : ITemplateStrategy ;
32- topBuffer : HTMLElement ;
33- bottomBuffer : HTMLElement ;
34- isLastIndex : boolean ;
35- readonly viewFactory : BoundViewFactory ;
17+ * Calculate required variables for a virtual repeat instance to operate properly
18+ *
19+ * @returns `false` to notify that calculation hasn't been finished
20+ */
21+ initCalculation ( repeat : VirtualRepeat , items : number | any [ ] | Map < any , any > | Set < any > ) : VirtualizationCalculation ;
22+ /**
23+ * Get the observer based on collection type of `items`
24+ */
25+ getCollectionObserver ( observerLocator : ObserverLocator , items : any [ ] | Map < any , any > | Set < any > ) : InternalCollectionObserver ;
26+ /**
27+ * @override
28+ * Handle the repeat's collection instance changing.
29+ * @param repeat The repeater instance.
30+ * @param items The new array instance.
31+ * @param firstIndex The index of first active view
32+ */
33+ instanceChanged ( repeat : VirtualRepeat , items : any [ ] | Map < any , any > | Set < any > , firstIndex ?: number ) : void ;
34+ /**
35+ * @override
36+ * Handle the repeat's collection instance mutating.
37+ * @param repeat The virtual repeat instance.
38+ * @param array The modified array.
39+ * @param splices Records of array changes.
40+ */
41+ instanceMutated ( repeat : VirtualRepeat , array : any [ ] , splices : ICollectionObserverSplice [ ] ) : void ;
3642}
3743/**
3844 * Templating strategy to handle virtual repeat views
3945 * Typically related to moving views, creating buffer and locating view range range in the DOM
4046 */
4147export interface ITemplateStrategy {
48+ /**
49+ * Determine the scroll container of a [virtual-repeat] based on its anchor (`element` is a comment node)
50+ */
4251 getScrollContainer ( element : Element ) : HTMLElement ;
52+ /**
53+ * Move root element of a view to first position in the list, after top buffer
54+ * Note: [virtual-repeat] only supports single root node repeat
55+ */
4356 moveViewFirst ( view : View , topBuffer : Element ) : void ;
57+ /**
58+ * Move root element of a view to last position in the list, before bottomBuffer
59+ * Note: [virtual-repeat] only supports single root node repeat
60+ */
4461 moveViewLast ( view : View , bottomBuffer : Element ) : void ;
45- createTopBufferElement ( element : Element ) : HTMLElement ;
46- createBottomBufferElement ( element : Element ) : HTMLElement ;
47- removeBufferElements ( element : Element , topBuffer : Element , bottomBuffer : Element ) : void ;
48- getFirstElement ( topBuffer : Element ) : Element ;
49- getLastElement ( bottomBuffer : Element ) : Element ;
50- getTopBufferDistance ( topBuffer : Element ) : number ;
62+ /**
63+ * Create top and bottom buffer elements for an anchor (`element` is a comment node)
64+ */
65+ createBuffers ( element : Element ) : [ HTMLElement , HTMLElement ] ;
66+ /**
67+ * Clean up buffers of a [virtual-repeat]
68+ */
69+ removeBuffers ( element : Element , topBuffer : Element , bottomBuffer : Element ) : void ;
70+ /**
71+ * Get the first element(or view) between top buffer and bottom buffer
72+ * Note: [virtual-repeat] only supports single root node repeat
73+ */
74+ getFirstElement ( topBufer : Element , botBuffer : Element ) : Element ;
75+ /**
76+ * Get the last element(or view) between top buffer and bottom buffer
77+ * Note: [virtual-repeat] only supports single root node repeat
78+ */
79+ getLastElement ( topBuffer : Element , bottomBuffer : Element ) : Element ;
5180}
5281/**
5382 * Override `bindingContext` and `overrideContext` on `View` interface
5483 */
5584export declare type IView = View & Scope ;
56- declare class VirtualRepeatStrategyLocator extends RepeatStrategyLocator {
85+ /**
86+ * Object with information about current state of a scrollable element
87+ * Capturing:
88+ * - current scroll height
89+ * - current scroll top
90+ * - real height
91+ */
92+ export interface IScrollerInfo {
93+ scroller : HTMLElement ;
94+ scrollHeight : number ;
95+ scrollTop : number ;
96+ height : number ;
97+ }
98+ export declare const enum VirtualizationCalculation {
99+ none = 0 ,
100+ reset = 1 ,
101+ has_sizing = 2 ,
102+ observe_scroller = 4
103+ }
104+ /**
105+ * List of events that can be used to notify virtual repeat that size has changed
106+ */
107+ export declare const VirtualizationEvents : {
108+ scrollerSizeChange : "virtual-repeat-scroller-size-changed" ;
109+ itemSizeChange : "virtual-repeat-item-size-changed" ;
110+ } ;
111+ declare class VirtualRepeatStrategyLocator {
57112 constructor ( ) ;
113+ /**
114+ * Adds a repeat strategy to be located when repeating a template over different collection types.
115+ * @param strategy A repeat strategy that can iterate a specific collection type.
116+ */
117+ addStrategy ( matcher : ( items : any ) => boolean , strategy : IVirtualRepeatStrategy ) : void ;
118+ /**
119+ * Gets the best strategy to handle iteration.
120+ */
58121 getStrategy ( items : any ) : IVirtualRepeatStrategy ;
59122}
60123declare class TemplateStrategyLocator {
61- static inject : ( typeof Container ) [ ] ;
62- container : Container ;
63124 constructor ( container : Container ) ;
64125 /**
65126 * Selects the template strategy based on element hosting `virtual-repeat` custom attribute
66127 */
67128 getStrategy ( element : Element ) : ITemplateStrategy ;
68129}
69- export declare class VirtualRepeat extends AbstractRepeater implements IVirtualRepeat {
130+ export declare class VirtualRepeat extends AbstractRepeater {
70131 key : any ;
71132 value : any ;
72133 /**
@@ -78,23 +139,16 @@ export declare class VirtualRepeat extends AbstractRepeater implements IVirtualR
78139 */
79140 local : string ;
80141 readonly viewFactory : BoundViewFactory ;
81- templateStrategy : ITemplateStrategy ;
82- topBuffer : HTMLElement ;
83- bottomBuffer : HTMLElement ;
84- itemHeight : number ;
85- movedViewsCount : number ;
142+ /**
143+ * Calculate current scrolltop position
144+ */
86145 distanceToTop : number ;
87146 /**
88- * When dealing with tables, there can be gaps between elements, causing distances to be messed up. Might need to handle this case here.
147+ * collection repeating strategy
89148 */
90- topBufferDistance : number ;
91- scrollContainerHeight : number ;
92- isLastIndex : boolean ;
93- elementsInView : number ;
94149 strategy : IVirtualRepeatStrategy ;
95- ignoreMutation : boolean ;
96150 collectionObserver : any ;
97- constructor ( element : HTMLElement , viewFactory : BoundViewFactory , instruction : TargetInstruction , viewSlot : ViewSlot , viewResources : ViewResources , observerLocator : ObserverLocator , strategyLocator : VirtualRepeatStrategyLocator , templateStrategyLocator : TemplateStrategyLocator , domHelper : DomHelper ) ;
151+ constructor ( element : HTMLElement , viewFactory : BoundViewFactory , instruction : TargetInstruction , viewSlot : ViewSlot , viewResources : ViewResources , observerLocator : ObserverLocator , collectionStrategyLocator : VirtualRepeatStrategyLocator , templateStrategyLocator : TemplateStrategyLocator ) ;
98152 /**@override */
99153 bind ( bindingContext : any , overrideContext : OverrideContext ) : void ;
100154 /**@override */
@@ -123,22 +177,32 @@ export declare class VirtualRepeat extends AbstractRepeater implements IVirtualR
123177 handleCollectionMutated ( collection : any [ ] , changes : ICollectionObserverSplice [ ] ) : void ;
124178 /**@override */
125179 handleInnerCollectionMutated ( collection : any [ ] , changes : ICollectionObserverSplice [ ] ) : void ;
180+ /**
181+ * Get the real scroller element of the DOM tree this repeat resides in
182+ */
183+ getScroller ( ) : HTMLElement ;
184+ /**
185+ * Get scrolling information of the real scroller element of the DOM tree this repeat resides in
186+ */
187+ getScrollerInfo ( ) : IScrollerInfo ;
126188 /**@override */
127189 viewCount ( ) : number ;
128190 /**@override */
129191 views ( ) : IView [ ] ;
130192 /**@override */
131- view ( index : number ) : IView ;
193+ view ( index : number ) : IView | null ;
132194 /**@override */
133- addView ( bindingContext : any , overrideContext : OverrideContext ) : void ;
195+ addView ( bindingContext : any , overrideContext : OverrideContext ) : IView ;
134196 /**@override */
135197 insertView ( index : number , bindingContext : any , overrideContext : OverrideContext ) : void ;
136198 /**@override */
137- removeAllViews ( returnToCache : boolean , skipAnimation : boolean ) : void | Promise < any > ;
199+ removeAllViews ( returnToCache : boolean , skipAnimation : boolean ) : void | Promise < void > ;
138200 /**@override */
139- removeView ( index : number , returnToCache : boolean , skipAnimation : boolean ) : View | Promise < View > ;
140- updateBindings ( view : View ) : void ;
201+ removeView ( index : number , returnToCache : boolean , skipAnimation : boolean ) : IView | Promise < IView > ;
202+ updateBindings ( view : IView ) : void ;
141203}
142204export declare class InfiniteScrollNext {
143205}
144- export declare function configure ( config : any ) : void ;
206+ export declare function configure ( config : {
207+ globalResources ( ...args : any [ ] ) : any ;
208+ } ) : void ;
0 commit comments