@angular/cdk 11.0.3 → 11.0.4

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 (69) hide show
  1. package/LICENSE +1 -1
  2. package/a11y/focus-monitor/focus-monitor.d.ts +6 -0
  3. package/a11y/index.metadata.json +1 -1
  4. package/bundles/cdk-a11y.umd.js +21 -9
  5. package/bundles/cdk-a11y.umd.js.map +1 -1
  6. package/bundles/cdk-a11y.umd.min.js +1 -8
  7. package/bundles/cdk-a11y.umd.min.js.map +1 -1
  8. package/bundles/cdk-drag-drop.umd.js +78 -40
  9. package/bundles/cdk-drag-drop.umd.js.map +1 -1
  10. package/bundles/cdk-drag-drop.umd.min.js +8 -8
  11. package/bundles/cdk-drag-drop.umd.min.js.map +1 -1
  12. package/bundles/cdk-overlay.umd.js +15 -7
  13. package/bundles/cdk-overlay.umd.js.map +1 -1
  14. package/bundles/cdk-overlay.umd.min.js +17 -24
  15. package/bundles/cdk-overlay.umd.min.js.map +1 -1
  16. package/bundles/cdk-platform.umd.js +1 -0
  17. package/bundles/cdk-platform.umd.js.map +1 -1
  18. package/bundles/cdk-platform.umd.min.js +1 -1
  19. package/bundles/cdk-platform.umd.min.js.map +1 -1
  20. package/bundles/cdk-scrolling.umd.js +9 -3
  21. package/bundles/cdk-scrolling.umd.js.map +1 -1
  22. package/bundles/cdk-scrolling.umd.min.js +2 -2
  23. package/bundles/cdk-scrolling.umd.min.js.map +1 -1
  24. package/bundles/cdk-tree.umd.js.map +1 -1
  25. package/bundles/cdk.umd.js +1 -1
  26. package/bundles/cdk.umd.js.map +1 -1
  27. package/bundles/cdk.umd.min.js +1 -1
  28. package/bundles/cdk.umd.min.js.map +1 -1
  29. package/drag-drop/directives/drag.d.ts +1 -1
  30. package/drag-drop/drag-drop-registry.d.ts +8 -1
  31. package/drag-drop/drag-ref.d.ts +2 -0
  32. package/drag-drop/drop-list-ref.d.ts +5 -1
  33. package/drag-drop/index.metadata.json +1 -1
  34. package/esm2015/a11y/focus-monitor/focus-monitor.js +18 -3
  35. package/esm2015/drag-drop/directives/drag.js +6 -4
  36. package/esm2015/drag-drop/drag-drop-registry.js +25 -12
  37. package/esm2015/drag-drop/drag-ref.js +10 -8
  38. package/esm2015/drag-drop/drop-list-ref.js +39 -19
  39. package/esm2015/overlay/scroll/block-scroll-strategy.js +13 -4
  40. package/esm2015/platform/features/scrolling.js +2 -1
  41. package/esm2015/scrolling/fixed-size-virtual-scroll.js +3 -2
  42. package/esm2015/scrolling/virtual-for-of.js +8 -4
  43. package/esm2015/tree/nested-node.js +1 -1
  44. package/esm2015/tree/padding.js +1 -1
  45. package/esm2015/tree/toggle.js +1 -1
  46. package/esm2015/tree/tree.js +1 -1
  47. package/esm2015/version.js +1 -1
  48. package/fesm2015/a11y.js +17 -2
  49. package/fesm2015/a11y.js.map +1 -1
  50. package/fesm2015/cdk.js +1 -1
  51. package/fesm2015/cdk.js.map +1 -1
  52. package/fesm2015/drag-drop.js +76 -39
  53. package/fesm2015/drag-drop.js.map +1 -1
  54. package/fesm2015/overlay.js +12 -4
  55. package/fesm2015/overlay.js.map +1 -1
  56. package/fesm2015/platform.js +1 -0
  57. package/fesm2015/platform.js.map +1 -1
  58. package/fesm2015/scrolling.js +9 -4
  59. package/fesm2015/scrolling.js.map +1 -1
  60. package/fesm2015/tree.js.map +1 -1
  61. package/overlay/index.metadata.json +1 -1
  62. package/package.json +1 -1
  63. package/schematics/ng-add/index.js +1 -1
  64. package/scrolling/index.metadata.json +1 -1
  65. package/tree/index.metadata.json +1 -1
  66. package/tree/nested-node.d.ts +3 -3
  67. package/tree/padding.d.ts +2 -2
  68. package/tree/toggle.d.ts +4 -4
  69. package/tree/tree.d.ts +5 -5
