Skip to content

Commit 53b0660

Browse files
committed
refactor(multiple): remove references to deprecated ClientRect (#28325)
The `ClientRect` type is deprecated in favor of `DOMRect`. These changes replace all the references. (cherry picked from commit 5849a74)
1 parent 94a9fa9 commit 53b0660

File tree

16 files changed

+108
-115
lines changed

16 files changed

+108
-115
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ describe('CdkDrag', () => {
567567
fixture.componentInstance.dragInstance.constrainPosition = (
568568
{x, y}: Point,
569569
_dragRef: DragRef,
570-
_dimensions: ClientRect,
570+
_dimensions: DOMRect,
571571
pickup: Point,
572572
) => {
573573
x -= pickup.x;
@@ -610,7 +610,7 @@ describe('CdkDrag', () => {
610610
fixture.componentInstance.dragInstance.constrainPosition = (
611611
{x, y}: Point,
612612
_dragRef: DragRef,
613-
_dimensions: ClientRect,
613+
_dimensions: DOMRect,
614614
pickup: Point,
615615
) => {
616616
x -= pickup.x;
@@ -1007,7 +1007,7 @@ describe('CdkDrag', () => {
10071007
fixture.componentInstance.dragInstance.constrainPosition = (
10081008
{x, y}: Point,
10091009
_dragRef: DragRef,
1010-
_dimensions: ClientRect,
1010+
_dimensions: DOMRect,
10111011
pickup: Point,
10121012
) => {
10131013
x -= pickup.x;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnChanges, OnDestroy {
143143
@Input('cdkDragConstrainPosition') constrainPosition?: (
144144
userPointerPosition: Point,
145145
dragRef: DragRef,
146-
dimensions: ClientRect,
146+
dimensions: DOMRect,
147147
pickupPositionInElement: Point,
148148
) => Point;
149149

src/cdk/drag-drop/dom/client-rect.ts renamed to src/cdk/drag-drop/dom/dom-rect.ts

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,45 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
/** Gets a mutable version of an element's bounding `ClientRect`. */
10-
export function getMutableClientRect(element: Element): ClientRect {
11-
const clientRect = element.getBoundingClientRect();
9+
/** Gets a mutable version of an element's bounding `DOMRect`. */
10+
export function getMutableClientRect(element: Element): DOMRect {
11+
const rect = element.getBoundingClientRect();
1212

1313
// We need to clone the `clientRect` here, because all the values on it are readonly
1414
// and we need to be able to update them. Also we can't use a spread here, because
15-
// the values on a `ClientRect` aren't own properties. See:
15+
// the values on a `DOMRect` aren't own properties. See:
1616
// https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect#Notes
1717
return {
18-
top: clientRect.top,
19-
right: clientRect.right,
20-
bottom: clientRect.bottom,
21-
left: clientRect.left,
22-
width: clientRect.width,
23-
height: clientRect.height,
24-
x: clientRect.x,
25-
y: clientRect.y,
26-
} as ClientRect;
18+
top: rect.top,
19+
right: rect.right,
20+
bottom: rect.bottom,
21+
left: rect.left,
22+
width: rect.width,
23+
height: rect.height,
24+
x: rect.x,
25+
y: rect.y,
26+
} as DOMRect;
2727
}
2828

2929
/**
30-
* Checks whether some coordinates are within a `ClientRect`.
31-
* @param clientRect ClientRect that is being checked.
30+
* Checks whether some coordinates are within a `DOMRect`.
31+
* @param clientRect DOMRect that is being checked.
3232
* @param x Coordinates along the X axis.
3333
* @param y Coordinates along the Y axis.
3434
*/
35-
export function isInsideClientRect(clientRect: ClientRect, x: number, y: number) {
35+
export function isInsideClientRect(clientRect: DOMRect, x: number, y: number) {
3636
const {top, bottom, left, right} = clientRect;
3737
return y >= top && y <= bottom && x >= left && x <= right;
3838
}
3939

4040
/**
41-
* Updates the top/left positions of a `ClientRect`, as well as their bottom/right counterparts.
42-
* @param clientRect `ClientRect` that should be updated.
41+
* Updates the top/left positions of a `DOMRect`, as well as their bottom/right counterparts.
42+
* @param domRect `DOMRect` that should be updated.
4343
* @param top Amount to add to the `top` position.
4444
* @param left Amount to add to the `left` position.
4545
*/
46-
export function adjustClientRect(
47-
clientRect: {
46+
export function adjustDomRect(
47+
domRect: {
4848
top: number;
4949
bottom: number;
5050
left: number;
@@ -55,22 +55,22 @@ export function adjustClientRect(
5555
top: number,
5656
left: number,
5757
) {
58-
clientRect.top += top;
59-
clientRect.bottom = clientRect.top + clientRect.height;
58+
domRect.top += top;
59+
domRect.bottom = domRect.top + domRect.height;
6060

61-
clientRect.left += left;
62-
clientRect.right = clientRect.left + clientRect.width;
61+
domRect.left += left;
62+
domRect.right = domRect.left + domRect.width;
6363
}
6464

6565
/**
66-
* Checks whether the pointer coordinates are close to a ClientRect.
67-
* @param rect ClientRect to check against.
68-
* @param threshold Threshold around the ClientRect.
66+
* Checks whether the pointer coordinates are close to a DOMRect.
67+
* @param rect DOMRect to check against.
68+
* @param threshold Threshold around the DOMRect.
6969
* @param pointerX Coordinates along the X axis.
7070
* @param pointerY Coordinates along the Y axis.
7171
*/
72-
export function isPointerNearClientRect(
73-
rect: ClientRect,
72+
export function isPointerNearDomRect(
73+
rect: DOMRect,
7474
threshold: number,
7575
pointerX: number,
7676
pointerY: number,

src/cdk/drag-drop/dom/parent-position-tracker.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import {_getEventTarget} from '@angular/cdk/platform';
10-
import {getMutableClientRect, adjustClientRect} from './client-rect';
10+
import {getMutableClientRect, adjustDomRect} from './dom-rect';
1111

1212
/** Object holding the scroll position of something. */
1313
interface ScrollPosition {
@@ -22,7 +22,7 @@ export class ParentPositionTracker {
2222
Document | HTMLElement,
2323
{
2424
scrollPosition: ScrollPosition;
25-
clientRect?: ClientRect;
25+
clientRect?: DOMRect;
2626
}
2727
>();
2828

@@ -77,7 +77,7 @@ export class ParentPositionTracker {
7777
// parents that are inside the element that was scrolled.
7878
this.positions.forEach((position, node) => {
7979
if (position.clientRect && target !== node && target.contains(node)) {
80-
adjustClientRect(position.clientRect, topDifference, leftDifference);
80+
adjustDomRect(position.clientRect, topDifference, leftDifference);
8181
}
8282
});
8383

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

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
toggleVisibility,
2828
} from './dom/styling';
2929
import {getTransformTransitionDurationInMs} from './dom/transition-duration';
30-
import {getMutableClientRect, adjustClientRect} from './dom/client-rect';
30+
import {getMutableClientRect, adjustDomRect} from './dom/dom-rect';
3131
import {ParentPositionTracker} from './dom/parent-position-tracker';
3232
import {deepCloneNode} from './dom/clone-node';
3333

@@ -234,13 +234,13 @@ export class DragRef<T = any> {
234234
private _nativeInteractionsEnabled = true;
235235

236236
/** Client rect of the root element when the dragging sequence has started. */
237-
private _initialClientRect?: ClientRect;
237+
private _initialDomRect?: DOMRect;
238238

239239
/** Cached dimensions of the preview element. Should be read via `_getPreviewRect`. */
240-
private _previewRect?: ClientRect;
240+
private _previewRect?: DOMRect;
241241

242242
/** Cached dimensions of the boundary element. */
243-
private _boundaryRect?: ClientRect;
243+
private _boundaryRect?: DOMRect;
244244

245245
/** Element that will be used as a template to create the draggable item's preview. */
246246
private _previewTemplate?: DragPreviewTemplate | null;
@@ -355,7 +355,7 @@ export class DragRef<T = any> {
355355
constrainPosition?: (
356356
userPointerPosition: Point,
357357
dragRef: DragRef,
358-
dimensions: ClientRect,
358+
dimensions: DOMRect,
359359
pickupPositionInElement: Point,
360360
) => Point;
361361

@@ -696,7 +696,7 @@ export class DragRef<T = any> {
696696
} else {
697697
// If there's a position constraint function, we want the element's top/left to be at the
698698
// specific position on the page. Use the initial position as a reference if that's the case.
699-
const offset = this.constrainPosition ? this._initialClientRect! : this._pickupPositionOnPage;
699+
const offset = this.constrainPosition ? this._initialDomRect! : this._pickupPositionOnPage;
700700
const activeTransform = this._activeTransform;
701701
activeTransform.x = constrainedPointerPosition.x - offset.x + this._passiveTransform.x;
702702
activeTransform.y = constrainedPointerPosition.y - offset.y + this._passiveTransform.y;
@@ -885,7 +885,7 @@ export class DragRef<T = any> {
885885
// Avoid multiple subscriptions and memory leaks when multi touch
886886
// (isDragging check above isn't enough because of possible temporal and/or dimensional delays)
887887
this._removeSubscriptions();
888-
this._initialClientRect = this._rootElement.getBoundingClientRect();
888+
this._initialDomRect = this._rootElement.getBoundingClientRect();
889889
this._pointerMoveSubscription = this._dragDropRegistry.pointerMove.subscribe(this._pointerMove);
890890
this._pointerUpSubscription = this._dragDropRegistry.pointerUp.subscribe(this._pointerUp);
891891
this._scrollSubscription = this._dragDropRegistry
@@ -903,7 +903,7 @@ export class DragRef<T = any> {
903903
this._pickupPositionInElement =
904904
previewTemplate && previewTemplate.template && !previewTemplate.matchSize
905905
? {x: 0, y: 0}
906-
: this._getPointerPositionInElement(this._initialClientRect, referenceElement, event);
906+
: this._getPointerPositionInElement(this._initialDomRect, referenceElement, event);
907907
const pointerPosition =
908908
(this._pickupPositionOnPage =
909909
this._lastKnownPointerPosition =
@@ -925,7 +925,7 @@ export class DragRef<T = any> {
925925

926926
this._destroyPreview();
927927
this._destroyPlaceholder();
928-
this._initialClientRect =
928+
this._initialDomRect =
929929
this._boundaryRect =
930930
this._previewRect =
931931
this._initialTransform =
@@ -1043,7 +1043,7 @@ export class DragRef<T = any> {
10431043
if (previewTemplate && previewConfig) {
10441044
// Measure the element before we've inserted the preview
10451045
// since the insertion could throw off the measurement.
1046-
const rootRect = previewConfig.matchSize ? this._initialClientRect : null;
1046+
const rootRect = previewConfig.matchSize ? this._initialDomRect : null;
10471047
const viewRef = previewConfig.viewContainer.createEmbeddedView(
10481048
previewTemplate,
10491049
previewConfig.context,
@@ -1061,7 +1061,7 @@ export class DragRef<T = any> {
10611061
}
10621062
} else {
10631063
preview = deepCloneNode(this._rootElement);
1064-
matchElementSize(preview, this._initialClientRect!);
1064+
matchElementSize(preview, this._initialDomRect!);
10651065

10661066
if (this._initialTransform) {
10671067
preview.style.transform = this._initialTransform;
@@ -1179,7 +1179,7 @@ export class DragRef<T = any> {
11791179
* @param event Event that initiated the dragging.
11801180
*/
11811181
private _getPointerPositionInElement(
1182-
elementRect: ClientRect,
1182+
elementRect: DOMRect,
11831183
referenceElement: HTMLElement,
11841184
event: MouseEvent | TouchEvent,
11851185
): Point {
@@ -1232,7 +1232,7 @@ export class DragRef<T = any> {
12321232
private _getConstrainedPointerPosition(point: Point): Point {
12331233
const dropContainerLock = this._dropContainer ? this._dropContainer.lockAxis : null;
12341234
let {x, y} = this.constrainPosition
1235-
? this.constrainPosition(point, this, this._initialClientRect!, this._pickupPositionInElement)
1235+
? this.constrainPosition(point, this, this._initialDomRect!, this._pickupPositionInElement)
12361236
: point;
12371237

12381238
if (this.lockAxis === 'x' || dropContainerLock === 'x') {
@@ -1452,14 +1452,14 @@ export class DragRef<T = any> {
14521452
if (scrollDifference) {
14531453
const target = _getEventTarget<HTMLElement | Document>(event)!;
14541454

1455-
// ClientRect dimensions are based on the scroll position of the page and its parent
1456-
// node so we have to update the cached boundary ClientRect if the user has scrolled.
1455+
// DOMRect dimensions are based on the scroll position of the page and its parent
1456+
// node so we have to update the cached boundary DOMRect if the user has scrolled.
14571457
if (
14581458
this._boundaryRect &&
14591459
target !== this._boundaryElement &&
14601460
target.contains(this._boundaryElement)
14611461
) {
1462-
adjustClientRect(this._boundaryRect, scrollDifference.top, scrollDifference.left);
1462+
adjustDomRect(this._boundaryRect, scrollDifference.top, scrollDifference.left);
14631463
}
14641464

14651465
this._pickupPositionOnPage.x += scrollDifference.left;
@@ -1528,13 +1528,13 @@ export class DragRef<T = any> {
15281528
}
15291529

15301530
/** Lazily resolves and returns the dimensions of the preview. */
1531-
private _getPreviewRect(): ClientRect {
1531+
private _getPreviewRect(): DOMRect {
15321532
// Cache the preview element rect if we haven't cached it already or if
15331533
// we cached it too early before the element dimensions were computed.
15341534
if (!this._previewRect || (!this._previewRect.width && !this._previewRect.height)) {
15351535
this._previewRect = this._preview
15361536
? this._preview.getBoundingClientRect()
1537-
: this._initialClientRect!;
1537+
: this._initialDomRect!;
15381538
}
15391539

15401540
return this._previewRect;
@@ -1608,7 +1608,7 @@ function getRootNode(viewRef: EmbeddedViewRef<any>, _document: Document): HTMLEl
16081608
* @param target Element that needs to be resized.
16091609
* @param sourceRect Dimensions of the source element.
16101610
*/
1611-
function matchElementSize(target: HTMLElement, sourceRect: ClientRect): void {
1611+
function matchElementSize(target: HTMLElement, sourceRect: DOMRect): void {
16121612
target.style.width = `${sourceRect.width}px`;
16131613
target.style.height = `${sourceRect.height}px`;
16141614
target.style.transform = getTransform(sourceRect.left, sourceRect.top);

0 commit comments

Comments
 (0)