@angular/cdk 9.2.0 → 9.2.1

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.
Files changed (63) hide show
  1. package/a11y/focus-monitor/focus-monitor.d.ts +6 -0
  2. package/a11y/index.metadata.json +1 -1
  3. package/bundles/cdk-a11y.umd.js +71 -64
  4. package/bundles/cdk-a11y.umd.js.map +1 -1
  5. package/bundles/cdk-a11y.umd.min.js +8 -8
  6. package/bundles/cdk-a11y.umd.min.js.map +1 -1
  7. package/bundles/cdk-drag-drop.umd.js +108 -79
  8. package/bundles/cdk-drag-drop.umd.js.map +1 -1
  9. package/bundles/cdk-drag-drop.umd.min.js +15 -8
  10. package/bundles/cdk-drag-drop.umd.min.js.map +1 -1
  11. package/bundles/cdk-tree.umd.js +8 -4
  12. package/bundles/cdk-tree.umd.js.map +1 -1
  13. package/bundles/cdk-tree.umd.min.js +1 -1
  14. package/bundles/cdk-tree.umd.min.js.map +1 -1
  15. package/bundles/cdk.umd.js +1 -1
  16. package/bundles/cdk.umd.js.map +1 -1
  17. package/bundles/cdk.umd.min.js +1 -1
  18. package/bundles/cdk.umd.min.js.map +1 -1
  19. package/drag-drop/client-rect.d.ts +31 -0
  20. package/drag-drop/directives/config.d.ts +1 -0
  21. package/drag-drop/directives/drop-list.d.ts +4 -3
  22. package/drag-drop/drag-ref.d.ts +4 -0
  23. package/drag-drop/index.metadata.json +1 -1
  24. package/esm2015/a11y/focus-monitor/focus-monitor.js +71 -65
  25. package/esm2015/a11y/high-contrast-mode/high-contrast-mode-detector.js +8 -4
  26. package/esm2015/drag-drop/client-rect.js +75 -0
  27. package/esm2015/drag-drop/directives/config.js +3 -1
  28. package/esm2015/drag-drop/directives/drag.js +3 -2
  29. package/esm2015/drag-drop/directives/drop-list.js +24 -18
  30. package/esm2015/drag-drop/drag-ref.js +55 -21
  31. package/esm2015/drag-drop/drop-list-ref.js +5 -64
  32. package/esm2015/tree/padding.js +9 -10
  33. package/esm2015/version.js +1 -1
  34. package/esm5/a11y/focus-monitor/focus-monitor.js +49 -44
  35. package/esm5/a11y/high-contrast-mode/high-contrast-mode-detector.js +7 -4
  36. package/esm5/drag-drop/client-rect.js +60 -0
  37. package/esm5/drag-drop/directives/config.js +1 -1
  38. package/esm5/drag-drop/directives/drag.js +3 -2
  39. package/esm5/drag-drop/directives/drop-list.js +13 -10
  40. package/esm5/drag-drop/drag-ref.js +33 -17
  41. package/esm5/drag-drop/drop-list-ref.js +5 -54
  42. package/esm5/tree/padding.js +9 -5
  43. package/esm5/version.js +1 -1
  44. package/fesm2015/a11y.js +101 -92
  45. package/fesm2015/a11y.js.map +1 -1
  46. package/fesm2015/cdk.js +1 -1
  47. package/fesm2015/cdk.js.map +1 -1
  48. package/fesm2015/drag-drop.js +158 -101
  49. package/fesm2015/drag-drop.js.map +1 -1
  50. package/fesm2015/tree.js +8 -9
  51. package/fesm2015/tree.js.map +1 -1
  52. package/fesm5/a11y.js +71 -64
  53. package/fesm5/a11y.js.map +1 -1
  54. package/fesm5/cdk.js +1 -1
  55. package/fesm5/cdk.js.map +1 -1
  56. package/fesm5/drag-drop.js +108 -79
  57. package/fesm5/drag-drop.js.map +1 -1
  58. package/fesm5/tree.js +8 -4
  59. package/fesm5/tree.js.map +1 -1
  60. package/package.json +1 -1
  61. package/schematics/ng-add/index.js +1 -1
  62. package/tree/index.metadata.json +1 -1
  63. package/tree/padding.d.ts +6 -2
