From 21e0358b92ef499e187b0e13157019442babc150 Mon Sep 17 00:00:00 2001 From: crisbeto Date: Sat, 5 Sep 2020 12:53:24 +0200 Subject: [PATCH] refactor(drag-drop): change deprecated APIs for v11 Changes the APIs that were marked as deprecated for v11. BREAKING CHANGES: * `_scrollDispatcher` parameter of the `CdkDropList` constructor is now required. Also the order of the parameters has changed to accommodate the parameter becoming required. * `previousIndex` parameter of `DropListRef.drop` is now required. Also the parameter order has changed. --- src/cdk/drag-drop/directives/drop-list.ts | 13 ++++--------- src/cdk/drag-drop/drag-ref.ts | 4 ++-- src/cdk/drag-drop/drop-list-ref.ts | 17 +++++------------ .../ng-update/data/constructor-checks.ts | 4 ++++ .../ng-update/data/method-call-checks.ts | 11 +++++++++++ tools/public_api_guard/cdk/drag-drop.d.ts | 7 +++---- 6 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/cdk/drag-drop/directives/drop-list.ts b/src/cdk/drag-drop/directives/drop-list.ts index 49638aa6ca14..5d772ee12ed3 100644 --- a/src/cdk/drag-drop/directives/drop-list.ts +++ b/src/cdk/drag-drop/directives/drop-list.ts @@ -168,15 +168,11 @@ export class CdkDropList implements OnDestroy { constructor( /** Element that the drop list is attached to. */ public element: ElementRef, dragDrop: DragDrop, - private _changeDetectorRef: ChangeDetectorRef, @Optional() private _dir?: Directionality, + private _changeDetectorRef: ChangeDetectorRef, + private _scrollDispatcher: ScrollDispatcher, + @Optional() private _dir?: Directionality, @Optional() @Inject(CDK_DROP_LIST_GROUP) @SkipSelf() private _group?: CdkDropListGroup, - - /** - * @deprecated _scrollDispatcher parameter to become required. - * @breaking-change 11.0.0 - */ - private _scrollDispatcher?: ScrollDispatcher, @Optional() @Inject(CDK_DRAG_CONFIG) config?: DragDropConfig) { this._dropListRef = dragDrop.createDropList(element); this._dropListRef.data = this; @@ -284,8 +280,7 @@ export class CdkDropList implements OnDestroy { // Note that we resolve the scrollable parents here so that we delay the resolution // as long as possible, ensuring that the element is in its final place in the DOM. - // @breaking-change 11.0.0 Remove null check for _scrollDispatcher once it's required. - if (!this._scrollableParentsResolved && this._scrollDispatcher) { + if (!this._scrollableParentsResolved) { const scrollableParents = this._scrollDispatcher .getAncestorScrollContainers(this.element) .map(scrollable => scrollable.getElementRef().nativeElement); diff --git a/src/cdk/drag-drop/drag-ref.ts b/src/cdk/drag-drop/drag-ref.ts index dd200ff065ad..5e823f11778b 100644 --- a/src/cdk/drag-drop/drag-ref.ts +++ b/src/cdk/drag-drop/drag-ref.ts @@ -851,8 +851,8 @@ export class DragRef { isPointerOverContainer, distance }); - container.drop(this, currentIndex, this._initialContainer, isPointerOverContainer, distance, - this._initialIndex); + container.drop(this, currentIndex, this._initialIndex, this._initialContainer, + isPointerOverContainer, distance); this._dropContainer = this._initialContainer; }); } diff --git a/src/cdk/drag-drop/drop-list-ref.ts b/src/cdk/drag-drop/drop-list-ref.ts index 6ea7f5f7c88a..7577ebb23dc8 100644 --- a/src/cdk/drag-drop/drop-list-ref.ts +++ b/src/cdk/drag-drop/drop-list-ref.ts @@ -339,24 +339,17 @@ export class DropListRef { * Drops an item into this container. * @param item Item being dropped into the container. * @param currentIndex Index at which the item should be inserted. + * @param previousIndex Index of the item when dragging started. * @param previousContainer Container from which the item got dragged in. * @param isPointerOverContainer Whether the user's pointer was over the * container when the item was dropped. * @param distance Distance the user has dragged since the start of the dragging sequence. - * @param previousIndex Index of the item when dragging started. - * - * @breaking-change 11.0.0 `previousIndex` parameter to become required. */ - drop(item: DragRef, currentIndex: number, previousContainer: DropListRef, - isPointerOverContainer: boolean, distance: Point, previousIndex?: number): void { + drop(item: DragRef, currentIndex: number, previousIndex: number, previousContainer: DropListRef, + isPointerOverContainer: boolean, distance: Point): void { this._reset(); - - // @breaking-change 11.0.0 Remove this fallback logic once `previousIndex` is a required param. - if (previousIndex == null) { - previousIndex = previousContainer.getItemIndex(item); - } - - this.dropped.next({item, + this.dropped.next({ + item, currentIndex, previousIndex, container: this, diff --git a/src/cdk/schematics/ng-update/data/constructor-checks.ts b/src/cdk/schematics/ng-update/data/constructor-checks.ts index 8f98010e507d..c70184d6c299 100644 --- a/src/cdk/schematics/ng-update/data/constructor-checks.ts +++ b/src/cdk/schematics/ng-update/data/constructor-checks.ts @@ -21,6 +21,10 @@ export const constructorChecks: VersionChanges = { { pr: 'https://github.com/angular/components/pull/20454', changes: ['ScrollDispatcher', 'ViewportRuler', 'CdkVirtualScrollViewport'] + }, + { + pr: 'https://github.com/angular/components/pull/20500', + changes: ['CdkDropList'] } ], [TargetVersion.V10]: [ diff --git a/src/cdk/schematics/ng-update/data/method-call-checks.ts b/src/cdk/schematics/ng-update/data/method-call-checks.ts index 048ed0b2caed..a159a07e5928 100644 --- a/src/cdk/schematics/ng-update/data/method-call-checks.ts +++ b/src/cdk/schematics/ng-update/data/method-call-checks.ts @@ -16,6 +16,17 @@ export interface MethodCallUpgradeData { } export const methodCallChecks: VersionChanges = { + [TargetVersion.V11]: [{ + pr: 'https://github.com/angular/components/pull/20500', + changes: [{ + className: 'DropListRef', + method: 'drop', + invalidArgCounts: [{ + count: 5, + message: 'The "previousIndex" parameter is required and the parameter order has changed.' + }] + }] + }], [TargetVersion.V9]: [{ pr: 'https://github.com/angular/components/pull/17084', changes: [{ diff --git a/tools/public_api_guard/cdk/drag-drop.d.ts b/tools/public_api_guard/cdk/drag-drop.d.ts index 4ce76e4ff1c7..d2f154c32562 100644 --- a/tools/public_api_guard/cdk/drag-drop.d.ts +++ b/tools/public_api_guard/cdk/drag-drop.d.ts @@ -172,8 +172,7 @@ export declare class CdkDropList implements OnDestroy { sorted: EventEmitter>; sortingDisabled: boolean; constructor( - element: ElementRef, dragDrop: DragDrop, _changeDetectorRef: ChangeDetectorRef, _dir?: Directionality | undefined, _group?: CdkDropListGroup> | undefined, - _scrollDispatcher?: ScrollDispatcher | undefined, config?: DragDropConfig); + element: ElementRef, dragDrop: DragDrop, _changeDetectorRef: ChangeDetectorRef, _scrollDispatcher: ScrollDispatcher, _dir?: Directionality | undefined, _group?: CdkDropListGroup> | undefined, config?: DragDropConfig); addItem(item: CdkDrag): void; getSortedItems(): CdkDrag[]; ngOnDestroy(): void; @@ -182,7 +181,7 @@ export declare class CdkDropList implements OnDestroy { static ngAcceptInputType_disabled: BooleanInput; static ngAcceptInputType_sortingDisabled: BooleanInput; static ɵdir: i0.ɵɵDirectiveDefWithMeta, "[cdkDropList], cdk-drop-list", ["cdkDropList"], { "connectedTo": "cdkDropListConnectedTo"; "data": "cdkDropListData"; "orientation": "cdkDropListOrientation"; "id": "id"; "lockAxis": "cdkDropListLockAxis"; "disabled": "cdkDropListDisabled"; "sortingDisabled": "cdkDropListSortingDisabled"; "enterPredicate": "cdkDropListEnterPredicate"; "sortPredicate": "cdkDropListSortPredicate"; "autoScrollDisabled": "cdkDropListAutoScrollDisabled"; }, { "dropped": "cdkDropListDropped"; "entered": "cdkDropListEntered"; "exited": "cdkDropListExited"; "sorted": "cdkDropListSorted"; }, never>; - static ɵfac: i0.ɵɵFactoryDef, [null, null, null, { optional: true; }, { optional: true; skipSelf: true; }, null, { optional: true; }]>; + static ɵfac: i0.ɵɵFactoryDef, [null, null, null, null, { optional: true; }, { optional: true; skipSelf: true; }, { optional: true; }]>; } export declare class CdkDropListGroup implements OnDestroy { @@ -380,7 +379,7 @@ export declare class DropListRef { _stopScrolling(): void; connectedTo(connectedTo: DropListRef[]): this; dispose(): void; - drop(item: DragRef, currentIndex: number, previousContainer: DropListRef, isPointerOverContainer: boolean, distance: Point, previousIndex?: number): void; + drop(item: DragRef, currentIndex: number, previousIndex: number, previousContainer: DropListRef, isPointerOverContainer: boolean, distance: Point): void; enter(item: DragRef, pointerX: number, pointerY: number, index?: number): void; exit(item: DragRef): void; getItemIndex(item: DragRef): number;