@angular/cdk 20.0.4 → 20.1.0-next.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 (70) hide show
  1. package/_adev_assets/cdk_drag_drop.json +100 -8
  2. package/_adev_assets/cdk_testing.json +634 -61
  3. package/dialog/index.d.ts +16 -12
  4. package/drag-drop/index.d.ts +30 -2
  5. package/fesm2022/a11y-module-DHa4AVFz.mjs.map +1 -1
  6. package/fesm2022/a11y.mjs.map +1 -1
  7. package/fesm2022/accordion.mjs.map +1 -1
  8. package/fesm2022/activedescendant-key-manager-CZAE5aFC.mjs.map +1 -1
  9. package/fesm2022/array-I1yfCXUO.mjs.map +1 -1
  10. package/fesm2022/bidi.mjs.map +1 -1
  11. package/fesm2022/breakpoints-observer-QutrMj4x.mjs.map +1 -1
  12. package/fesm2022/cdk.mjs +1 -1
  13. package/fesm2022/cdk.mjs.map +1 -1
  14. package/fesm2022/clipboard.mjs.map +1 -1
  15. package/fesm2022/coercion/private.mjs.map +1 -1
  16. package/fesm2022/coercion.mjs.map +1 -1
  17. package/fesm2022/css-pixel-value-C_HEqLhI.mjs.map +1 -1
  18. package/fesm2022/data-source-D34wiQZj.mjs.map +1 -1
  19. package/fesm2022/dialog.mjs +21 -9
  20. package/fesm2022/dialog.mjs.map +1 -1
  21. package/fesm2022/directionality-CChdj3az.mjs.map +1 -1
  22. package/fesm2022/dispose-view-repeater-strategy-Cvpav0PR.mjs.map +1 -1
  23. package/fesm2022/drag-drop.mjs +98 -24
  24. package/fesm2022/drag-drop.mjs.map +1 -1
  25. package/fesm2022/element-x4z00URv.mjs.map +1 -1
  26. package/fesm2022/fake-event-detection-DWOdFTFz.mjs.map +1 -1
  27. package/fesm2022/focus-key-manager-CPmlyB_c.mjs.map +1 -1
  28. package/fesm2022/focus-monitor-DLjkiju1.mjs.map +1 -1
  29. package/fesm2022/id-generator-LuoRZSid.mjs.map +1 -1
  30. package/fesm2022/keycodes-CpHkExLC.mjs.map +1 -1
  31. package/fesm2022/keycodes.mjs.map +1 -1
  32. package/fesm2022/layout.mjs.map +1 -1
  33. package/fesm2022/list-key-manager-C7tp3RbG.mjs.map +1 -1
  34. package/fesm2022/listbox.mjs.map +1 -1
  35. package/fesm2022/menu.mjs +24 -30
  36. package/fesm2022/menu.mjs.map +1 -1
  37. package/fesm2022/observers/private.mjs.map +1 -1
  38. package/fesm2022/observers.mjs.map +1 -1
  39. package/fesm2022/overlay-module-Bd2UplUU.mjs.map +1 -1
  40. package/fesm2022/overlay.mjs.map +1 -1
  41. package/fesm2022/passive-listeners-esHZRgIN.mjs.map +1 -1
  42. package/fesm2022/platform-DNDzkVcI.mjs.map +1 -1
  43. package/fesm2022/platform.mjs.map +1 -1
  44. package/fesm2022/portal.mjs.map +1 -1
  45. package/fesm2022/private.mjs.map +1 -1
  46. package/fesm2022/recycle-view-repeater-strategy-SfuyU210.mjs.map +1 -1
  47. package/fesm2022/scrolling-BkvA05C8.mjs.map +1 -1
  48. package/fesm2022/scrolling.mjs.map +1 -1
  49. package/fesm2022/selection-model-BCgC8uEN.mjs.map +1 -1
  50. package/fesm2022/shadow-dom-B0oHn41l.mjs.map +1 -1
  51. package/fesm2022/stepper.mjs.map +1 -1
  52. package/fesm2022/style-loader-B2sGQXxD.mjs.map +1 -1
  53. package/fesm2022/table.mjs.map +1 -1
  54. package/fesm2022/test-environment-CT0XxPyp.mjs.map +1 -1
  55. package/fesm2022/testing/selenium-webdriver.mjs.map +1 -1
  56. package/fesm2022/testing/testbed.mjs.map +1 -1
  57. package/fesm2022/testing.mjs +50 -1
  58. package/fesm2022/testing.mjs.map +1 -1
  59. package/fesm2022/text-field.mjs.map +1 -1
  60. package/fesm2022/tree-key-manager-KnCoIkIC.mjs.map +1 -1
  61. package/fesm2022/tree.mjs.map +1 -1
  62. package/fesm2022/typeahead-9ZW4Dtsf.mjs.map +1 -1
  63. package/fesm2022/unique-selection-dispatcher-Cewa_Eg3.mjs.map +1 -1
  64. package/{harness-environment.d-BbFzIFDE.d.ts → harness-environment.d-C-TBj7IN.d.ts} +52 -1
  65. package/menu/index.d.ts +14 -19
  66. package/package.json +3 -3
  67. package/schematics/ng-add/index.js +1 -1
  68. package/testing/index.d.ts +1 -1
  69. package/testing/selenium-webdriver/index.d.ts +1 -1
  70. package/testing/testbed/index.d.ts +1 -1