@@ -78,6 +78,66 @@
78
78
  return value.split(',').map(function (part) { return part.trim(); });
79
79
  }
80
80
 
81
+ /**
82
+ * @license
83
+ * Copyright Google LLC All Rights Reserved.
84
+ *
85
+ * Use of this source code is governed by an MIT-style license that can be
86
+ * found in the LICENSE file at https://angular.io/license
87
+ */
88
+ /** Gets a mutable version of an element's bounding `ClientRect`. */
89
+ function getMutableClientRect(element) {
90
+ var clientRect = element.getBoundingClientRect();
91
+ // We need to clone the `clientRect` here, because all the values on it are readonly
92
+ // and we need to be able to update them. Also we can't use a spread here, because
93
+ // the values on a `ClientRect` aren't own properties. See:
94
+ // https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect#Notes
95
+ return {
96
+ top: clientRect.top,
97
+ right: clientRect.right,
98
+ bottom: clientRect.bottom,
99
+ left: clientRect.left,
100
+ width: clientRect.width,
101
+ height: clientRect.height
102
+ };
103
+ }
104
+ /**
105
+ * Checks whether some coordinates are within a `ClientRect`.
106
+ * @param clientRect ClientRect that is being checked.
107
+ * @param x Coordinates along the X axis.
108
+ * @param y Coordinates along the Y axis.
109
+ */
110
+ function isInsideClientRect(clientRect, x, y) {
111
+ var top = clientRect.top, bottom = clientRect.bottom, left = clientRect.left, right = clientRect.right;
112
+ return y >= top && y <= bottom && x >= left && x <= right;
113
+ }
114
+ /**
115
+ * Updates the top/left positions of a `ClientRect`, as well as their bottom/right counterparts.
116
+ * @param clientRect `ClientRect` that should be updated.
117
+ * @param top Amount to add to the `top` position.
118
+ * @param left Amount to add to the `left` position.
119
+ */
120
+ function adjustClientRect(clientRect, top, left) {
121
+ clientRect.top += top;
122
+ clientRect.bottom = clientRect.top + clientRect.height;
123
+ clientRect.left += left;
124
+ clientRect.right = clientRect.left + clientRect.width;
125
+ }
126
+ /**
127
+ * Checks whether the pointer coordinates are close to a ClientRect.
128
+ * @param rect ClientRect to check against.
129
+ * @param threshold Threshold around the ClientRect.
130
+ * @param pointerX Coordinates along the X axis.
131
+ * @param pointerY Coordinates along the Y axis.
132
+ */
133
+ function isPointerNearClientRect(rect, threshold, pointerX, pointerY) {
134
+ var top = rect.top, right = rect.right, bottom = rect.bottom, left = rect.left, width = rect.width, height = rect.height;
135
+ var xThreshold = width * threshold;
136
+ var yThreshold = height * threshold;
137
+ return pointerY > top - yThreshold && pointerY < bottom + yThreshold &&
138
+ pointerX > left - xThreshold && pointerX < right + xThreshold;
139
+ }
140
+
81
141
  /**
82
142
  * @license
83
143
  * Copyright Google LLC All Rights Reserved.
@@ -183,8 +243,8 @@
183
243
  // Prevent the default action as early as possible in order to block
184
244
  // native actions like dragging the selected text or images with the mouse.
185
245
  event.preventDefault();
246
+ var pointerPosition = _this._getPointerPositionOnPage(event);
186
247
  if (!_this._hasStartedDragging) {
187
- var pointerPosition = _this._getPointerPositionOnPage(event);
188
248
  var distanceX = Math.abs(pointerPosition.x - _this._pickupPositionOnPage.x);
189
249
  var distanceY = Math.abs(pointerPosition.y - _this._pickupPositionOnPage.y);
190
250
  var isOverThreshold = distanceX + distanceY >= _this._config.dragStartThreshold;
@@ -216,7 +276,7 @@
216
276
  _this._previewRect = (_this._preview || _this._rootElement).getBoundingClientRect();
217
277
  }
218
278
  }
219
- var constrainedPointerPosition = _this._getConstrainedPointerPosition(event);
279
+ var constrainedPointerPosition = _this._getConstrainedPointerPosition(pointerPosition);
220
280
  _this._hasMoved = true;
221
281
  _this._updatePointerDirectionDelta(constrainedPointerPosition);
222
282
  if (_this._dropContainer) {
@@ -319,13 +379,16 @@
319
379
  * dragging on an element that you might not have access to.
320
380
  */