package/fesm2015/cdk.js CHANGED
@@ -8,7 +8,7 @@ import { Version } from '@angular/core';
8
8
  * found in the LICENSE file at https://angular.io/license
9
9
  */
10
10
  /** Current version of the Angular Component Development Kit. */
11
- const VERSION = new Version('11.0.3');
11
+ const VERSION = new Version('11.0.4');
12
12
 
13
13
  /**
14
14
  * @license
@@ -1 +1 @@
1
- {"version":3,"file":"cdk.js","sources":["../../../../../../src/cdk/version.ts","../../../../../../src/cdk/public-api.ts","../../../../../../src/cdk/index.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nimport {Version} from '@angular/core';\n\n/** Current version of the Angular Component Development Kit. */\nexport const VERSION = new Version('11.0.3');\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nexport * from './version';\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;AAAA;;;;;;;AAQA,AAEA;AACA,MAAa,OAAO,GAAG,IAAI,OAAO,CAAC,mBAAmB,CAAC;;ACXvD;;;;;;GAMG;;ACNH;;;;;;GAMG;;;;"}
1
+ {"version":3,"file":"cdk.js","sources":["../../../../../../src/cdk/version.ts","../../../../../../src/cdk/public-api.ts","../../../../../../src/cdk/index.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nimport {Version} from '@angular/core';\n\n/** Current version of the Angular Component Development Kit. */\nexport const VERSION = new Version('11.0.4');\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nexport * from './version';\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;AAAA;;;;;;;AAQA,AAEA;AACA,MAAa,OAAO,GAAG,IAAI,OAAO,CAAC,mBAAmB,CAAC;;ACXvD;;;;;;GAMG;;ACNH;;;;;;GAMG;;;;"}
@@ -389,9 +389,6 @@ class DragRef {
389
389
  };
390
390
  /** Handler that is invoked when the user moves their pointer after they've initiated a drag. */
391
391
  this._pointerMove = (event) => {
392
- // Prevent the default action as early as possible in order to block
393
- // native actions like dragging the selected text or images with the mouse.
394
- event.preventDefault();
395
392
  const pointerPosition = this._getPointerPositionOnPage(event);
396
393
  if (!this._hasStartedDragging) {
397
394
  const distanceX = Math.abs(pointerPosition.x - this._pickupPositionOnPage.x);
@@ -426,6 +423,10 @@ class DragRef {
426
423
  this._previewRect = (this._preview || this._rootElement).getBoundingClientRect();
427
424
  }
428
425
  }
426
+ // We prevent the default action down here so that we know that dragging has started. This is
427
+ // important for touch devices where doing this too early can unnecessarily block scrolling,
428
+ // if there's a dragging delay.
429
+ event.preventDefault();
429
430
  const constrainedPointerPosition = this._getConstrainedPointerPosition(pointerPosition);
430
431
  this._hasMoved = true;
431
432
  this._lastKnownPointerPosition = pointerPosition;
@@ -782,10 +783,11 @@ class DragRef {
782
783
  * @param event Browser event object that started the sequence.
783
784
  */
784
785
  _initializeDragSequence(referenceElement, event) {
785
- // Always stop propagation for the event that initializes
786
- // the dragging sequence, in order to prevent it from potentially
787
- // starting another sequence for a draggable parent somewhere up the DOM tree.
788
- event.stopPropagation();
786
+ // Stop propagation if the item is inside another
787
+ // draggable so we don't start multiple drag sequences.
788
+ if (this._config.parentDragRef) {
789
+ event.stopPropagation();
790
+ }
789
791
  const isDragging = this.isDragging();
790
792
  const isTouchSequence = isTouchEvent(event);
791
793
  const isAuxiliaryMouseButton = !isTouchSequence && event.button !== 0;
@@ -1458,6 +1460,8 @@ class DropListRef {
1458
1460
  * overlap with the swapped item after the swapping occurred.
1459
1461
  */
1460
1462
  this._previousSwap = { drag: null, delta: 0, overlaps: false };
1463
+ /** Draggable items in the container. */
1464
+ this._draggables = [];
1461
1465
  /** Drop lists that are connected to the current one. */
1462
1466
  this._siblings = [];
1463
1467
  /** Direction in which the list is oriented. */
@@ -1524,18 +1528,8 @@ class DropListRef {
1524
1528
  }
1525
1529
  /** Starts dragging an item. */
1526
1530
  start() {
1527
- const styles = coerceElement(this.element).style;
1528
- this.beforeStarted.next();
1529
- this._isDragging = true;
1530
- // We need to disable scroll snapping while the user is dragging, because it breaks automatic
1531
- // scrolling. The browser seems to round the value based on the snapping points which means
1532
- // that we can't increment/decrement the scroll position.
1533
- this._initialScrollSnap = styles.msScrollSnapType || styles.scrollSnapType || '';
1534
- styles.scrollSnapType = styles.msScrollSnapType = 'none';
1535
- this._cacheItems();
1536
- this._siblings.forEach(sibling => sibling._startReceiving(this));
1537
- this._viewportScrollSubscription.unsubscribe();
1538
- this._listenToScrollEvents();
1531
+ this._draggingStarted();
1532
+ this._notifyReceivingSiblings();
1539
1533
  }
1540
1534
  /**
1541
1535
  * Emits an event to indicate that the user moved an item into the container.
@@ -1546,7 +1540,7 @@ class DropListRef {
1546
1540
  * out automatically.
1547
1541
  */
1548
1542
  enter(item, pointerX, pointerY, index) {
1549
- this.start();
1543
+ this._draggingStarted();
1550
1544
  // If sorting is disabled, we want the item to return to its starting
1551
1545
  // position if the user is returning it to its initial container.
1552
1546
  let newIndex;
@@ -1598,6 +1592,8 @@ class DropListRef {
1598
1592
  // but we need to refresh them since the amount of items has changed and also parent rects.
1599
1593
  this._cacheItemPositions();
1600
1594
  this._cacheParentPositions();
1595
+ // Notify siblings at the end so that the item has been inserted into the `activeDraggables`.
1596
+ this._notifyReceivingSiblings();
1601
1597
  this.entered.next({ item, container: this, currentIndex: this.getItemIndex(item) });
1602
1598
  }
1603
1599
  /**
@@ -1720,7 +1716,7 @@ class DropListRef {
1720
1716
  */
1721
1717
  _sortItem(item, pointerX, pointerY, pointerDelta) {
1722
1718
  // Don't sort the item if sorting is disabled or it's out of range.
1723
- if (this.sortingDisabled ||
1719
+ if (this.sortingDisabled || !this._clientRect ||
1724
1720
  !isPointerNearClientRect(this._clientRect, DROP_PROXIMITY_THRESHOLD, pointerX, pointerY)) {
1725
1721
  return;
1726
1722
  }
@@ -1834,6 +1830,20 @@ class DropListRef {
1834
1830
  _stopScrolling() {
1835
1831
  this._stopScrollTimers.next();
1836
1832
  }
1833
+ /** Starts the dragging sequence within the list. */
1834
+ _draggingStarted() {
1835
+ const styles = coerceElement(this.element).style;
1836
+ this.beforeStarted.next();
1837
+ this._isDragging = true;
1838
+ // We need to disable scroll snapping while the user is dragging, because it breaks automatic
1839
+ // scrolling. The browser seems to round the value based on the snapping points which means
1840
+ // that we can't increment/decrement the scroll position.
1841
+ this._initialScrollSnap = styles.msScrollSnapType || styles.scrollSnapType || '';
1842
+ styles.scrollSnapType = styles.msScrollSnapType = 'none';
1843
+ this._cacheItems();
1844
+ this._viewportScrollSubscription.unsubscribe();
1845
+ this._listenToScrollEvents();
1846
+ }
1837
1847
  /** Caches the positions of the configured scrollable parents. */
1838
1848
  _cacheParentPositions() {
1839
1849
  const element = coerceElement(this.element);
@@ -1987,7 +1997,7 @@ class DropListRef {
1987
1997
  * @param y Pointer position along the Y axis.
1988
1998
  */
1989
1999
  _isOverContainer(x, y) {
1990
- return isInsideClientRect(this._clientRect, x, y);
2000
+ return this._clientRect != null && isInsideClientRect(this._clientRect, x, y);
1991
2001
  }
1992
2002
  /**
1993
2003
  * Figures out whether an item should be moved into a sibling
@@ -2006,7 +2016,8 @@ class DropListRef {
2006
2016
  * @param y Position of the item along the Y axis.
2007
2017
  */
2008
2018
  _canReceive(item, x, y) {
2009
- if (!isInsideClientRect(this._clientRect, x, y) || !this.enterPredicate(item, this)) {
2019
+ if (!this._clientRect || !isInsideClientRect(this._clientRect, x, y) ||
2020
+ !this.enterPredicate(item, this)) {
2010
2021
  return false;
2011
2022
  }
2012
2023
  const elementFromPoint = this._getShadowRoot().elementFromPoint(x, y);
@@ -2028,9 +2039,15 @@ class DropListRef {
2028
2039
  * Called by one of the connected drop lists when a dragging sequence has started.
2029
2040
  * @param sibling Sibling in which dragging has started.
2030
2041
  */
2031
- _startReceiving(sibling) {
2042
+ _startReceiving(sibling, items) {
2032
2043
  const activeSiblings = this._activeSiblings;
2033
- if (!activeSiblings.has(sibling)) {
2044
+ if (!activeSiblings.has(sibling) && items.every(item => {
2045
+ // Note that we have to add an exception to the `enterPredicate` for items that started off
2046
+ // in this drop list. The drag ref has logic that allows an item to return to its initial
2047
+ // container, if it has left the initial container and none of the connected containers
2048
+ // allow it to enter. See `DragRef._updateActiveDropContainer` for more context.
2049
+ return this.enterPredicate(item, this) || this._draggables.indexOf(item) > -1;
2050
+ })) {
2034
2051
  activeSiblings.add(sibling);
2035
2052
  this._cacheParentPositions();
2036
2053
  this._listenToScrollEvents();
@@ -2089,6 +2106,11 @@ class DropListRef {
2089
2106
  }
2090
2107
  return this._cachedShadowRoot;
2091
2108
  }
2109
+ /** Notifies any siblings that may potentially receive the item. */
2110
+ _notifyReceivingSiblings() {
2111
+ const draggedItems = this._activeDraggables.filter(item => item.isDragging());
2112
+ this._siblings.forEach(sibling => sibling._startReceiving(this, draggedItems));
2113
+ }
2092
2114
  }
2093
2115
  /**
2094
2116
  * Finds the index of an item that matches a predicate function. Used as an equivalent
@@ -2234,9 +2256,14 @@ class DragDropRegistry {
2234
2256
  /** Registered drag item instances. */
2235
2257
  this._dragInstances = new Set();
2236
2258
  /** Drag item instances that are currently being dragged. */
2237
- this._activeDragInstances = new Set();
2259
+ this._activeDragInstances = [];
2238
2260
  /** Keeps track of the event listeners that we've bound to the `document`. */
2239
2261
  this._globalListeners = new Map();
2262
+ /**
2263
+ * Predicate function to check if an item is being dragged. Moved out into a property,
2264
+ * because it'll be called a lot and we don't want to create a new function every time.
2265
+ */
2266
+ this._draggingPredicate = (item) => item.isDragging();
2240
2267
  /**
2241
2268
  * Emits the `touchmove` or `mousemove` events that are dispatched
2242
2269
  * while the user is dragging a drag item instance.
@@ -2254,14 +2281,19 @@ class DragDropRegistry {
2254
2281
  * @param event Event whose default action should be prevented.
2255
2282
  */
2256
2283
  this._preventDefaultWhileDragging = (event) => {
2257
- if (this._activeDragInstances.size) {
2284
+ if (this._activeDragInstances.length > 0) {
2258
2285
  event.preventDefault();
2259
2286
  }
2260
2287
  };
2261
2288
  /** Event listener for `touchmove` that is bound even if no dragging is happening. */
2262
2289
  this._persistentTouchmoveListener = (event) => {
2263
- if (this._activeDragInstances.size) {
2264
- event.preventDefault();
2290
+ if (this._activeDragInstances.length > 0) {
2291
+ // Note that we only want to prevent the default action after dragging has actually started.
2292
+ // Usually this is the same time at which the item is added to the `_activeDragInstances`,
2293
+ // but it could be pushed back if the user has set up a drag delay or threshold.
2294
+ if (this._activeDragInstances.some(this._draggingPredicate)) {
2295
+ event.preventDefault();
2296
+ }
2265
2297
  this.pointerMove.next(event);
2266
2298
  }
2267
2299
  };
@@ -2306,11 +2338,11 @@ class DragDropRegistry {
2306
2338
  */
2307
2339
  startDragging(drag, event) {
2308
2340
  // Do not process the same drag twice to avoid memory leaks and redundant listeners
2309
- if (this._activeDragInstances.has(drag)) {
2341
+ if (this._activeDragInstances.indexOf(drag) > -1) {
2310
2342
  return;
2311
2343
  }
2312
- this._activeDragInstances.add(drag);
2313
- if (this._activeDragInstances.size === 1) {
2344
+ this._activeDragInstances.push(drag);
2345
+ if (this._activeDragInstances.length === 1) {
2314
2346
  const isTouchEvent = event.type.startsWith('touch');
2315
2347
  // We explicitly bind __active__ listeners here, because newer browsers will default to
2316
2348
  // passive ones for `mousemove` and `touchmove`. The events need to be active, because we
@@ -2351,14 +2383,17 @@ class DragDropRegistry {
2351
2383
  }
2352
2384
  /** Stops dragging a drag item instance. */
2353
2385
  stopDragging(drag) {
2354
- this._activeDragInstances.delete(drag);
2355
- if (this._activeDragInstances.size === 0) {
2356
- this._clearGlobalListeners();
2386
+ const index = this._activeDragInstances.indexOf(drag);
2387
+ if (index > -1) {
2388
+ this._activeDragInstances.splice(index, 1);
2389
+ if (this._activeDragInstances.length === 0) {
2390
+ this._clearGlobalListeners();
2391
+ }
2357
2392
  }
2358
2393
  }
2359
2394
  /** Gets whether a drag item instance is currently being dragged. */
2360
2395
  isDragging(drag) {
2361
- return this._activeDragInstances.has(drag);
2396
+ return this._activeDragInstances.indexOf(drag) > -1;
2362
2397
  }
2363
2398
  ngOnDestroy() {
2364
2399
  this._dragInstances.forEach(instance => this.removeDragItem(instance));
@@ -2965,7 +3000,7 @@ class CdkDrag {
2965
3000
  * @deprecated `_document` parameter no longer being used and will be removed.
2966
3001
  * @breaking-change 12.0.0
2967
3002
  */
2968
- _document, _ngZone, _viewContainerRef, config, _dir, dragDrop, _changeDetectorRef, _selfHandle) {
3003
+ _document, _ngZone, _viewContainerRef, config, _dir, dragDrop, _changeDetectorRef, _selfHandle, parentDrag) {
2969
3004
  this.element = element;
2970
3005
  this.dropContainer = dropContainer;
2971
3006
  this._ngZone = _ngZone;
@@ -3007,7 +3042,8 @@ class CdkDrag {
3007
3042
  config.dragStartThreshold : 5,
3008
3043
  pointerDirectionChangeThreshold: config && config.pointerDirectionChangeThreshold != null ?
3009
3044
  config.pointerDirectionChangeThreshold : 5,
3010
- zIndex: config === null || config === void 0 ? void 0 : config.zIndex
3045
+ zIndex: config === null || config === void 0 ? void 0 : config.zIndex,
3046
+ parentDragRef: parentDrag === null || parentDrag === void 0 ? void 0 : parentDrag._dragRef
3011
3047
  });
3012
3048
  this._dragRef.data = this;
3013
3049
  if (config) {
@@ -3262,7 +3298,8 @@ CdkDrag.ctorParameters = () => [
3262
3298
  { type: Directionality, decorators: [{ type: Optional }] },
3263
3299
  { type: DragDrop },
3264
3300
  { type: ChangeDetectorRef },
3265
- { type: CdkDragHandle, decorators: [{ type: Optional }, { type: Self }, { type: Inject, args: [CDK_DRAG_HANDLE,] }] }
3301
+ { type: CdkDragHandle, decorators: [{ type: Optional }, { type: Self }, { type: Inject, args: [CDK_DRAG_HANDLE,] }] },
3302
+ { type: CdkDrag, decorators: [{ type: Optional }, { type: SkipSelf }, { type: Inject, args: [CDK_DRAG_PARENT,] }] }
3266
3303
  ];
3267
3304
  CdkDrag.propDecorators = {
3268
3305
  _handles: [{ type: ContentChildren, args: [CDK_DRAG_HANDLE, { descendants: true },] }],