@@ -482,6 +482,8 @@ const activeCapturingEventOptions$1 = {
482
482
  * addition to touch events.
483
483
  */
484
484
  const MOUSE_EVENT_IGNORE_TIME = 800;
485
+ /** Class applied to the drag placeholder. */
486
+ const PLACEHOLDER_CLASS = 'cdk-drag-placeholder';
485
487
  /** Inline styles to be set as `!important` while dragging. */
486
488
  const dragImportantProperties = new Set([
487
489
  // Needs to be important, because some `mat-table` sets `position: sticky !important`. See #22781.
@@ -512,10 +514,14 @@ class DragRef {
512
514
  /** Coordinates on the page at which the user picked up the element. */
513
515
  _pickupPositionOnPage;
514
516
  /**
515
- * Anchor node used to save the place in the DOM where the element was
517
+ * Marker node used to save the place in the DOM where the element was
516
518
  * picked up so that it can be restored at the end of the drag sequence.
517
519
  */
518
- _anchor;
520
+ _marker;
521
+ /**
522
+ * Element indicating the position from which the item was picked up initially.
523
+ */
524
+ _anchor = null;
519
525
  /**
520
526
  * CSS `transform` applied to the element when it isn't being dragged. We need a
521
527
  * passive transform in order for the dragged element to retain its new position
@@ -776,7 +782,7 @@ class DragRef {
776
782
  // dragged, we have to make sure that it's removed if it gets destroyed.
777
783
  this._rootElement?.remove();
778
784
  }
779
- this._anchor?.remove();
785
+ this._marker?.remove();
780
786
  this._destroyPreview();
781
787
  this._destroyPlaceholder();
782
788
  this._dragDropRegistry.removeDragItem(this);
@@ -799,7 +805,7 @@ class DragRef {
799
805
  this._ownerSVGElement =
800
806
  this._placeholderTemplate =
801
807
  this._previewTemplate =
802
- this._anchor =
808
+ this._marker =
803
809
  this._parentDragRef =
804
810
  null;
805
811
  }
@@ -926,9 +932,10 @@ class DragRef {
926
932
  }
927
933
  /** Destroys the placeholder element and its ViewRef. */
928
934
  _destroyPlaceholder() {
935
+ this._anchor?.remove();
929
936
  this._placeholder?.remove();
930
937
  this._placeholderRef?.destroy();
931
- this._placeholder = this._placeholderRef = null;
938
+ this._placeholder = this._anchor = this._placeholderRef = null;
932
939
  }
933
940
  /** Handler for the `mousedown`/`touchstart` events. */
934
941
  _pointerDown = (event) => {
@@ -1089,11 +1096,11 @@ class DragRef {
1089
1096
  const element = this._rootElement;
1090
1097
  const parent = element.parentNode;
1091
1098
  const placeholder = (this._placeholder = this._createPlaceholderElement());
1092
- const anchor = (this._anchor =
1093
- this._anchor ||
1094
- this._document.createComment(typeof ngDevMode === 'undefined' || ngDevMode ? 'cdk-drag-anchor' : ''));
1095
- // Insert an anchor node so that we can restore the element's position in the DOM.
1096
- parent.insertBefore(anchor, element);
1099
+ const marker = (this._marker =
1100
+ this._marker ||
1101
+ this._document.createComment(typeof ngDevMode === 'undefined' || ngDevMode ? 'cdk-drag-marker' : ''));
1102
+ // Insert a marker node so that we can restore the element's position in the DOM.
1103
+ parent.insertBefore(marker, element);
1097
1104
  // There's no risk of transforms stacking when inside a drop container so
1098
1105
  // we can keep the initial transform up to date any time dragging starts.
1099
1106
  this._initialTransform = element.style.transform || '';
@@ -1200,7 +1207,7 @@ class DragRef {
1200
1207
  // can throw off `NgFor` which does smart diffing and re-creates elements only when necessary,
1201
1208
  // while moving the existing elements in all other cases.
1202
1209
  toggleVisibility(this._rootElement, true, dragImportantProperties);
1203
- this._anchor.parentNode.replaceChild(this._rootElement, this._anchor);
1210
+ this._marker.parentNode.replaceChild(this._rootElement, this._marker);
1204
1211
  this._destroyPreview();
1205
1212
  this._destroyPlaceholder();
1206
1213
  this._initialDomRect =
@@ -1249,15 +1256,18 @@ class DragRef {
1249
1256
  }
1250
1257
  if (newContainer && newContainer !== this._dropContainer) {
1251
1258
  this._ngZone.run(() => {
1259
+ const exitIndex = this._dropContainer.getItemIndex(this);
1260
+ const nextItemElement = this._dropContainer.getItemAtIndex(exitIndex + 1)?.getVisibleElement() || null;
1252
1261
  // Notify the old container that the item has left.
1253
1262
  this.exited.next({ item: this, container: this._dropContainer });
1254
1263
  this._dropContainer.exit(this);
1264
+ this._conditionallyInsertAnchor(newContainer, this._dropContainer, nextItemElement);
1255
1265
  // Notify the new container that the item has entered.
1256
1266
  this._dropContainer = newContainer;
1257
- this._dropContainer.enter(this, x, y, newContainer === this._initialContainer &&
1258
- // If we're re-entering the initial container and sorting is disabled,
1259
- // put item the into its starting index to begin with.
1260
- newContainer.sortingDisabled
1267
+ this._dropContainer.enter(this, x, y,
1268
+ // If we're re-entering the initial container and sorting is disabled,
1269
+ // put item the into its starting index to begin with.
1270
+ newContainer === this._initialContainer && newContainer.sortingDisabled
1261
1271
  ? this._initialIndex
1262
1272
  : undefined);
1263
1273
  this.entered.next({
@@ -1337,7 +1347,7 @@ class DragRef {
1337
1347
  // Stop pointer events on the preview so the user can't
1338
1348
  // interact with it while the preview is animating.
1339
1349
  placeholder.style.pointerEvents = 'none';
1340
- placeholder.classList.add('cdk-drag-placeholder');
1350
+ placeholder.classList.add(PLACEHOLDER_CLASS);
1341
1351
  return placeholder;
1342
1352
  }
1343
1353
  /**
@@ -1659,6 +1669,31 @@ class DragRef {
1659
1669
  return event.target && (event.target === handle || handle.contains(event.target));
1660
1670
  });
1661
1671
  }
1672
+ /** Inserts the anchor element, if it's valid. */
1673
+ _conditionallyInsertAnchor(newContainer, exitContainer, nextItemElement) {
1674
+ // Remove the anchor when returning to the initial container.
1675
+ if (newContainer === this._initialContainer) {
1676
+ this._anchor?.remove();
1677
+ this._anchor = null;
1678
+ }
1679
+ else if (exitContainer === this._initialContainer && exitContainer.hasAnchor) {
1680
+ // Insert the anchor when leaving the initial container.
1681
+ const anchor = (this._anchor ??= deepCloneNode(this._placeholder));
1682
+ anchor.classList.remove(PLACEHOLDER_CLASS);
1683
+ anchor.classList.add('cdk-drag-anchor');
1684
+ // Clear the transform since the single-axis strategy uses transforms to sort the items.
1685
+ anchor.style.transform = '';
1686
+ // When the item leaves the initial container, the container's DOM will be restored to
1687
+ // its original state, except for the dragged item which is removed. Insert the anchor in
1688
+ // the position from which the item left so that the list looks consistent.
1689
+ if (nextItemElement) {
1690
+ nextItemElement.before(anchor);
1691
+ }
1692
+ else {
1693
+ coerceElement(exitContainer.element).appendChild(anchor);
1694
+ }
1695
+ }
1696
+ }
1662
1697
  }
1663
1698
  /** Clamps a value between a minimum and a maximum. */
1664
1699
  function clamp$1(value, min, max) {
@@ -1922,13 +1957,11 @@ class SingleAxisSortStrategy {
1922
1957
  }
1923
1958
  /** Gets the index of a specific item. */
1924
1959
  getItemIndex(item) {
1925
- // Items are sorted always by top/left in the cache, however they flow differently in RTL.
1926
- // The rest of the logic still stands no matter what orientation we're in, however
1927
- // we need to invert the array when determining the index.
1928
- const items = this.orientation === 'horizontal' && this.direction === 'rtl'
1929
- ? this._itemPositions.slice().reverse()
1930
- : this._itemPositions;
1931
- return items.findIndex(currentItem => currentItem.drag === item);
1960
+ return this._getVisualItemPositions().findIndex(currentItem => currentItem.drag === item);
1961
+ }
1962
+ /** Gets the item at a specific index. */
1963
+ getItemAtIndex(index) {
1964
+ return this._getVisualItemPositions()[index]?.drag || null;
1932
1965
  }
1933
1966
  /** Used to notify the strategy that the scroll position has changed. */
1934
1967
  updateOnScroll(topDifference, leftDifference) {
@@ -1971,6 +2004,14 @@ class SingleAxisSortStrategy {
1971
2004
  : a.clientRect.top - b.clientRect.top;
1972
2005
  });
1973
2006
  }
2007
+ _getVisualItemPositions() {
2008
+ // Items are sorted always by top/left in the cache, however they flow differently in RTL.
2009
+ // The rest of the logic still stands no matter what orientation we're in, however
2010
+ // we need to invert the array when determining the index.
2011
+ return this.orientation === 'horizontal' && this.direction === 'rtl'
2012
+ ? this._itemPositions.slice().reverse()
2013
+ : this._itemPositions;
2014
+ }
1974
2015
  /**
1975
2016
  * Gets the offset in pixels by which the item that is being dragged should be moved.
1976
2017
  * @param currentPosition Current position of the item.
@@ -2251,6 +2292,10 @@ class MixedSortStrategy {
2251
2292
  getItemIndex(item) {
2252
2293
  return this._activeItems.indexOf(item);
2253
2294
  }
2295
+ /** Gets the item at a specific index. */
2296
+ getItemAtIndex(index) {
2297
+ return this._activeItems[index] || null;
2298
+ }
2254
2299
  /** Used to notify the strategy that the scroll position has changed. */
2255
2300
  updateOnScroll() {
2256
2301
  this._activeItems.forEach(item => {
@@ -2372,6 +2417,10 @@ class DropListRef {
2372
2417
  autoScrollDisabled = false;
2373
2418
  /** Number of pixels to scroll for each frame when auto-scrolling an element. */
2374
2419
  autoScrollStep = 2;
2420
+ /**
2421
+ * Whether the items in the list should leave an anchor node when leaving the initial container.
2422
+ */
2423
+ hasAnchor = false;
2375
2424
  /**
2376
2425
  * Function that is used to determine whether an item
2377
2426
  * is allowed to be moved into a drop container.
@@ -2644,6 +2693,15 @@ class DropListRef {
2644
2693
  ? this._sortStrategy.getItemIndex(item)
2645
2694
  : this._draggables.indexOf(item);
2646
2695
  }
2696
+ /**
2697
+ * Gets the item at a specific index.
2698
+ * @param index Index at which to retrieve the item.
2699
+ */
2700
+ getItemAtIndex(index) {
2701
+ return this._isDragging
2702
+ ? this._sortStrategy.getItemAtIndex(index)
2703
+ : this._draggables[index] || null;
2704
+ }
2647
2705
  /**
2648
2706
  * Whether the list is able to receive the item that
2649
2707
  * is currently being dragged inside a connected drop list.
@@ -4013,6 +4071,18 @@ class CdkDropList {
4013
4071
  * ```
4014
4072
  */
4015
4073
  elementContainerSelector;
4074
+ /**
4075
+ * By default when an item leaves its initial container, its placeholder will be transferred
4076
+ * to the new container. If that's not desirable for your use case, you can enable this option
4077
+ * which will clone the placeholder and leave it inside the original container. If the item is
4078
+ * returned to the initial container, the anchor element will be removed automatically.
4079
+ *
4080
+ * The cloned placeholder can be styled by targeting the `cdk-drag-anchor` class.
4081
+ *
4082
+ * This option is useful in combination with `cdkDropListSortingDisabled` to implement copying
4083
+ * behavior in a drop list.
4084
+ */
4085
+ hasAnchor;
4016
4086
  /** Emits when the user drops an item inside the container. */
4017
4087
  dropped = new EventEmitter();
4018
4088
  /**
@@ -4155,6 +4225,7 @@ class CdkDropList {
4155
4225
  ref.sortingDisabled = this.sortingDisabled;
4156
4226
  ref.autoScrollDisabled = this.autoScrollDisabled;
4157
4227
  ref.autoScrollStep = coerceNumberProperty(this.autoScrollStep, 2);
4228
+ ref.hasAnchor = this.hasAnchor;
4158
4229
  ref
4159
4230
  .connectedTo(siblings.filter(drop => drop && drop !== this).map(list => list._dropListRef))
4160
4231
  .withOrientation(this.orientation);
@@ -4223,7 +4294,7 @@ class CdkDropList {
4223
4294
  this._dropListRef.withItems(items);
4224
4295
  }
4225
4296
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.0", ngImport: i0, type: CdkDropList, deps: [], target: i0.ɵɵFactoryTarget.Directive });
4226
- static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "16.1.0", version: "20.0.0", type: CdkDropList, isStandalone: true, selector: "[cdkDropList], cdk-drop-list", inputs: { connectedTo: ["cdkDropListConnectedTo", "connectedTo"], data: ["cdkDropListData", "data"], orientation: ["cdkDropListOrientation", "orientation"], id: "id", lockAxis: ["cdkDropListLockAxis", "lockAxis"], disabled: ["cdkDropListDisabled", "disabled", booleanAttribute], sortingDisabled: ["cdkDropListSortingDisabled", "sortingDisabled", booleanAttribute], enterPredicate: ["cdkDropListEnterPredicate", "enterPredicate"], sortPredicate: ["cdkDropListSortPredicate", "sortPredicate"], autoScrollDisabled: ["cdkDropListAutoScrollDisabled", "autoScrollDisabled", booleanAttribute], autoScrollStep: ["cdkDropListAutoScrollStep", "autoScrollStep"], elementContainerSelector: ["cdkDropListElementContainer", "elementContainerSelector"] }, outputs: { dropped: "cdkDropListDropped", entered: "cdkDropListEntered", exited: "cdkDropListExited", sorted: "cdkDropListSorted" }, host: { properties: { "attr.id": "id", "class.cdk-drop-list-disabled": "disabled", "class.cdk-drop-list-dragging": "_dropListRef.isDragging()", "class.cdk-drop-list-receiving": "_dropListRef.isReceiving()" }, classAttribute: "cdk-drop-list" }, providers: [
4297
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "16.1.0", version: "20.0.0", type: CdkDropList, isStandalone: true, selector: "[cdkDropList], cdk-drop-list", inputs: { connectedTo: ["cdkDropListConnectedTo", "connectedTo"], data: ["cdkDropListData", "data"], orientation: ["cdkDropListOrientation", "orientation"], id: "id", lockAxis: ["cdkDropListLockAxis", "lockAxis"], disabled: ["cdkDropListDisabled", "disabled", booleanAttribute], sortingDisabled: ["cdkDropListSortingDisabled", "sortingDisabled", booleanAttribute], enterPredicate: ["cdkDropListEnterPredicate", "enterPredicate"], sortPredicate: ["cdkDropListSortPredicate", "sortPredicate"], autoScrollDisabled: ["cdkDropListAutoScrollDisabled", "autoScrollDisabled", booleanAttribute], autoScrollStep: ["cdkDropListAutoScrollStep", "autoScrollStep"], elementContainerSelector: ["cdkDropListElementContainer", "elementContainerSelector"], hasAnchor: ["cdkDropListHasAnchor", "hasAnchor", booleanAttribute] }, outputs: { dropped: "cdkDropListDropped", entered: "cdkDropListEntered", exited: "cdkDropListExited", sorted: "cdkDropListSorted" }, host: { properties: { "attr.id": "id", "class.cdk-drop-list-disabled": "disabled", "class.cdk-drop-list-dragging": "_dropListRef.isDragging()", "class.cdk-drop-list-receiving": "_dropListRef.isReceiving()" }, classAttribute: "cdk-drop-list" }, providers: [
4227
4298
  // Prevent child drop lists from picking up the same group as their parent.
4228
4299
  { provide: CDK_DROP_LIST_GROUP, useValue: undefined },
4229
4300
  { provide: CDK_DROP_LIST, useExisting: CdkDropList },
@@ -4282,6 +4353,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.0", ngImpor
4282
4353
  }], elementContainerSelector: [{
4283
4354
  type: Input,
4284
4355
  args: ['cdkDropListElementContainer']
4356
+ }], hasAnchor: [{
4357
+ type: Input,
4358
+ args: [{ alias: 'cdkDropListHasAnchor', transform: booleanAttribute }]
4285
4359
  }], dropped: [{
4286
4360
  type: Output,
4287
4361
  args: ['cdkDropListDropped']