321
381
  DragRef.prototype.withRootElement = function (rootElement) {
382
+ var _this = this;
322
383
  var element = coercion.coerceElement(rootElement);
323
384
  if (element !== this._rootElement) {
324
385
  if (this._rootElement) {
325
386
  this._removeRootElementListeners(this._rootElement);
326
387
  }
327
- element.addEventListener('mousedown', this._pointerDown, activeEventListenerOptions);
328
- element.addEventListener('touchstart', this._pointerDown, passiveEventListenerOptions);
388
+ this._ngZone.runOutsideAngular(function () {
389
+ element.addEventListener('mousedown', _this._pointerDown, activeEventListenerOptions);
390
+ element.addEventListener('touchstart', _this._pointerDown, passiveEventListenerOptions);
391
+ });
329
392
  this._initialTransform = undefined;
330
393
  this._rootElement = element;
331
394
  }
@@ -434,7 +497,7 @@
434
497
  DragRef.prototype._sortFromLastPointerPosition = function () {
435
498
  var position = this._pointerPositionAtLastDirectionChange;
436
499
  if (position && this._dropContainer) {
437
- this._updateActiveDropContainer(position);
500
+ this._updateActiveDropContainer(this._getConstrainedPointerPosition(position));
438
501
  }
439
502
  };
440
503
  /** Unsubscribes from the global subscriptions. */
@@ -586,10 +649,10 @@
586
649
  this._pointerMoveSubscription = this._dragDropRegistry.pointerMove.subscribe(this._pointerMove);
587
650
  this._pointerUpSubscription = this._dragDropRegistry.pointerUp.subscribe(this._pointerUp);
588
651
  this._scrollSubscription = this._dragDropRegistry.scroll.pipe(operators.startWith(null)).subscribe(function () {
589
- _this._scrollPosition = _this._viewportRuler.getViewportScrollPosition();
652
+ _this._updateOnScroll();
590
653
  });
591
654
  if (this._boundaryElement) {
592
- this._boundaryRect = this._boundaryElement.getBoundingClientRect();
655
+ this._boundaryRect = getMutableClientRect(this._boundaryElement);
593
656
  }
594
657
  // If we have a custom preview we can't know ahead of time how large it'll be so we position
595
658
  // it next to the cursor. The exception is when the consumer has opted into making the preview
@@ -713,7 +776,7 @@
713
776
  position: 'fixed',
714
777
  top: '0',
715
778
  left: '0',
716
- zIndex: '1000'
779
+ zIndex: "" + (this._config.zIndex || 1000)
717
780
  });
718
781
  toggleNativeDragInteractions(preview, false);
719
782
  preview.classList.add('cdk-drag-preview');
@@ -811,8 +874,7 @@
811
874
  };
812
875
  };
813
876
  /** Gets the pointer position on the page, accounting for any position constraints. */
814
- DragRef.prototype._getConstrainedPointerPosition = function (event) {
815
- var point = this._getPointerPositionOnPage(event);
877
+ DragRef.prototype._getConstrainedPointerPosition = function (point) {
816
878
  var constrainedPoint = this.constrainPosition ? this.constrainPosition(point, this) : point;
817
879
  var dropContainerLock = this._dropContainer ? this._dropContainer.lockAxis : null;
818
880
  if (this.lockAxis === 'x' || dropContainerLock === 'x') {
@@ -967,6 +1029,19 @@
967
1029
  }
968
1030
  return value ? value.mouse : 0;
969
1031
  };
1032
+ /** Updates the internal state of the draggable element when scrolling has occurred. */
1033
+ DragRef.prototype._updateOnScroll = function () {
1034
+ var oldScrollPosition = this._scrollPosition;
1035
+ var currentScrollPosition = this._viewportRuler.getViewportScrollPosition();
1036
+ // ClientRect dimensions are based on the page's scroll position so
1037
+ // we have to update the cached boundary ClientRect if the user has scrolled.
1038
+ if (oldScrollPosition && this._boundaryRect) {
1039
+ var topDifference = oldScrollPosition.top - currentScrollPosition.top;
1040
+ var leftDifference = oldScrollPosition.left - currentScrollPosition.left;
1041
+ adjustClientRect(this._boundaryRect, topDifference, leftDifference);
1042
+ }
1043
+ this._scrollPosition = currentScrollPosition;
1044
+ };
970
1045
  return DragRef;
971
1046
  }());
