@angular/cdk 17.0.4 → 17.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/dialog/index.d.ts +1 -0
- package/drag-drop/index.d.ts +5 -5
- package/esm2022/a11y/aria-describer/aria-reference.mjs +8 -5
- package/esm2022/a11y/focus-trap/focus-trap.mjs +16 -11
- package/esm2022/collections/selection-model.mjs +5 -4
- package/esm2022/dialog/dialog-container.mjs +14 -9
- package/esm2022/drag-drop/directives/drag.mjs +1 -1
- package/esm2022/drag-drop/dom/dom-rect.mjs +64 -0
- package/esm2022/drag-drop/dom/parent-position-tracker.mjs +3 -3
- package/esm2022/drag-drop/drag-ref.mjs +13 -13
- package/esm2022/drag-drop/drop-list-ref.mjs +34 -20
- package/esm2022/drag-drop/sorting/single-axis-sort-strategy.mjs +5 -5
- package/esm2022/overlay/position/flexible-connected-position-strategy.mjs +5 -5
- package/esm2022/overlay/position/scroll-clip.mjs +1 -1
- package/esm2022/scrolling/viewport-ruler.mjs +2 -2
- package/esm2022/scrolling/virtual-scrollable.mjs +1 -1
- package/esm2022/version.mjs +1 -1
- package/fesm2022/a11y.mjs +21 -13
- package/fesm2022/a11y.mjs.map +1 -1
- package/fesm2022/cdk.mjs +1 -1
- package/fesm2022/cdk.mjs.map +1 -1
- package/fesm2022/collections.mjs +4 -3
- package/fesm2022/collections.mjs.map +1 -1
- package/fesm2022/dialog.mjs +13 -8
- package/fesm2022/dialog.mjs.map +1 -1
- package/fesm2022/drag-drop.mjs +71 -57
- package/fesm2022/drag-drop.mjs.map +1 -1
- package/fesm2022/overlay.mjs +4 -4
- package/fesm2022/overlay.mjs.map +1 -1
- package/fesm2022/scrolling.mjs +1 -1
- package/fesm2022/scrolling.mjs.map +1 -1
- package/overlay/index.d.ts +1 -1
- package/package.json +1 -1
- package/schematics/ng-add/index.js +1 -1
- package/schematics/ng-add/index.mjs +1 -1
- package/schematics/ng-generate/drag-drop/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.ts.template +3 -3
- package/scrolling/index.d.ts +2 -2
- package/esm2022/drag-drop/dom/client-rect.mjs +0 -64
package/fesm2022/drag-drop.mjs
CHANGED
|
@@ -101,27 +101,27 @@ function parseCssPropertyValue(computedStyle, name) {
|
|
|
101
101
|
return value.split(',').map(part => part.trim());
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
/** Gets a mutable version of an element's bounding `
|
|
104
|
+
/** Gets a mutable version of an element's bounding `DOMRect`. */
|
|
105
105
|
function getMutableClientRect(element) {
|
|
106
|
-
const
|
|
106
|
+
const rect = element.getBoundingClientRect();
|
|
107
107
|
// We need to clone the `clientRect` here, because all the values on it are readonly
|
|
108
108
|
// and we need to be able to update them. Also we can't use a spread here, because
|
|
109
|
-
// the values on a `
|
|
109
|
+
// the values on a `DOMRect` aren't own properties. See:
|
|
110
110
|
// https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect#Notes
|
|
111
111
|
return {
|
|
112
|
-
top:
|
|
113
|
-
right:
|
|
114
|
-
bottom:
|
|
115
|
-
left:
|
|
116
|
-
width:
|
|
117
|
-
height:
|
|
118
|
-
x:
|
|
119
|
-
y:
|
|
112
|
+
top: rect.top,
|
|
113
|
+
right: rect.right,
|
|
114
|
+
bottom: rect.bottom,
|
|
115
|
+
left: rect.left,
|
|
116
|
+
width: rect.width,
|
|
117
|
+
height: rect.height,
|
|
118
|
+
x: rect.x,
|
|
119
|
+
y: rect.y,
|
|
120
120
|
};
|
|
121
121
|
}
|
|
122
122
|
/**
|
|
123
|
-
* Checks whether some coordinates are within a `
|
|
124
|
-
* @param clientRect
|
|
123
|
+
* Checks whether some coordinates are within a `DOMRect`.
|
|
124
|
+
* @param clientRect DOMRect that is being checked.
|
|
125
125
|
* @param x Coordinates along the X axis.
|
|
126
126
|
* @param y Coordinates along the Y axis.
|
|
127
127
|
*/
|
|
@@ -130,25 +130,25 @@ function isInsideClientRect(clientRect, x, y) {
|
|
|
130
130
|
return y >= top && y <= bottom && x >= left && x <= right;
|
|
131
131
|
}
|
|
132
132
|
/**
|
|
133
|
-
* Updates the top/left positions of a `
|
|
134
|
-
* @param
|
|
133
|
+
* Updates the top/left positions of a `DOMRect`, as well as their bottom/right counterparts.
|
|
134
|
+
* @param domRect `DOMRect` that should be updated.
|
|
135
135
|
* @param top Amount to add to the `top` position.
|
|
136
136
|
* @param left Amount to add to the `left` position.
|
|
137
137
|
*/
|
|
138
|
-
function
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
138
|
+
function adjustDomRect(domRect, top, left) {
|
|
139
|
+
domRect.top += top;
|
|
140
|
+
domRect.bottom = domRect.top + domRect.height;
|
|
141
|
+
domRect.left += left;
|
|
142
|
+
domRect.right = domRect.left + domRect.width;
|
|
143
143
|
}
|
|
144
144
|
/**
|
|
145
|
-
* Checks whether the pointer coordinates are close to a
|
|
146
|
-
* @param rect
|
|
147
|
-
* @param threshold Threshold around the
|
|
145
|
+
* Checks whether the pointer coordinates are close to a DOMRect.
|
|
146
|
+
* @param rect DOMRect to check against.
|
|
147
|
+
* @param threshold Threshold around the DOMRect.
|
|
148
148
|
* @param pointerX Coordinates along the X axis.
|
|
149
149
|
* @param pointerY Coordinates along the Y axis.
|
|
150
150
|
*/
|
|
151
|
-
function
|
|
151
|
+
function isPointerNearDomRect(rect, threshold, pointerX, pointerY) {
|
|
152
152
|
const { top, right, bottom, left, width, height } = rect;
|
|
153
153
|
const xThreshold = width * threshold;
|
|
154
154
|
const yThreshold = height * threshold;
|
|
@@ -207,7 +207,7 @@ class ParentPositionTracker {
|
|
|
207
207
|
// parents that are inside the element that was scrolled.
|
|
208
208
|
this.positions.forEach((position, node) => {
|
|
209
209
|
if (position.clientRect && target !== node && target.contains(node)) {
|
|
210
|
-
|
|
210
|
+
adjustDomRect(position.clientRect, topDifference, leftDifference);
|
|
211
211
|
}
|
|
212
212
|
});
|
|
213
213
|
scrollPosition.top = newTop;
|
|
@@ -438,7 +438,7 @@ class DragRef {
|
|
|
438
438
|
else {
|
|
439
439
|
// If there's a position constraint function, we want the element's top/left to be at the
|
|
440
440
|
// specific position on the page. Use the initial position as a reference if that's the case.
|
|
441
|
-
const offset = this.constrainPosition ? this.
|
|
441
|
+
const offset = this.constrainPosition ? this._initialDomRect : this._pickupPositionOnPage;
|
|
442
442
|
const activeTransform = this._activeTransform;
|
|
443
443
|
activeTransform.x = constrainedPointerPosition.x - offset.x + this._passiveTransform.x;
|
|
444
444
|
activeTransform.y = constrainedPointerPosition.y - offset.y + this._passiveTransform.y;
|
|
@@ -844,7 +844,7 @@ class DragRef {
|
|
|
844
844
|
// Avoid multiple subscriptions and memory leaks when multi touch
|
|
845
845
|
// (isDragging check above isn't enough because of possible temporal and/or dimensional delays)
|
|
846
846
|
this._removeSubscriptions();
|
|
847
|
-
this.
|
|
847
|
+
this._initialDomRect = this._rootElement.getBoundingClientRect();
|
|
848
848
|
this._pointerMoveSubscription = this._dragDropRegistry.pointerMove.subscribe(this._pointerMove);
|
|
849
849
|
this._pointerUpSubscription = this._dragDropRegistry.pointerUp.subscribe(this._pointerUp);
|
|
850
850
|
this._scrollSubscription = this._dragDropRegistry
|
|
@@ -860,7 +860,7 @@ class DragRef {
|
|
|
860
860
|
this._pickupPositionInElement =
|
|
861
861
|
previewTemplate && previewTemplate.template && !previewTemplate.matchSize
|
|
862
862
|
? { x: 0, y: 0 }
|
|
863
|
-
: this._getPointerPositionInElement(this.
|
|
863
|
+
: this._getPointerPositionInElement(this._initialDomRect, referenceElement, event);
|
|
864
864
|
const pointerPosition = (this._pickupPositionOnPage =
|
|
865
865
|
this._lastKnownPointerPosition =
|
|
866
866
|
this._getPointerPositionOnPage(event));
|
|
@@ -879,7 +879,7 @@ class DragRef {
|
|
|
879
879
|
this._anchor.parentNode.replaceChild(this._rootElement, this._anchor);
|
|
880
880
|
this._destroyPreview();
|
|
881
881
|
this._destroyPlaceholder();
|
|
882
|
-
this.
|
|
882
|
+
this._initialDomRect =
|
|
883
883
|
this._boundaryRect =
|
|
884
884
|
this._previewRect =
|
|
885
885
|
this._initialTransform =
|
|
@@ -967,7 +967,7 @@ class DragRef {
|
|
|
967
967
|
if (previewTemplate && previewConfig) {
|
|
968
968
|
// Measure the element before we've inserted the preview
|
|
969
969
|
// since the insertion could throw off the measurement.
|
|
970
|
-
const rootRect = previewConfig.matchSize ? this.
|
|
970
|
+
const rootRect = previewConfig.matchSize ? this._initialDomRect : null;
|
|
971
971
|
const viewRef = previewConfig.viewContainer.createEmbeddedView(previewTemplate, previewConfig.context);
|
|
972
972
|
viewRef.detectChanges();
|
|
973
973
|
preview = getRootNode(viewRef, this._document);
|
|
@@ -981,7 +981,7 @@ class DragRef {
|
|
|
981
981
|
}
|
|
982
982
|
else {
|
|
983
983
|
preview = deepCloneNode(this._rootElement);
|
|
984
|
-
matchElementSize(preview, this.
|
|
984
|
+
matchElementSize(preview, this._initialDomRect);
|
|
985
985
|
if (this._initialTransform) {
|
|
986
986
|
preview.style.transform = this._initialTransform;
|
|
987
987
|
}
|
|
@@ -1118,7 +1118,7 @@ class DragRef {
|
|
|
1118
1118
|
_getConstrainedPointerPosition(point) {
|
|
1119
1119
|
const dropContainerLock = this._dropContainer ? this._dropContainer.lockAxis : null;
|
|
1120
1120
|
let { x, y } = this.constrainPosition
|
|
1121
|
-
? this.constrainPosition(point, this, this.
|
|
1121
|
+
? this.constrainPosition(point, this, this._initialDomRect, this._pickupPositionInElement)
|
|
1122
1122
|
: point;
|
|
1123
1123
|
if (this.lockAxis === 'x' || dropContainerLock === 'x') {
|
|
1124
1124
|
y =
|
|
@@ -1302,12 +1302,12 @@ class DragRef {
|
|
|
1302
1302
|
const scrollDifference = this._parentPositions.handleScroll(event);
|
|
1303
1303
|
if (scrollDifference) {
|
|
1304
1304
|
const target = _getEventTarget(event);
|
|
1305
|
-
//
|
|
1306
|
-
// node so we have to update the cached boundary
|
|
1305
|
+
// DOMRect dimensions are based on the scroll position of the page and its parent
|
|
1306
|
+
// node so we have to update the cached boundary DOMRect if the user has scrolled.
|
|
1307
1307
|
if (this._boundaryRect &&
|
|
1308
1308
|
target !== this._boundaryElement &&
|
|
1309
1309
|
target.contains(this._boundaryElement)) {
|
|
1310
|
-
|
|
1310
|
+
adjustDomRect(this._boundaryRect, scrollDifference.top, scrollDifference.left);
|
|
1311
1311
|
}
|
|
1312
1312
|
this._pickupPositionOnPage.x += scrollDifference.left;
|
|
1313
1313
|
this._pickupPositionOnPage.y += scrollDifference.top;
|
|
@@ -1364,7 +1364,7 @@ class DragRef {
|
|
|
1364
1364
|
if (!this._previewRect || (!this._previewRect.width && !this._previewRect.height)) {
|
|
1365
1365
|
this._previewRect = this._preview
|
|
1366
1366
|
? this._preview.getBoundingClientRect()
|
|
1367
|
-
: this.
|
|
1367
|
+
: this._initialDomRect;
|
|
1368
1368
|
}
|
|
1369
1369
|
return this._previewRect;
|
|
1370
1370
|
}
|
|
@@ -1552,11 +1552,11 @@ class SingleAxisSortStrategy {
|
|
|
1552
1552
|
// Round the transforms since some browsers will
|
|
1553
1553
|
// blur the elements, for sub-pixel transforms.
|
|
1554
1554
|
elementToOffset.style.transform = combineTransforms(`translate3d(${Math.round(sibling.offset)}px, 0, 0)`, sibling.initialTransform);
|
|
1555
|
-
|
|
1555
|
+
adjustDomRect(sibling.clientRect, 0, offset);
|
|
1556
1556
|
}
|
|
1557
1557
|
else {
|
|
1558
1558
|
elementToOffset.style.transform = combineTransforms(`translate3d(0, ${Math.round(sibling.offset)}px, 0)`, sibling.initialTransform);
|
|
1559
|
-
|
|
1559
|
+
adjustDomRect(sibling.clientRect, offset, 0);
|
|
1560
1560
|
}
|
|
1561
1561
|
});
|
|
1562
1562
|
// Note that it's important that we do this after the client rects have been adjusted.
|
|
@@ -1668,7 +1668,7 @@ class SingleAxisSortStrategy {
|
|
|
1668
1668
|
// we can avoid inconsistent behavior where we might be measuring the element before
|
|
1669
1669
|
// its position has changed.
|
|
1670
1670
|
this._itemPositions.forEach(({ clientRect }) => {
|
|
1671
|
-
|
|
1671
|
+
adjustDomRect(clientRect, topDifference, leftDifference);
|
|
1672
1672
|
});
|
|
1673
1673
|
// We need two loops for this, because we want all of the cached
|
|
1674
1674
|
// positions to be up-to-date before we re-sort the item.
|
|
@@ -2077,8 +2077,8 @@ class DropListRef {
|
|
|
2077
2077
|
_sortItem(item, pointerX, pointerY, pointerDelta) {
|
|
2078
2078
|
// Don't sort the item if sorting is disabled or it's out of range.
|
|
2079
2079
|
if (this.sortingDisabled ||
|
|
2080
|
-
!this.
|
|
2081
|
-
!
|
|
2080
|
+
!this._domRect ||
|
|
2081
|
+
!isPointerNearDomRect(this._domRect, DROP_PROXIMITY_THRESHOLD, pointerX, pointerY)) {
|
|
2082
2082
|
return;
|
|
2083
2083
|
}
|
|
2084
2084
|
const result = this._sortStrategy.sort(item, pointerX, pointerY, pointerDelta);
|
|
@@ -2111,8 +2111,8 @@ class DropListRef {
|
|
|
2111
2111
|
if (element === this._document || !position.clientRect || scrollNode) {
|
|
2112
2112
|
return;
|
|
2113
2113
|
}
|
|
2114
|
-
if (
|
|
2115
|
-
[verticalScrollDirection, horizontalScrollDirection] = getElementScrollDirections(element, position.clientRect, pointerX, pointerY);
|
|
2114
|
+
if (isPointerNearDomRect(position.clientRect, DROP_PROXIMITY_THRESHOLD, pointerX, pointerY)) {
|
|
2115
|
+
[verticalScrollDirection, horizontalScrollDirection] = getElementScrollDirections(element, position.clientRect, this._sortStrategy.direction, pointerX, pointerY);
|
|
2116
2116
|
if (verticalScrollDirection || horizontalScrollDirection) {
|
|
2117
2117
|
scrollNode = element;
|
|
2118
2118
|
}
|
|
@@ -2121,7 +2121,7 @@ class DropListRef {
|
|
|
2121
2121
|
// Otherwise check if we can start scrolling the viewport.
|
|
2122
2122
|
if (!verticalScrollDirection && !horizontalScrollDirection) {
|
|
2123
2123
|
const { width, height } = this._viewportRuler.getViewportSize();
|
|
2124
|
-
const
|
|
2124
|
+
const domRect = {
|
|
2125
2125
|
width,
|
|
2126
2126
|
height,
|
|
2127
2127
|
top: 0,
|
|
@@ -2129,8 +2129,8 @@ class DropListRef {
|
|
|
2129
2129
|
bottom: height,
|
|
2130
2130
|
left: 0,
|
|
2131
2131
|
};
|
|
2132
|
-
verticalScrollDirection = getVerticalScrollDirection(
|
|
2133
|
-
horizontalScrollDirection = getHorizontalScrollDirection(
|
|
2132
|
+
verticalScrollDirection = getVerticalScrollDirection(domRect, pointerY);
|
|
2133
|
+
horizontalScrollDirection = getHorizontalScrollDirection(domRect, pointerX);
|
|
2134
2134
|
scrollNode = window;
|
|
2135
2135
|
}
|
|
2136
2136
|
if (scrollNode &&
|
|
@@ -2172,8 +2172,8 @@ class DropListRef {
|
|
|
2172
2172
|
const element = coerceElement(this.element);
|
|
2173
2173
|
this._parentPositions.cache(this._scrollableElements);
|
|
2174
2174
|
// The list element is always in the `scrollableElements`
|
|
2175
|
-
// so we can take advantage of the cached `
|
|
2176
|
-
this.
|
|
2175
|
+
// so we can take advantage of the cached `DOMRect`.
|
|
2176
|
+
this._domRect = this._parentPositions.positions.get(element).clientRect;
|
|
2177
2177
|
}
|
|
2178
2178
|
/** Resets the container to its initial state. */
|
|
2179
2179
|
_reset() {
|
|
@@ -2192,7 +2192,7 @@ class DropListRef {
|
|
|
2192
2192
|
* @param y Pointer position along the Y axis.
|
|
2193
2193
|
*/
|
|
2194
2194
|
_isOverContainer(x, y) {
|
|
2195
|
-
return this.
|
|
2195
|
+
return this._domRect != null && isInsideClientRect(this._domRect, x, y);
|
|
2196
2196
|
}
|
|
2197
2197
|
/**
|
|
2198
2198
|
* Figures out whether an item should be moved into a sibling
|
|
@@ -2211,8 +2211,8 @@ class DropListRef {
|
|
|
2211
2211
|
* @param y Position of the item along the Y axis.
|
|
2212
2212
|
*/
|
|
2213
2213
|
_canReceive(item, x, y) {
|
|
2214
|
-
if (!this.
|
|
2215
|
-
!isInsideClientRect(this.
|
|
2214
|
+
if (!this._domRect ||
|
|
2215
|
+
!isInsideClientRect(this._domRect, x, y) ||
|
|
2216
2216
|
!this.enterPredicate(item, this)) {
|
|
2217
2217
|
return false;
|
|
2218
2218
|
}
|
|
@@ -2223,7 +2223,7 @@ class DropListRef {
|
|
|
2223
2223
|
return false;
|
|
2224
2224
|
}
|
|
2225
2225
|
const nativeElement = coerceElement(this.element);
|
|
2226
|
-
// The `
|
|
2226
|
+
// The `DOMRect`, that we're using to find the container over which the user is
|
|
2227
2227
|
// hovering, doesn't give us any information on whether the element has been scrolled
|
|
2228
2228
|
// out of the view or whether it's overlapping with other containers. This means that
|
|
2229
2229
|
// we could end up transferring the item into a container that's invisible or is positioned
|
|
@@ -2341,10 +2341,11 @@ function getHorizontalScrollDirection(clientRect, pointerX) {
|
|
|
2341
2341
|
* assuming that the user's pointer is already within it scrollable region.
|
|
2342
2342
|
* @param element Element for which we should calculate the scroll direction.
|
|
2343
2343
|
* @param clientRect Bounding client rectangle of the element.
|
|
2344
|
+
* @param direction Layout direction of the drop list.
|
|
2344
2345
|
* @param pointerX Position of the user's pointer along the x axis.
|
|
2345
2346
|
* @param pointerY Position of the user's pointer along the y axis.
|
|
2346
2347
|
*/
|
|
2347
|
-
function getElementScrollDirections(element, clientRect, pointerX, pointerY) {
|
|
2348
|
+
function getElementScrollDirections(element, clientRect, direction, pointerX, pointerY) {
|
|
2348
2349
|
const computedVertical = getVerticalScrollDirection(clientRect, pointerY);
|
|
2349
2350
|
const computedHorizontal = getHorizontalScrollDirection(clientRect, pointerX);
|
|
2350
2351
|
let verticalScrollDirection = 0 /* AutoScrollVerticalDirection.NONE */;
|
|
@@ -2366,13 +2367,26 @@ function getElementScrollDirections(element, clientRect, pointerX, pointerY) {
|
|
|
2366
2367
|
}
|
|
2367
2368
|
if (computedHorizontal) {
|
|
2368
2369
|
const scrollLeft = element.scrollLeft;
|
|
2369
|
-
if (
|
|
2370
|
-
if (
|
|
2370
|
+
if (direction === 'rtl') {
|
|
2371
|
+
if (computedHorizontal === 2 /* AutoScrollHorizontalDirection.RIGHT */) {
|
|
2372
|
+
// In RTL `scrollLeft` will be negative when scrolled.
|
|
2373
|
+
if (scrollLeft < 0) {
|
|
2374
|
+
horizontalScrollDirection = 2 /* AutoScrollHorizontalDirection.RIGHT */;
|
|
2375
|
+
}
|
|
2376
|
+
}
|
|
2377
|
+
else if (element.scrollWidth + scrollLeft > element.clientWidth) {
|
|
2371
2378
|
horizontalScrollDirection = 1 /* AutoScrollHorizontalDirection.LEFT */;
|
|
2372
2379
|
}
|
|
2373
2380
|
}
|
|
2374
|
-
else
|
|
2375
|
-
|
|
2381
|
+
else {
|
|
2382
|
+
if (computedHorizontal === 1 /* AutoScrollHorizontalDirection.LEFT */) {
|
|
2383
|
+
if (scrollLeft > 0) {
|
|
2384
|
+
horizontalScrollDirection = 1 /* AutoScrollHorizontalDirection.LEFT */;
|
|
2385
|
+
}
|
|
2386
|
+
}
|
|
2387
|
+
else if (element.scrollWidth - scrollLeft > element.clientWidth) {
|
|
2388
|
+
horizontalScrollDirection = 2 /* AutoScrollHorizontalDirection.RIGHT */;
|
|
2389
|
+
}
|
|
2376
2390
|
}
|
|
2377
2391
|
}
|
|
2378
2392
|
return [verticalScrollDirection, horizontalScrollDirection];
|