Skip to content

Commit a168339

Browse files
committed
refactor(drag-drop): remove deprecated APIs for 9.0.0
Cleans on the APIs that were marked as deprecated for 8.0 and 9.0. Also deprecates a few for 10.0 which were supposed to be removed in 9.0, but hadn't been marked correctly. BREAKING CHANGES: * `DropListRef.id` has been removed. * `CdkDragConfig` has been replaced with `DragRefConfig`. * `DragDropRegistry.getDropContainer` has been removed. * `CdkDropListContainer` interface has been removed. * `CDK_DROP_LIST_CONTAINER` has been replaced with `CDK_DROP_LIST`. * `CdkDrag.boundaryElementSelector` has been replaced with `CdkDrag.boundaryElement`. * `_ngZone` and `_viewportRuler` parameters in the `DropListRef` constructor are now required. * `distance` parameter in `DropListRef.drop` is now required.
1 parent 77994e9 commit a168339

File tree

10 files changed

+54
-264
lines changed

10 files changed

+54
-264
lines changed

src/cdk/drag-drop/directives/drag.ts

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,17 @@ import {
4545
import {CdkDragHandle} from './drag-handle';
4646
import {CdkDragPlaceholder} from './drag-placeholder';
4747
import {CdkDragPreview} from './drag-preview';
48-
import {CDK_DROP_LIST} from '../drop-list-container';
4948
import {CDK_DRAG_PARENT} from '../drag-parent';
5049
import {DragRef, DragRefConfig, Point} from '../drag-ref';
5150
import {CdkDropListInternal as CdkDropList} from './drop-list';
5251
import {DragDrop} from '../drag-drop';
5352

53+
/**
54+
* Injection token that is used to provide a CdkDropList instance to CdkDrag.
55+
* Used for avoiding circular imports.
56+
*/
57+
export const CDK_DROP_LIST = new InjectionToken<CdkDropList>('CDK_DROP_LIST');
58+
5459
/** Injection token that can be used to configure the behavior of `CdkDrag`. */
5560
export const CDK_DRAG_CONFIG = new InjectionToken<DragRefConfig>('CDK_DRAG_CONFIG', {
5661
providedIn: 'root',
@@ -109,20 +114,6 @@ export class CdkDrag<T = any> implements AfterViewInit, OnChanges, OnDestroy {
109114
*/
110115
@Input('cdkDragBoundary') boundaryElement: string | ElementRef<HTMLElement> | HTMLElement;
111116

112-
/**
113-
* Selector that will be used to determine the element to which the draggable's position will
114-
* be constrained. Matching starts from the element's parent and goes up the DOM until a matching
115-
* element has been found
116-
* @deprecated Use `boundaryElement` instead.
117-
* @breaking-change 9.0.0
118-
*/
119-
get boundaryElementSelector(): string {
120-
return typeof this.boundaryElement === 'string' ? this.boundaryElement : undefined!;
121-
}
122-
set boundaryElementSelector(selector: string) {
123-
this.boundaryElement = selector;
124-
}
125-
126117
/**
127118
* Amount of milliseconds to wait after the user has put their
128119
* pointer down before starting to drag the element.

src/cdk/drag-drop/directives/drop-list.ts

Lines changed: 21 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
ContentChildren,
1212
ElementRef,
1313
EventEmitter,
14-
forwardRef,
1514
Input,
1615
OnDestroy,
1716
Output,
@@ -23,9 +22,8 @@ import {
2322
AfterContentInit,
2423
} from '@angular/core';
2524
import {Directionality} from '@angular/cdk/bidi';
26-
import {CdkDrag} from './drag';
25+
import {CdkDrag, CDK_DROP_LIST} from './drag';
2726
import {CdkDragDrop, CdkDragEnter, CdkDragExit, CdkDragSortEvent} from '../drag-events';
28-
import {CDK_DROP_LIST_CONTAINER, CdkDropListContainer} from '../drop-list-container';
2927
import {CdkDropListGroup} from './drop-list-group';
3028
import {DropListRef} from '../drop-list-ref';
3129
import {DragRef} from '../drag-ref';
@@ -43,18 +41,14 @@ let _uniqueIdCounter = 0;
4341
*/
4442
export interface CdkDropListInternal extends CdkDropList {}
4543

46-
// @breaking-change 8.0.0 `CdkDropList` implements `CdkDropListContainer` for backwards
47-
// compatiblity. The implements clause, as well as all the methods that it enforces can
48-
// be removed when `CdkDropListContainer` is deleted.
49-
5044
/** Container that wraps a set of draggable items. */
5145
@Directive({
5246
selector: '[cdkDropList], cdk-drop-list',
5347
exportAs: 'cdkDropList',
5448
providers: [
5549
// Prevent child drop lists from picking up the same group as their parent.
5650
{provide: CdkDropListGroup, useValue: undefined},
57-
{provide: CDK_DROP_LIST_CONTAINER, useExisting: CdkDropList},
51+
{provide: CDK_DROP_LIST, useExisting: CdkDropList},
5852
],
5953
host: {
6054
'class': 'cdk-drop-list',
@@ -64,7 +58,7 @@ export interface CdkDropListInternal extends CdkDropList {}
6458
'[class.cdk-drop-list-receiving]': '_dropListRef.isReceiving()',
6559
}
6660
})
67-
export class CdkDropList<T = any> implements CdkDropListContainer, AfterContentInit, OnDestroy {
61+
export class CdkDropList<T = any> implements AfterContentInit, OnDestroy {
6862
/** Emits when the list has been destroyed. */
6963
private _destroyed = new Subject<void>();
7064

@@ -75,7 +69,7 @@ export class CdkDropList<T = any> implements CdkDropListContainer, AfterContentI
7569
_dropListRef: DropListRef<CdkDropList<T>>;
7670

7771
/** Draggable items in the container. */
78-
@ContentChildren(forwardRef(() => CdkDrag), {
72+
@ContentChildren(CdkDrag, {
7973
// Explicitly set to false since some of the logic below makes assumptions about it.
8074
// The `.withItems` call below should be updated if we ever need to switch this to `true`.
8175
descendants: false
@@ -198,7 +192,11 @@ export class CdkDropList<T = any> implements CdkDropListContainer, AfterContentI
198192
this._destroyed.complete();
199193
}
200194

201-
/** Starts dragging an item. */
195+
/**
196+
* Starts dragging an item.
197+
* @deprecated No longer being used. To be removed.
198+
* @breaking-change 10.0.0
199+
*/
202200
start(): void {
203201
this._dropListRef.start();
204202
}
@@ -210,18 +208,23 @@ export class CdkDropList<T = any> implements CdkDropListContainer, AfterContentI
210208
* @param previousContainer Container from which the item got dragged in.
211209
* @param isPointerOverContainer Whether the user's pointer was over the
212210
* container when the item was dropped.
211+
*
212+
* @deprecated No longer being used. To be removed.
213+
* @breaking-change 10.0.0
213214
*/
214-
drop(item: CdkDrag, currentIndex: number, previousContainer: Partial<CdkDropListContainer>,
215+
drop(item: CdkDrag, currentIndex: number, previousContainer: CdkDropList,
215216
isPointerOverContainer: boolean): void {
216-
this._dropListRef.drop(item._dragRef, currentIndex,
217-
(previousContainer as CdkDropList)._dropListRef, isPointerOverContainer);
217+
this._dropListRef.drop(item._dragRef, currentIndex, previousContainer._dropListRef,
218+
isPointerOverContainer, {x: 0, y: 0});
218219
}
219220

220221
/**
221222
* Emits an event to indicate that the user moved an item into the container.
222223
* @param item Item that was moved into the container.
223224
* @param pointerX Position of the item along the X axis.
224225
* @param pointerY Position of the item along the Y axis.
226+
* @deprecated No longer being used. To be removed.
227+
* @breaking-change 10.0.0
225228
*/
226229
enter(item: CdkDrag, pointerX: number, pointerY: number): void {
227230
this._dropListRef.enter(item._dragRef, pointerX, pointerY);
@@ -230,6 +233,8 @@ export class CdkDropList<T = any> implements CdkDropListContainer, AfterContentI
230233
/**
231234
* Removes an item from the container after it was dragged into another container by the user.
232235
* @param item Item that was dragged out.
236+
* @deprecated No longer being used. To be removed.
237+
* @breaking-change 10.0.0
233238
*/
234239
exit(item: CdkDrag): void {
235240
this._dropListRef.exit(item._dragRef);
@@ -238,45 +243,13 @@ export class CdkDropList<T = any> implements CdkDropListContainer, AfterContentI
238243
/**
239244
* Figures out the index of an item in the container.
240245
* @param item Item whose index should be determined.
246+
* @deprecated No longer being used. To be removed.
247+
* @breaking-change 10.0.0
241248
*/
242249
getItemIndex(item: CdkDrag): number {
243250
return this._dropListRef.getItemIndex(item._dragRef);
244251
}
245252

246-
/**
247-
* Sorts an item inside the container based on its position.
248-
* @param item Item to be sorted.
249-
* @param pointerX Position of the item along the X axis.
250-
* @param pointerY Position of the item along the Y axis.
251-
* @param pointerDelta Direction in which the pointer is moving along each axis.
252-
*/
253-
_sortItem(item: CdkDrag, pointerX: number, pointerY: number,
254-
pointerDelta: {x: number, y: number}): void {
255-
return this._dropListRef._sortItem(item._dragRef, pointerX, pointerY, pointerDelta);
256-
}
257-
258-
/**
259-
* Figures out whether an item should be moved into a sibling
260-
* drop container, based on its current position.
261-
* @param item Drag item that is being moved.
262-
* @param x Position of the item along the X axis.
263-
* @param y Position of the item along the Y axis.
264-
*/
265-
_getSiblingContainerFromPosition(item: CdkDrag, x: number, y: number):
266-
CdkDropListContainer | null {
267-
const result = this._dropListRef._getSiblingContainerFromPosition(item._dragRef, x, y);
268-
return result ? result.data : null;
269-
}
270-
271-
/**
272-
* Checks whether the user's pointer is positioned over the container.
273-
* @param x Pointer position along the X axis.
274-
* @param y Pointer position along the Y axis.
275-
*/
276-
_isOverContainer(x: number, y: number): boolean {
277-
return this._dropListRef._isOverContainer(x, y);
278-
}
279-
280253
/** Syncs the inputs of the CdkDropList with the options of the underlying DropListRef. */
281254
private _syncInputs(ref: DropListRef<CdkDropList>) {
282255
if (this._dir) {

src/cdk/drag-drop/drag-drop-registry.spec.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,6 @@ describe('DragDropRegistry', () => {
186186
pointerMoveSubscription.unsubscribe();
187187
});
188188

189-
it('should not throw when trying to register the same container again', () => {
190-
expect(() => registry.registerDropContainer(testComponent.dropInstances.first)).not.toThrow();
191-
});
192-
193189
it('should not prevent the default `touchmove` actions when nothing is being dragged', () => {
194190
expect(dispatchTouchEvent(document, 'touchmove').defaultPrevented).toBe(false);
195191
});

src/cdk/drag-drop/drag-drop-registry.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const activeCapturingEventOptions = normalizePassiveListenerOptions({
2626
// to avoid circular imports. If we were to reference them here, importing the registry into the
2727
// classes that are registering themselves will introduce a circular import.
2828
@Injectable({providedIn: 'root'})
29-
export class DragDropRegistry<I, C extends {id: string}> implements OnDestroy {
29+
export class DragDropRegistry<I, C> implements OnDestroy {
3030
private _document: Document;
3131

3232
/** Registered drop container instances. */
@@ -68,10 +68,6 @@ export class DragDropRegistry<I, C extends {id: string}> implements OnDestroy {
6868
/** Adds a drop container to the registry. */
6969
registerDropContainer(drop: C) {
7070
if (!this._dropInstances.has(drop)) {
71-
if (this.getDropContainer(drop.id)) {
72-
throw Error(`Drop instance with id "${drop.id}" has already been registered.`);
73-
}
74-
7571
this._dropInstances.add(drop);
7672
}
7773
}
@@ -173,15 +169,6 @@ export class DragDropRegistry<I, C extends {id: string}> implements OnDestroy {
173169
return this._activeDragInstances.has(drag);
174170
}
175171

176-
/**
177-
* Gets a drop container by its id.
178-
* @deprecated No longer being used. To be removed.
179-
* @breaking-change 8.0.0
180-
*/
181-
getDropContainer(id: string): C | undefined {
182-
return Array.from(this._dropInstances).find(instance => instance.id === id);
183-
}
184-
185172
ngOnDestroy() {
186173
this._dragInstances.forEach(instance => this.removeDragItem(instance));
187174
this._dropInstances.forEach(instance => this.removeDropContainer(instance));

src/cdk/drag-drop/drop-list-container.ts

Lines changed: 0 additions & 92 deletions
This file was deleted.

0 commit comments

Comments
 (0)