972
1047
  /**
@@ -1038,13 +1113,13 @@
1038
1113
  * If the root is not an HTML element it gets wrapped in one.
1039
1114
  */
1040
1115
  function getRootNode(viewRef, _document) {
1041
- var rootNode = viewRef.rootNodes[0];
1042
- if (rootNode.nodeType !== _document.ELEMENT_NODE) {
1043
- var wrapper = _document.createElement('div');
1044
- wrapper.appendChild(rootNode);
1045
- return wrapper;
1116
+ var rootNodes = viewRef.rootNodes;
1117
+ if (rootNodes.length === 1 && rootNodes[0].nodeType === _document.ELEMENT_NODE) {
1118
+ return rootNodes[0];
1046
1119
  }
1047
- return rootNode;
1120
+ var wrapper = _document.createElement('div');
1121
+ rootNodes.forEach(function (node) { return wrapper.appendChild(node); });
1122
+ return wrapper;
1048
1123
  }
1049
1124
  /**
1050
1125
  * Matches the target element's size to the source's size.
@@ -1635,7 +1710,8 @@
1635
1710
  */
1636
1711
  DropListRef.prototype._sortItem = function (item, pointerX, pointerY, pointerDelta) {
1637
1712
  // Don't sort the item if sorting is disabled or it's out of range.
1638
- if (this.sortingDisabled || !isPointerNearClientRect(this._clientRect, pointerX, pointerY)) {
1713
+ if (this.sortingDisabled ||
1714
+ !isPointerNearClientRect(this._clientRect, DROP_PROXIMITY_THRESHOLD, pointerX, pointerY)) {
1639
1715
  return;
1640
1716
  }
1641
1717
  var siblings = this._itemPositions;
@@ -1715,7 +1791,7 @@
1715
1791
  if (element === _this._document || !position.clientRect || scrollNode) {
1716
1792
  return;
1717
1793
  }
1718
- if (isPointerNearClientRect(position.clientRect, pointerX, pointerY)) {
1794
+ if (isPointerNearClientRect(position.clientRect, DROP_PROXIMITY_THRESHOLD, pointerX, pointerY)) {
1719
1795
  _a = __read(getElementScrollDirections(element, position.clientRect, pointerX, pointerY), 2), verticalScrollDirection = _a[0], horizontalScrollDirection = _a[1];
1720
1796
  if (verticalScrollDirection || horizontalScrollDirection) {
1721
1797
  scrollNode = element;
@@ -2029,31 +2105,6 @@
2029
2105
  };
2030
2106
  return DropListRef;
2031
2107
  }());
2032
- /**
2033
- * Updates the top/left positions of a `ClientRect`, as well as their bottom/right counterparts.
2034
- * @param clientRect `ClientRect` that should be updated.
2035
- * @param top Amount to add to the `top` position.
2036
- * @param left Amount to add to the `left` position.
2037
- */
2038
- function adjustClientRect(clientRect, top, left) {
2039
- clientRect.top += top;
2040
- clientRect.bottom = clientRect.top + clientRect.height;
2041
- clientRect.left += left;
2042
- clientRect.right = clientRect.left + clientRect.width;
2043
- }
2044
- /**
2045
- * Checks whether the pointer coordinates are close to a ClientRect.
2046
- * @param rect ClientRect to check against.
2047
- * @param pointerX Coordinates along the X axis.
2048
- * @param pointerY Coordinates along the Y axis.
2049
- */
2050
- function isPointerNearClientRect(rect, pointerX, pointerY) {
2051
- var top = rect.top, right = rect.right, bottom = rect.bottom, left = rect.left, width = rect.width, height = rect.height;
2052
- var xThreshold = width * DROP_PROXIMITY_THRESHOLD;
2053
- var yThreshold = height * DROP_PROXIMITY_THRESHOLD;
2054
- return pointerY > top - yThreshold && pointerY < bottom + yThreshold &&
2055
- pointerX > left - xThreshold && pointerX < right + xThreshold;
2056
- }
2057
2108
  /**
2058
2109
  * Finds the index of an item that matches a predicate function. Used as an equivalent
2059
2110
  * of `Array.prototype.findIndex` which isn't part of the standard Google typings.
@@ -2068,32 +2119,6 @@
2068
2119
  }
2069
2120
  return -1;
2070
2121
  }
2071
- /**
2072
- * Checks whether some coordinates are within a `ClientRect`.
2073
- * @param clientRect ClientRect that is being checked.
2074
- * @param x Coordinates along the X axis.
2075
- * @param y Coordinates along the Y axis.
2076
- */
2077
- function isInsideClientRect(clientRect, x, y) {
2078
- var top = clientRect.top, bottom = clientRect.bottom, left = clientRect.left, right = clientRect.right;
2079
- return y >= top && y <= bottom && x >= left && x <= right;
2080
- }
2081
- /** Gets a mutable version of an element's bounding `ClientRect`. */
2082
- function getMutableClientRect(element) {
2083
- var clientRect = element.getBoundingClientRect();
2084
- // We need to clone the `clientRect` here, because all the values on it are readonly
2085
- // and we need to be able to update them. Also we can't use a spread here, because
2086
- // the values on a `ClientRect` aren't own properties. See:
2087
- // https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect#Notes
2088
- return {
2089
- top: clientRect.top,
2090
- right: clientRect.right,
2091
- bottom: clientRect.bottom,
2092
- left: clientRect.left,
2093
- width: clientRect.width,
2094
- height: clientRect.height
2095
- };
2096
- }
2097
2122
  /**
2098
2123
  * Increments the vertical scroll position of a node.
2099
2124
  * @param node Node whose scroll position should change.
@@ -2638,7 +2663,8 @@
2638
2663
  dragStartThreshold: config && config.dragStartThreshold != null ?
2639
2664
  config.dragStartThreshold : 5,
2640
2665
  pointerDirectionChangeThreshold: config && config.pointerDirectionChangeThreshold != null ?
2641
- config.pointerDirectionChangeThreshold : 5
2666
+ config.pointerDirectionChangeThreshold : 5,
2667
+ zIndex: config === null || config === void 0 ? void 0 : config.zIndex
2642
2668
  });
2643
2669
  this._dragRef.data = this;
2644
2670
  if (config) {
@@ -3070,15 +3096,6 @@
3070
3096
  enumerable: true,
3071
3097
  configurable: true
3072
3098
  });
3073
- CdkDropList.prototype.ngAfterContentInit = function () {
3074
- // @breaking-change 11.0.0 Remove null check for _scrollDispatcher once it's required.
3075
- if (this._scrollDispatcher) {
3076
- var scrollableParents = this._scrollDispatcher
3077
- .getAncestorScrollContainers(this.element)
3078
- .map(function (scrollable) { return scrollable.getElementRef().nativeElement; });
3079
- this._dropListRef.withScrollableParents(scrollableParents);
3080
- }
3081
- };
3082
3099
  /** Registers an items with the drop list. */
3083
3100
  CdkDropList.prototype.addItem = function (item) {
3084
3101
  this._unsortedItems.add(item);
@@ -3187,6 +3204,18 @@
3187
3204
  }
3188
3205
  });
3189
3206
  }
3207
+ // Note that we resolve the scrollable parents here so that we delay the resolution
3208
+ // as long as possible, ensuring that the element is in its final place in the DOM.
3209
+ // @breaking-change 11.0.0 Remove null check for _scrollDispatcher once it's required.
3210
+ if (!_this._scrollableParentsResolved && _this._scrollDispatcher) {
3211
+ var scrollableParents = _this._scrollDispatcher
3212
+ .getAncestorScrollContainers(_this.element)
3213
+ .map(function (scrollable) { return scrollable.getElementRef().nativeElement; });
3214
+ _this._dropListRef.withScrollableParents(scrollableParents);
3215
+ // Only do this once since it involves traversing the DOM and the parents
3216
+ // shouldn't be able to change without the drop list being destroyed.
3217
+ _this._scrollableParentsResolved = true;
3218
+ }
3190
3219
  ref.disabled = _this.disabled;
3191
3220
  ref.lockAxis = _this.lockAxis;
3192
3221
  ref.sortingDisabled = coercion.coerceBooleanProperty(_this.sortingDisabled);