diff --git a/src/cdk/drag-drop/directives/config.ts b/src/cdk/drag-drop/directives/config.ts index 7e44425d85e5..2263935d85c0 100644 --- a/src/cdk/drag-drop/directives/config.ts +++ b/src/cdk/drag-drop/directives/config.ts @@ -7,7 +7,7 @@ */ import {InjectionToken} from '@angular/core'; -import {DragRefConfig, Point, DragRef} from '../drag-ref'; +import {DragRefConfig, DragConstrainPosition} from '../drag-ref'; /** Possible values that can be used to configure the drag start delay. */ export type DragStartDelay = number | {touch: number; mouse: number}; @@ -15,9 +15,6 @@ export type DragStartDelay = number | {touch: number; mouse: number}; /** Possible axis along which dragging can be locked. */ export type DragAxis = 'x' | 'y'; -/** Function that can be used to constrain the position of a dragged element. */ -export type DragConstrainPosition = (point: Point, dragRef: DragRef) => Point; - /** Possible orientations for a drop list. */ export type DropListOrientation = 'horizontal' | 'vertical' | 'mixed'; diff --git a/src/cdk/drag-drop/directives/drag.ts b/src/cdk/drag-drop/directives/drag.ts index 8ec7fab27f5e..d051a972e1dd 100644 --- a/src/cdk/drag-drop/directives/drag.ts +++ b/src/cdk/drag-drop/directives/drag.ts @@ -43,7 +43,7 @@ import {CDK_DRAG_HANDLE, CdkDragHandle} from './drag-handle'; import {CdkDragPlaceholder} from './drag-placeholder'; import {CdkDragPreview} from './drag-preview'; import {CDK_DRAG_PARENT} from '../drag-parent'; -import {DragRef, Point, PreviewContainer} from '../drag-ref'; +import {DragRef, Point, PreviewContainer, DragConstrainPosition} from '../drag-ref'; import type {CdkDropList} from './drop-list'; import {DragDrop} from '../drag-drop'; import {CDK_DRAG_CONFIG, DragDropConfig, DragStartDelay, DragAxis} from './config'; @@ -137,12 +137,7 @@ export class CdkDrag implements AfterViewInit, OnChanges, OnDestroy { * of the user's pointer on the page, a reference to the item being dragged and its dimensions. * Should return a point describing where the item should be rendered. */ - @Input('cdkDragConstrainPosition') constrainPosition?: ( - userPointerPosition: Point, - dragRef: DragRef, - dimensions: DOMRect, - pickupPositionInElement: Point, - ) => Point; + @Input('cdkDragConstrainPosition') constrainPosition?: DragConstrainPosition; /** Class to be added to the preview element. */ @Input('cdkDragPreviewClass') previewClass: string | string[]; diff --git a/src/cdk/drag-drop/drag-ref.ts b/src/cdk/drag-drop/drag-ref.ts index 9bcb2e9d5133..fa24a4e76576 100644 --- a/src/cdk/drag-drop/drag-ref.ts +++ b/src/cdk/drag-drop/drag-ref.ts @@ -57,6 +57,14 @@ export interface DragRefConfig { parentDragRef?: DragRef; } +/** Function that can be used to constrain the position of a dragged element. */ +export type DragConstrainPosition = ( + userPointerPosition: Point, + dragRef: DragRef, + dimensions: DOMRect, + pickupPositionInElement: Point, +) => Point; + /** Options that can be used to bind a passive event listener. */ const passiveEventListenerOptions = {passive: true}; @@ -364,12 +372,7 @@ export class DragRef { * of the user's pointer on the page, a reference to the item being dragged and its dimensions. * Should return a point describing where the item should be rendered. */ - constrainPosition?: ( - userPointerPosition: Point, - dragRef: DragRef, - dimensions: DOMRect, - pickupPositionInElement: Point, - ) => Point; + constrainPosition?: DragConstrainPosition; constructor( element: ElementRef | HTMLElement, diff --git a/src/cdk/drag-drop/public-api.ts b/src/cdk/drag-drop/public-api.ts index f3b87dba939d..34d541d83211 100644 --- a/src/cdk/drag-drop/public-api.ts +++ b/src/cdk/drag-drop/public-api.ts @@ -7,7 +7,7 @@ */ export {DragDrop} from './drag-drop'; -export {DragRef, DragRefConfig, Point, PreviewContainer} from './drag-ref'; +export {DragRef, DragRefConfig, Point, PreviewContainer, DragConstrainPosition} from './drag-ref'; export {DropListRef} from './drop-list-ref'; export {CDK_DRAG_PARENT} from './drag-parent'; diff --git a/tools/public_api_guard/cdk/drag-drop.md b/tools/public_api_guard/cdk/drag-drop.md index 28e2c19ceba0..3a580646aee3 100644 --- a/tools/public_api_guard/cdk/drag-drop.md +++ b/tools/public_api_guard/cdk/drag-drop.md @@ -50,7 +50,7 @@ export class CdkDrag implements AfterViewInit, OnChanges, OnDestroy { // (undocumented) _addHandle(handle: CdkDragHandle): void; boundaryElement: string | ElementRef | HTMLElement; - constrainPosition?: (userPointerPosition: Point, dragRef: DragRef, dimensions: DOMRect, pickupPositionInElement: Point) => Point; + constrainPosition?: DragConstrainPosition; data: T; get disabled(): boolean; set disabled(value: boolean); @@ -300,7 +300,7 @@ export function copyArrayItem(currentArray: T[], targetArray: T[], curr export type DragAxis = 'x' | 'y'; // @public -export type DragConstrainPosition = (point: Point, dragRef: DragRef) => Point; +export type DragConstrainPosition = (userPointerPosition: Point, dragRef: DragRef, dimensions: DOMRect, pickupPositionInElement: Point) => Point; // @public export class DragDrop { @@ -381,7 +381,7 @@ export class DragDropRegistry<_ = unknown, __ = unknown> implements OnDestroy { export class DragRef { constructor(element: ElementRef | HTMLElement, _config: DragRefConfig, _document: Document, _ngZone: NgZone, _viewportRuler: ViewportRuler, _dragDropRegistry: DragDropRegistry, _renderer: Renderer2); readonly beforeStarted: Subject; - constrainPosition?: (userPointerPosition: Point, dragRef: DragRef, dimensions: DOMRect, pickupPositionInElement: Point) => Point; + constrainPosition?: DragConstrainPosition; data: T; get disabled(): boolean; set disabled(value: boolean);