@@ -13,11 +13,8 @@ import {DragDropRegistry} from '../drag-drop-registry';
1313import { moveItemInArray } from '../drag-utils' ;
1414import { combineTransforms } from '../dom/styling' ;
1515import { adjustDomRect , getMutableClientRect , isInsideClientRect } from '../dom/dom-rect' ;
16- import {
17- DropListSortStrategy ,
18- DropListSortStrategyItem ,
19- SortPredicate ,
20- } from './drop-list-sort-strategy' ;
16+ import { DropListSortStrategy , SortPredicate } from './drop-list-sort-strategy' ;
17+ import type { DragRef } from '../drag-ref' ;
2118
2219/**
2320 * Entry in the position cache for draggable items.
@@ -39,21 +36,19 @@ interface CachedItemPosition<T> {
3936 * Items are reordered using CSS transforms which allows for sorting to be animated.
4037 * @docs -private
4138 */
42- export class SingleAxisSortStrategy < T extends DropListSortStrategyItem >
43- implements DropListSortStrategy < T >
44- {
39+ export class SingleAxisSortStrategy implements DropListSortStrategy {
4540 /** Function used to determine if an item can be sorted into a specific index. */
46- private _sortPredicate : SortPredicate < T > ;
41+ private _sortPredicate : SortPredicate < DragRef > ;
4742
4843 /** Cache of the dimensions of all the items inside the container. */
49- private _itemPositions : CachedItemPosition < T > [ ] = [ ] ;
44+ private _itemPositions : CachedItemPosition < DragRef > [ ] = [ ] ;
5045
5146 /**
5247 * Draggable items that are currently active inside the container. Includes the items
5348 * that were there at the start of the sequence, as well as any items that have been dragged
5449 * in, but haven't been dropped yet.
5550 */
56- private _activeDraggables : T [ ] ;
51+ private _activeDraggables : DragRef [ ] ;
5752
5853 /** Direction in which the list is oriented. */
5954 orientation : 'vertical' | 'horizontal' = 'vertical' ;
@@ -63,7 +58,7 @@ export class SingleAxisSortStrategy<T extends DropListSortStrategyItem>
6358
6459 constructor (
6560 private _element : HTMLElement | ElementRef < HTMLElement > ,
66- private _dragDropRegistry : DragDropRegistry < T , unknown > ,
61+ private _dragDropRegistry : DragDropRegistry < DragRef , unknown > ,
6762 ) { }
6863
6964 /**
@@ -72,7 +67,7 @@ export class SingleAxisSortStrategy<T extends DropListSortStrategyItem>
7267 * overlap with the swapped item after the swapping occurred.
7368 */
7469 private _previousSwap = {
75- drag : null as T | null ,
70+ drag : null as DragRef | null ,
7671 delta : 0 ,
7772 overlaps : false ,
7873 } ;
@@ -81,7 +76,7 @@ export class SingleAxisSortStrategy<T extends DropListSortStrategyItem>
8176 * To be called when the drag sequence starts.
8277 * @param items Items that are currently in the list.
8378 */
84- start ( items : readonly T [ ] ) {
79+ start ( items : readonly DragRef [ ] ) {
8580 this . withItems ( items ) ;
8681 }
8782
@@ -92,7 +87,7 @@ export class SingleAxisSortStrategy<T extends DropListSortStrategyItem>
9287 * @param pointerY Position of the item along the Y axis.
9388 * @param pointerDelta Direction in which the pointer is moving along each axis.
9489 */
95- sort ( item : T , pointerX : number , pointerY : number , pointerDelta : { x : number ; y : number } ) {
90+ sort ( item : DragRef , pointerX : number , pointerY : number , pointerDelta : { x : number ; y : number } ) {
9691 const siblings = this . _itemPositions ;
9792 const newIndex = this . _getItemIndexFromPointerPosition ( item , pointerX , pointerY , pointerDelta ) ;
9893
@@ -172,7 +167,7 @@ export class SingleAxisSortStrategy<T extends DropListSortStrategyItem>
172167 * @param index Index at which the item entered. If omitted, the container will try to figure it
173168 * out automatically.
174169 */
175- enter ( item : T , pointerX : number , pointerY : number , index ?: number ) : void {
170+ enter ( item : DragRef , pointerX : number , pointerY : number , index ?: number ) : void {
176171 const newIndex =
177172 index == null || index < 0
178173 ? // We use the coordinates of where the item entered the drop
@@ -183,7 +178,7 @@ export class SingleAxisSortStrategy<T extends DropListSortStrategyItem>
183178 const activeDraggables = this . _activeDraggables ;
184179 const currentIndex = activeDraggables . indexOf ( item ) ;
185180 const placeholder = item . getPlaceholderElement ( ) ;
186- let newPositionReference : T | undefined = activeDraggables [ newIndex ] ;
181+ let newPositionReference : DragRef | undefined = activeDraggables [ newIndex ] ;
187182
188183 // If the item at the new position is the same as the item that is being dragged,
189184 // it means that we're trying to restore the item to its initial position. In this
@@ -229,13 +224,13 @@ export class SingleAxisSortStrategy<T extends DropListSortStrategyItem>
229224 }
230225
231226 /** Sets the items that are currently part of the list. */
232- withItems ( items : readonly T [ ] ) : void {
227+ withItems ( items : readonly DragRef [ ] ) : void {
233228 this . _activeDraggables = items . slice ( ) ;
234229 this . _cacheItemPositions ( ) ;
235230 }
236231
237232 /** Assigns a sort predicate to the strategy. */
238- withSortPredicate ( predicate : SortPredicate < T > ) : void {
233+ withSortPredicate ( predicate : SortPredicate < DragRef > ) : void {
239234 this . _sortPredicate = predicate ;
240235 }
241236
@@ -262,12 +257,12 @@ export class SingleAxisSortStrategy<T extends DropListSortStrategyItem>
262257 * Gets a snapshot of items currently in the list.
263258 * Can include items that we dragged in from another list.
264259 */
265- getActiveItemsSnapshot ( ) : readonly T [ ] {
260+ getActiveItemsSnapshot ( ) : readonly DragRef [ ] {
266261 return this . _activeDraggables ;
267262 }
268263
269264 /** Gets the index of a specific item. */
270- getItemIndex ( item : T ) : number {
265+ getItemIndex ( item : DragRef ) : number {
271266 // Items are sorted always by top/left in the cache, however they flow differently in RTL.
272267 // The rest of the logic still stands no matter what orientation we're in, however
273268 // we need to invert the array when determining the index.
@@ -351,7 +346,7 @@ export class SingleAxisSortStrategy<T extends DropListSortStrategyItem>
351346 */
352347 private _getSiblingOffsetPx (
353348 currentIndex : number ,
354- siblings : CachedItemPosition < T > [ ] ,
349+ siblings : CachedItemPosition < DragRef > [ ] ,
355350 delta : 1 | - 1 ,
356351 ) {
357352 const isHorizontal = this . orientation === 'horizontal' ;
@@ -410,7 +405,7 @@ export class SingleAxisSortStrategy<T extends DropListSortStrategyItem>
410405 * @param delta Direction in which the user is moving their pointer.
411406 */
412407 private _getItemIndexFromPointerPosition (
413- item : T ,
408+ item : DragRef ,
414409 pointerX : number ,
415410 pointerY : number ,
416411 delta ?: { x : number ; y : number } ,
0 commit comments