@angular/cdk 14.0.0-next.3 → 14.0.0-next.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.
package/fesm2020/cdk.mjs 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('14.0.0-next.3');
11
+ const VERSION = new Version('14.0.0-next.4');
12
12
 
13
13
  /**
14
14
  * @license
@@ -1 +1 @@
1
- {"version":3,"file":"cdk.mjs","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('14.0.0-next.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;;;;;;;AAUA;MACa,OAAO,GAAG,IAAI,OAAO,CAAC,mBAAmB;;ACXtD;;;;;;;;ACAA;;;;;;;;;;"}
1
+ {"version":3,"file":"cdk.mjs","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('14.0.0-next.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;;;;;;;AAUA;MACa,OAAO,GAAG,IAAI,OAAO,CAAC,mBAAmB;;ACXtD;;;;;;;;ACAA;;;;;;;;;;"}
@@ -188,9 +188,8 @@ function isPointerNearClientRect(rect, threshold, pointerX, pointerY) {
188
188
  */
189
189
  /** Keeps track of the scroll position and dimensions of the parents of an element. */
190
190
  class ParentPositionTracker {
191
- constructor(_document, _viewportRuler) {
191
+ constructor(_document) {
192
192
  this._document = _document;
193
- this._viewportRuler = _viewportRuler;
194
193
  /** Cached positions of the scrollable parent elements. */
195
194
  this.positions = new Map();
196
195
  }
@@ -202,7 +201,7 @@ class ParentPositionTracker {
202
201
  cache(elements) {
203
202
  this.clear();
204
203
  this.positions.set(this._document, {
205
- scrollPosition: this._viewportRuler.getViewportScrollPosition(),
204
+ scrollPosition: this.getViewportScrollPosition(),
206
205
  });
207
206
  elements.forEach(element => {
208
207
  this.positions.set(element, {
@@ -222,7 +221,7 @@ class ParentPositionTracker {
222
221
  let newTop;
223
222
  let newLeft;
224
223
  if (target === this._document) {
225
- const viewportScrollPosition = this._viewportRuler.getViewportScrollPosition();
224
+ const viewportScrollPosition = this.getViewportScrollPosition();
226
225
  newTop = viewportScrollPosition.top;
227
226
  newLeft = viewportScrollPosition.left;
228
227
  }
@@ -243,6 +242,15 @@ class ParentPositionTracker {
243
242
  scrollPosition.left = newLeft;
244
243
  return { top: topDifference, left: leftDifference };
245
244
  }
245
+ /**
246
+ * Gets the scroll position of the viewport. Note that we use the scrollX and scrollY directly,
247
+ * instead of going through the `ViewportRuler`, because the first value the ruler looks at is
248
+ * the top/left offset of the `document.documentElement` which works for most cases, but breaks
249
+ * if the element is offset by something like the `BlockScrollStrategy`.
250
+ */
251
+ getViewportScrollPosition() {
252
+ return { top: window.scrollY, left: window.scrollX };
253
+ }
246
254
  }
247
255
 
248
256
  /**
@@ -496,7 +504,7 @@ class DragRef {
496
504
  this._endDragSequence(event);
497
505
  };
498
506
  this.withRootElement(element).withParent(_config.parentDragRef || null);
499
- this._parentPositions = new ParentPositionTracker(_document, _viewportRuler);
507
+ this._parentPositions = new ParentPositionTracker(_document);
500
508
  _dragDropRegistry.registerDragItem(this);
501
509
  }
502
510
  /** Whether starting to drag this element is disabled. */
@@ -577,6 +585,9 @@ class DragRef {
577
585
  this._ngZone.runOutsideAngular(() => {
578
586
  element.addEventListener('mousedown', this._pointerDown, activeEventListenerOptions);
579
587
  element.addEventListener('touchstart', this._pointerDown, passiveEventListenerOptions);
588
+ // Usually this isn't necessary since the we prevent the default action in `pointerDown`,
589
+ // but some cases like dragging of links can slip through (see #24403).
590
+ element.addEventListener('dragstart', preventDefault, activeEventListenerOptions);
580
591
  });
581
592
  this._initialTransform = undefined;
582
593
  this._rootElement = element;
@@ -1081,6 +1092,9 @@ class DragRef {
1081
1092
  else {
1082
1093
  placeholder = deepCloneNode(this._rootElement);
1083
1094
  }
1095
+ // Stop pointer events on the preview so the user can't
1096
+ // interact with it while the preview is animating.
1097
+ placeholder.style.pointerEvents = 'none';
1084
1098
  placeholder.classList.add('cdk-drag-placeholder');
1085
1099
  return placeholder;
1086
1100
  }
@@ -1190,6 +1204,7 @@ class DragRef {
1190
1204
  _removeRootElementListeners(element) {
1191
1205
  element.removeEventListener('mousedown', this._pointerDown, activeEventListenerOptions);
1192
1206
  element.removeEventListener('touchstart', this._pointerDown, passiveEventListenerOptions);
1207
+ element.removeEventListener('dragstart', preventDefault, activeEventListenerOptions);
1193
1208
  }
1194
1209
  /**
1195
1210
  * Applies a `transform` to the root element, taking into account any existing transforms on it.
@@ -1326,10 +1341,8 @@ class DragRef {
1326
1341
  }
1327
1342
  /** Gets the scroll position of the viewport. */
1328
1343
  _getViewportScrollPosition() {
1329
- const cachedPosition = this._parentPositions.positions.get(this._document);
1330
- return cachedPosition
1331
- ? cachedPosition.scrollPosition
1332
- : this._viewportRuler.getViewportScrollPosition();
1344
+ return (this._parentPositions.positions.get(this._document)?.scrollPosition ||
1345
+ this._parentPositions.getViewportScrollPosition());
1333
1346
  }
1334
1347
  /**
1335
1348
  * Lazily resolves and returns the shadow root of the element. We do this in a function, rather
@@ -1408,6 +1421,10 @@ function matchElementSize(target, sourceRect) {
1408
1421
  target.style.height = `${sourceRect.height}px`;
1409
1422
  target.style.transform = getTransform(sourceRect.left, sourceRect.top);
1410
1423
  }
1424
+ /** Utility to prevent the default action of an event. */
1425
+ function preventDefault(event) {
1426
+ event.preventDefault();
1427
+ }
1411
1428
 
1412
1429
  /**
1413
1430
  * @license
@@ -1583,7 +1600,7 @@ class DropListRef {
1583
1600
  this._document = _document;
1584
1601
  this.withScrollableParents([this.element]);
1585
1602
  _dragDropRegistry.registerDropContainer(this);
1586
- this._parentPositions = new ParentPositionTracker(_document, _viewportRuler);
1603
+ this._parentPositions = new ParentPositionTracker(_document);
1587
1604
  }
1588
1605
  /** Removes the drop list functionality from the DOM element. */
1589
1606
  dispose() {