@@ -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. */
@@ -141,14 +142,23 @@ export class CdkDropList<T = any> implements OnInit, OnDestroy {
141142 constructor (
142143 public element : ElementRef < HTMLElement > ,
143144 private _dragDropRegistry : DragDropRegistry < CdkDrag , CdkDropList < T > > ,
144- @Optional ( ) private _dir ?: Directionality ) { }
145+ @Optional ( ) private _dir ?: Directionality ,
146+ @Optional ( ) private _group ?: CdkDropListGroup < CdkDropList > ) { }
145147
146148 ngOnInit ( ) {
147149 this . _dragDropRegistry . registerDropContainer ( this ) ;
150+
151+ if ( this . _group ) {
152+ this . _group . _items . add ( this ) ;
153+ }
148154 }
149155
150156 ngOnDestroy ( ) {
151157 this . _dragDropRegistry . removeDropContainer ( this ) ;
158+
159+ if ( this . _group ) {
160+ this . _group . _items . delete ( this ) ;
161+ }
152162 }
153163
154164 /** Whether an item in the container is being dragged. */
@@ -364,6 +374,8 @@ export class CdkDropList<T = any> implements OnInit, OnDestroy {
364374 /** Refreshes the position cache of the items and sibling containers. */
365375 private _cachePositions ( ) {
366376 const isHorizontal = this . orientation === 'horizontal' ;
377+
378+ this . _positionCache . self = this . element . nativeElement . getBoundingClientRect ( ) ;
367379 this . _positionCache . items = this . _activeDraggables
368380 . map ( drag => {
369381 const elementToMeasure = this . _dragDropRegistry . isDragging ( drag ) ?
@@ -395,12 +407,10 @@ export class CdkDropList<T = any> implements OnInit, OnDestroy {
395407 a . clientRect . top - b . clientRect . top ;
396408 } ) ;
397409
398- this . _positionCache . siblings = coerceArray ( this . connectedTo )
399- . map ( drop => typeof drop === 'string' ? this . _dragDropRegistry . getDropContainer ( drop ) ! : drop )
400- . filter ( drop => drop && drop !== this )
401- . map ( drop => ( { drop, clientRect : drop . element . nativeElement . getBoundingClientRect ( ) } ) ) ;
402-
403- this . _positionCache . self = this . element . nativeElement . getBoundingClientRect ( ) ;
410+ this . _positionCache . siblings = this . _getConnectedLists ( ) . map ( drop => ( {
411+ drop,
412+ clientRect : drop . element . nativeElement . getBoundingClientRect ( )
413+ } ) ) ;
404414 }
405415
406416 /** Resets the container to its initial state. */
@@ -533,6 +543,23 @@ export class CdkDropList<T = any> implements OnInit, OnDestroy {
533543
534544 return siblingOffset ;
535545 }
546+
547+ /** Gets an array of unique drop lists that the current list is connected to. */
548+ private _getConnectedLists ( ) : CdkDropList [ ] {
549+ const siblings = coerceArray ( this . connectedTo ) . map ( drop => {
550+ return typeof drop === 'string' ? this . _dragDropRegistry . getDropContainer ( drop ) ! : drop ;
551+ } ) ;
552+
553+ if ( this . _group ) {
554+ this . _group . _items . forEach ( drop => {
555+ if ( siblings . indexOf ( drop ) === - 1 ) {
556+ siblings . push ( drop ) ;
557+ }
558+ } ) ;
559+ }
560+
561+ return siblings . filter ( drop => drop && drop !== this ) ;
562+ }
536563}
537564
538565
0 commit comments