@@ -26,6 +26,7 @@ import {DragDropRegistry} from './drag-drop-registry';
2626import { CdkDragDrop , CdkDragEnter , CdkDragExit } from './drag-events' ;
2727import { moveItemInArray } from './drag-utils' ;
2828import { CDK_DROP_LIST_CONTAINER } from './drop-list-container' ;
29+ import { CdkDropListGroup } from './drop-list-group' ;
2930
3031
3132/** Counter used to generate unique ids for drop zones. */
@@ -104,21 +105,30 @@ export class CdkDropList<T = any> implements OnInit, OnDestroy {
104105 constructor (
105106 public element : ElementRef < HTMLElement > ,
106107 private _dragDropRegistry : DragDropRegistry < CdkDrag , CdkDropList < T > > ,
107- @Optional ( ) private _dir ?: Directionality ) { }
108+ @Optional ( ) private _dir ?: Directionality ,
109+ @Optional ( ) private _group ?: CdkDropListGroup < CdkDropList > ) { }
108110
109111 ngOnInit ( ) {
110112 this . _dragDropRegistry . registerDropContainer ( this ) ;
113+
114+ if ( this . _group ) {
115+ this . _group . _items . add ( this ) ;
116+ }
111117 }
112118
113119 ngOnDestroy ( ) {
114120 this . _dragDropRegistry . removeDropContainer ( this ) ;
121+
122+ if ( this . _group ) {
123+ this . _group . _items . delete ( this ) ;
124+ }
115125 }
116126
117127 /** Whether an item in the container is being dragged. */
118128 _dragging = false ;
119129
120130 /** Cache of the dimensions of all the items and the sibling containers. */
121- private _positionCache = {
131+ private readonly _positionCache = {
122132 items : [ ] as { drag : CdkDrag , clientRect : ClientRect , offset : number } [ ] ,
123133 siblings : [ ] as { drop : CdkDropList , clientRect : ClientRect } [ ] ,
124134 self : { } as ClientRect
@@ -333,6 +343,8 @@ export class CdkDropList<T = any> implements OnInit, OnDestroy {
333343 /** Refreshes the position cache of the items and sibling containers. */
334344 private _cachePositions ( ) {
335345 const isHorizontal = this . orientation === 'horizontal' ;
346+
347+ this . _positionCache . self = this . element . nativeElement . getBoundingClientRect ( ) ;
336348 this . _positionCache . items = this . _activeDraggables
337349 . map ( drag => {
338350 const elementToMeasure = this . _dragDropRegistry . isDragging ( drag ) ?
@@ -364,12 +376,10 @@ export class CdkDropList<T = any> implements OnInit, OnDestroy {
364376 a . clientRect . top - b . clientRect . top ;
365377 } ) ;
366378
367- this . _positionCache . siblings = coerceArray ( this . connectedTo )
368- . map ( drop => typeof drop === 'string' ? this . _dragDropRegistry . getDropContainer ( drop ) ! : drop )
369- . filter ( drop => drop && drop !== this )
370- . map ( drop => ( { drop, clientRect : drop . element . nativeElement . getBoundingClientRect ( ) } ) ) ;
371-
372- this . _positionCache . self = this . element . nativeElement . getBoundingClientRect ( ) ;
379+ this . _positionCache . siblings = this . _getConnectedLists ( ) . map ( drop => ( {
380+ drop,
381+ clientRect : drop . element . nativeElement . getBoundingClientRect ( )
382+ } ) ) ;
373383 }
374384
375385 /** Resets the container to its initial state. */
@@ -449,6 +459,23 @@ export class CdkDropList<T = any> implements OnInit, OnDestroy {
449459 return pointerY > top - yThreshold && pointerY < bottom + yThreshold &&
450460 pointerX > left - xThreshold && pointerX < right + xThreshold ;
451461 }
462+
463+ /** Gets an array of unique drop lists that the current list is connected to. */
464+ private _getConnectedLists ( ) : CdkDropList [ ] {
465+ const siblings = coerceArray ( this . connectedTo ) . map ( drop => {
466+ return typeof drop === 'string' ? this . _dragDropRegistry . getDropContainer ( drop ) ! : drop ;
467+ } ) ;
468+
469+ if ( this . _group ) {
470+ this . _group . _items . forEach ( drop => {
471+ if ( siblings . indexOf ( drop ) === - 1 ) {
472+ siblings . push ( drop ) ;
473+ }
474+ } ) ;
475+ }
476+
477+ return siblings . filter ( drop => drop && drop !== this ) ;
478+ }
452479}
453480
454481
0 commit comments