Skip to content

Commit 69eedd7

Browse files
authored
fix(cdk/drag-drop): incorrect type DragConstrainPosition (#30510)
* fix(cdk/drag-drop): incorrect type DragConstrainPosition Fixes type DragConstrainPosition, which of сorrect configuration of CdkDrag is not possible when using in providers Fixes #30509 * fix(cdk/drag-drop): change type in CdkDrag for input cdkDragConstrainPosition Impot the type from the configuration CdkDrag for input cdkDragConstrainPosition, which leads to type safety. * fix(cdk/drag-drop): change type in CdkRef for property constrainPosition Impot the type from the configuration CdkRef for property constrainPosition, which leads to type safety. * fix(cdk/drag-drop): move type DragConstrainPosition in DragRef fix circular dependency * fix(cdk/drag-drop): added type DragConstrainPosition in public api DragConstrainPosition type should be in the documentation
1 parent c0a8060 commit 69eedd7

File tree

5 files changed

+16
-21
lines changed

5 files changed

+16
-21
lines changed

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,14 @@
77
*/
88

99
import {InjectionToken} from '@angular/core';
10-
import {DragRefConfig, Point, DragRef} from '../drag-ref';
10+
import {DragRefConfig, DragConstrainPosition} from '../drag-ref';
1111

1212
/** Possible values that can be used to configure the drag start delay. */
1313
export type DragStartDelay = number | {touch: number; mouse: number};
1414

1515
/** Possible axis along which dragging can be locked. */
1616
export type DragAxis = 'x' | 'y';
1717

18-
/** Function that can be used to constrain the position of a dragged element. */
19-
export type DragConstrainPosition = (point: Point, dragRef: DragRef) => Point;
20-
2118
/** Possible orientations for a drop list. */
2219
export type DropListOrientation = 'horizontal' | 'vertical' | 'mixed';
2320

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import {CDK_DRAG_HANDLE, CdkDragHandle} from './drag-handle';
4343
import {CdkDragPlaceholder} from './drag-placeholder';
4444
import {CdkDragPreview} from './drag-preview';
4545
import {CDK_DRAG_PARENT} from '../drag-parent';
46-
import {DragRef, Point, PreviewContainer} from '../drag-ref';
46+
import {DragRef, Point, PreviewContainer, DragConstrainPosition} from '../drag-ref';
4747
import type {CdkDropList} from './drop-list';
4848
import {DragDrop} from '../drag-drop';
4949
import {CDK_DRAG_CONFIG, DragDropConfig, DragStartDelay, DragAxis} from './config';
@@ -137,12 +137,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnChanges, OnDestroy {
137137
* of the user's pointer on the page, a reference to the item being dragged and its dimensions.
138138
* Should return a point describing where the item should be rendered.
139139
*/
140-
@Input('cdkDragConstrainPosition') constrainPosition?: (
141-
userPointerPosition: Point,
142-
dragRef: DragRef,
143-
dimensions: DOMRect,
144-
pickupPositionInElement: Point,
145-
) => Point;
140+
@Input('cdkDragConstrainPosition') constrainPosition?: DragConstrainPosition;
146141

147142
/** Class to be added to the preview element. */
148143
@Input('cdkDragPreviewClass') previewClass: string | string[];

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ export interface DragRefConfig {
5757
parentDragRef?: DragRef;
5858
}
5959

60+
/** Function that can be used to constrain the position of a dragged element. */
61+
export type DragConstrainPosition = (
62+
userPointerPosition: Point,
63+
dragRef: DragRef,
64+
dimensions: DOMRect,
65+
pickupPositionInElement: Point,
66+
) => Point;
67+
6068
/** Options that can be used to bind a passive event listener. */
6169
const passiveEventListenerOptions = {passive: true};
6270

@@ -364,12 +372,7 @@ export class DragRef<T = any> {
364372
* of the user's pointer on the page, a reference to the item being dragged and its dimensions.
365373
* Should return a point describing where the item should be rendered.
366374
*/
367-
constrainPosition?: (
368-
userPointerPosition: Point,
369-
dragRef: DragRef,
370-
dimensions: DOMRect,
371-
pickupPositionInElement: Point,
372-
) => Point;
375+
constrainPosition?: DragConstrainPosition;
373376

374377
constructor(
375378
element: ElementRef<HTMLElement> | HTMLElement,

src/cdk/drag-drop/public-api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
export {DragDrop} from './drag-drop';
10-
export {DragRef, DragRefConfig, Point, PreviewContainer} from './drag-ref';
10+
export {DragRef, DragRefConfig, Point, PreviewContainer, DragConstrainPosition} from './drag-ref';
1111
export {DropListRef} from './drop-list-ref';
1212
export {CDK_DRAG_PARENT} from './drag-parent';
1313

tools/public_api_guard/cdk/drag-drop.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnChanges, OnDestroy {
5050
// (undocumented)
5151
_addHandle(handle: CdkDragHandle): void;
5252
boundaryElement: string | ElementRef<HTMLElement> | HTMLElement;
53-
constrainPosition?: (userPointerPosition: Point, dragRef: DragRef, dimensions: DOMRect, pickupPositionInElement: Point) => Point;
53+
constrainPosition?: DragConstrainPosition;
5454
data: T;
5555
get disabled(): boolean;
5656
set disabled(value: boolean);
@@ -300,7 +300,7 @@ export function copyArrayItem<T = any>(currentArray: T[], targetArray: T[], curr
300300
export type DragAxis = 'x' | 'y';
301301

302302
// @public
303-
export type DragConstrainPosition = (point: Point, dragRef: DragRef) => Point;
303+
export type DragConstrainPosition = (userPointerPosition: Point, dragRef: DragRef, dimensions: DOMRect, pickupPositionInElement: Point) => Point;
304304

305305
// @public
306306
export class DragDrop {
@@ -381,7 +381,7 @@ export class DragDropRegistry<_ = unknown, __ = unknown> implements OnDestroy {
381381
export class DragRef<T = any> {
382382
constructor(element: ElementRef<HTMLElement> | HTMLElement, _config: DragRefConfig, _document: Document, _ngZone: NgZone, _viewportRuler: ViewportRuler, _dragDropRegistry: DragDropRegistry, _renderer: Renderer2);
383383
readonly beforeStarted: Subject<void>;
384-
constrainPosition?: (userPointerPosition: Point, dragRef: DragRef, dimensions: DOMRect, pickupPositionInElement: Point) => Point;
384+
constrainPosition?: DragConstrainPosition;
385385
data: T;
386386
get disabled(): boolean;
387387
set disabled(value: boolean);

0 commit comments

Comments
 (0)