@@ -13,11 +13,8 @@ import {DragDropRegistry} from '../drag-drop-registry';
13
13
import { moveItemInArray } from '../drag-utils' ;
14
14
import { combineTransforms } from '../dom/styling' ;
15
15
import { 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' ;
21
18
22
19
/**
23
20
* Entry in the position cache for draggable items.
@@ -39,21 +36,19 @@ interface CachedItemPosition<T> {
39
36
* Items are reordered using CSS transforms which allows for sorting to be animated.
40
37
* @docs -private
41
38
*/
42
- export class SingleAxisSortStrategy < T extends DropListSortStrategyItem >
43
- implements DropListSortStrategy < T >
44
- {
39
+ export class SingleAxisSortStrategy implements DropListSortStrategy {
45
40
/** Function used to determine if an item can be sorted into a specific index. */
46
- private _sortPredicate : SortPredicate < T > ;
41
+ private _sortPredicate : SortPredicate < DragRef > ;
47
42
48
43
/** Cache of the dimensions of all the items inside the container. */
49
- private _itemPositions : CachedItemPosition < T > [ ] = [ ] ;
44
+ private _itemPositions : CachedItemPosition < DragRef > [ ] = [ ] ;
50
45
51
46
/**
52
47
* Draggable items that are currently active inside the container. Includes the items
53
48
* that were there at the start of the sequence, as well as any items that have been dragged
54
49
* in, but haven't been dropped yet.
55
50
*/
56
- private _activeDraggables : T [ ] ;
51
+ private _activeDraggables : DragRef [ ] ;
57
52
58
53
/** Direction in which the list is oriented. */
59
54
orientation : 'vertical' | 'horizontal' = 'vertical' ;
@@ -63,7 +58,7 @@ export class SingleAxisSortStrategy<T extends DropListSortStrategyItem>
63
58
64
59
constructor (
65
60
private _element : HTMLElement | ElementRef < HTMLElement > ,
66
- private _dragDropRegistry : DragDropRegistry < T , unknown > ,
61
+ private _dragDropRegistry : DragDropRegistry < DragRef , unknown > ,
67
62
) { }
68
63
69
64
/**
@@ -72,7 +67,7 @@ export class SingleAxisSortStrategy<T extends DropListSortStrategyItem>
72
67
* overlap with the swapped item after the swapping occurred.
73
68
*/
74
69
private _previousSwap = {
75
- drag : null as T | null ,
70
+ drag : null as DragRef | null ,
76
71
delta : 0 ,
77
72
overlaps : false ,
78
73
} ;
@@ -81,7 +76,7 @@ export class SingleAxisSortStrategy<T extends DropListSortStrategyItem>
81
76
* To be called when the drag sequence starts.
82
77
* @param items Items that are currently in the list.
83
78
*/
84
- start ( items : readonly T [ ] ) {
79
+ start ( items : readonly DragRef [ ] ) {
85
80
this . withItems ( items ) ;
86
81
}
87
82
@@ -92,7 +87,7 @@ export class SingleAxisSortStrategy<T extends DropListSortStrategyItem>
92
87
* @param pointerY Position of the item along the Y axis.
93
88
* @param pointerDelta Direction in which the pointer is moving along each axis.
94
89
*/
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 } ) {
96
91
const siblings = this . _itemPositions ;
97
92
const newIndex = this . _getItemIndexFromPointerPosition ( item , pointerX , pointerY , pointerDelta ) ;
98
93
@@ -172,7 +167,7 @@ export class SingleAxisSortStrategy<T extends DropListSortStrategyItem>
172
167
* @param index Index at which the item entered. If omitted, the container will try to figure it
173
168
* out automatically.
174
169
*/
175
- enter ( item : T , pointerX : number , pointerY : number , index ?: number ) : void {
170
+ enter ( item : DragRef , pointerX : number , pointerY : number , index ?: number ) : void {
176
171
const newIndex =
177
172
index == null || index < 0
178
173
? // We use the coordinates of where the item entered the drop
@@ -183,7 +178,7 @@ export class SingleAxisSortStrategy<T extends DropListSortStrategyItem>
183
178
const activeDraggables = this . _activeDraggables ;
184
179
const currentIndex = activeDraggables . indexOf ( item ) ;
185
180
const placeholder = item . getPlaceholderElement ( ) ;
186
- let newPositionReference : T | undefined = activeDraggables [ newIndex ] ;
181
+ let newPositionReference : DragRef | undefined = activeDraggables [ newIndex ] ;
187
182
188
183
// If the item at the new position is the same as the item that is being dragged,
189
184
// 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>
229
224
}
230
225
231
226
/** Sets the items that are currently part of the list. */
232
- withItems ( items : readonly T [ ] ) : void {
227
+ withItems ( items : readonly DragRef [ ] ) : void {
233
228
this . _activeDraggables = items . slice ( ) ;
234
229
this . _cacheItemPositions ( ) ;
235
230
}
236
231
237
232
/** Assigns a sort predicate to the strategy. */
238
- withSortPredicate ( predicate : SortPredicate < T > ) : void {
233
+ withSortPredicate ( predicate : SortPredicate < DragRef > ) : void {
239
234
this . _sortPredicate = predicate ;
240
235
}
241
236
@@ -262,12 +257,12 @@ export class SingleAxisSortStrategy<T extends DropListSortStrategyItem>
262
257
* Gets a snapshot of items currently in the list.
263
258
* Can include items that we dragged in from another list.
264
259
*/
265
- getActiveItemsSnapshot ( ) : readonly T [ ] {
260
+ getActiveItemsSnapshot ( ) : readonly DragRef [ ] {
266
261
return this . _activeDraggables ;
267
262
}
268
263
269
264
/** Gets the index of a specific item. */
270
- getItemIndex ( item : T ) : number {
265
+ getItemIndex ( item : DragRef ) : number {
271
266
// Items are sorted always by top/left in the cache, however they flow differently in RTL.
272
267
// The rest of the logic still stands no matter what orientation we're in, however
273
268
// we need to invert the array when determining the index.
@@ -351,7 +346,7 @@ export class SingleAxisSortStrategy<T extends DropListSortStrategyItem>
351
346
*/
352
347
private _getSiblingOffsetPx (
353
348
currentIndex : number ,
354
- siblings : CachedItemPosition < T > [ ] ,
349
+ siblings : CachedItemPosition < DragRef > [ ] ,
355
350
delta : 1 | - 1 ,
356
351
) {
357
352
const isHorizontal = this . orientation === 'horizontal' ;
@@ -410,7 +405,7 @@ export class SingleAxisSortStrategy<T extends DropListSortStrategyItem>
410
405
* @param delta Direction in which the user is moving their pointer.
411
406
*/
412
407
private _getItemIndexFromPointerPosition (
413
- item : T ,
408
+ item : DragRef ,
414
409
pointerX : number ,
415
410
pointerY : number ,
416
411
delta ?: { x : number ; y : number } ,
0 commit comments