@angular/cdk 10.0.2 → 10.1.3

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 (216) hide show
  1. package/a11y/aria-describer/aria-describer.d.ts +10 -1
  2. package/a11y/index.metadata.json +1 -1
  3. package/a11y/interactivity-checker/interactivity-checker.d.ts +11 -1
  4. package/a11y/key-manager/list-key-manager.d.ts +6 -0
  5. package/accordion/accordion.d.ts +7 -1
  6. package/accordion/index.d.ts +1 -0
  7. package/accordion/index.metadata.json +1 -1
  8. package/bundles/cdk-a11y.umd.js +514 -410
  9. package/bundles/cdk-a11y.umd.js.map +1 -1
  10. package/bundles/cdk-a11y.umd.min.js +35 -11
  11. package/bundles/cdk-a11y.umd.min.js.map +1 -1
  12. package/bundles/cdk-accordion.umd.js +47 -39
  13. package/bundles/cdk-accordion.umd.js.map +1 -1
  14. package/bundles/cdk-accordion.umd.min.js +10 -2
  15. package/bundles/cdk-accordion.umd.min.js.map +1 -1
  16. package/bundles/cdk-bidi.umd.js +25 -25
  17. package/bundles/cdk-bidi.umd.js.map +1 -1
  18. package/bundles/cdk-bidi.umd.min.js +5 -4
  19. package/bundles/cdk-bidi.umd.min.js.map +1 -1
  20. package/bundles/cdk-clipboard.umd.js +37 -36
  21. package/bundles/cdk-clipboard.umd.js.map +1 -1
  22. package/bundles/cdk-clipboard.umd.min.js +10 -2
  23. package/bundles/cdk-clipboard.umd.min.js.map +1 -1
  24. package/bundles/cdk-coercion.umd.js.map +1 -1
  25. package/bundles/cdk-collections.umd.js +303 -237
  26. package/bundles/cdk-collections.umd.js.map +1 -1
  27. package/bundles/cdk-collections.umd.min.js +3 -9
  28. package/bundles/cdk-collections.umd.min.js.map +1 -1
  29. package/bundles/cdk-drag-drop.umd.js +1059 -927
  30. package/bundles/cdk-drag-drop.umd.js.map +1 -1
  31. package/bundles/cdk-drag-drop.umd.min.js +72 -10
  32. package/bundles/cdk-drag-drop.umd.min.js.map +1 -1
  33. package/bundles/cdk-keycodes.umd.js.map +1 -1
  34. package/bundles/cdk-layout.umd.js +18 -18
  35. package/bundles/cdk-layout.umd.js.map +1 -1
  36. package/bundles/cdk-layout.umd.min.js +6 -5
  37. package/bundles/cdk-layout.umd.min.js.map +1 -1
  38. package/bundles/cdk-observers.umd.js +34 -34
  39. package/bundles/cdk-observers.umd.js.map +1 -1
  40. package/bundles/cdk-observers.umd.min.js +2 -2
  41. package/bundles/cdk-observers.umd.min.js.map +1 -1
  42. package/bundles/cdk-overlay.umd.js +638 -416
  43. package/bundles/cdk-overlay.umd.js.map +1 -1
  44. package/bundles/cdk-overlay.umd.min.js +51 -12
  45. package/bundles/cdk-overlay.umd.min.js.map +1 -1
  46. package/bundles/cdk-platform.umd.js +10 -10
  47. package/bundles/cdk-platform.umd.js.map +1 -1
  48. package/bundles/cdk-platform.umd.min.js +4 -11
  49. package/bundles/cdk-platform.umd.min.js.map +1 -1
  50. package/bundles/cdk-portal.umd.js +355 -300
  51. package/bundles/cdk-portal.umd.js.map +1 -1
  52. package/bundles/cdk-portal.umd.min.js +4 -5
  53. package/bundles/cdk-portal.umd.min.js.map +1 -1
  54. package/bundles/cdk-scrolling.umd.js +482 -392
  55. package/bundles/cdk-scrolling.umd.js.map +1 -1
  56. package/bundles/cdk-scrolling.umd.min.js +20 -12
  57. package/bundles/cdk-scrolling.umd.min.js.map +1 -1
  58. package/bundles/cdk-stepper.umd.js +117 -117
  59. package/bundles/cdk-stepper.umd.js.map +1 -1
  60. package/bundles/cdk-stepper.umd.min.js +11 -2
  61. package/bundles/cdk-stepper.umd.min.js.map +1 -1
  62. package/bundles/cdk-table.umd.js +862 -607
  63. package/bundles/cdk-table.umd.js.map +1 -1
  64. package/bundles/cdk-table.umd.min.js +8 -15
  65. package/bundles/cdk-table.umd.min.js.map +1 -1
  66. package/bundles/cdk-testing-protractor.umd.js +300 -241
  67. package/bundles/cdk-testing-protractor.umd.js.map +1 -1
  68. package/bundles/cdk-testing-protractor.umd.min.js +2 -9
  69. package/bundles/cdk-testing-protractor.umd.min.js.map +1 -1
  70. package/bundles/cdk-testing-testbed.umd.js +337 -276
  71. package/bundles/cdk-testing-testbed.umd.js.map +1 -1
  72. package/bundles/cdk-testing-testbed.umd.min.js +7 -30
  73. package/bundles/cdk-testing-testbed.umd.min.js.map +1 -1
  74. package/bundles/cdk-testing.umd.js +358 -270
  75. package/bundles/cdk-testing.umd.js.map +1 -1
  76. package/bundles/cdk-testing.umd.min.js +3 -18
  77. package/bundles/cdk-testing.umd.min.js.map +1 -1
  78. package/bundles/cdk-text-field.umd.js +51 -51
  79. package/bundles/cdk-text-field.umd.js.map +1 -1
  80. package/bundles/cdk-text-field.umd.min.js +10 -2
  81. package/bundles/cdk-text-field.umd.min.js.map +1 -1
  82. package/bundles/cdk-tree.umd.js +449 -396
  83. package/bundles/cdk-tree.umd.js.map +1 -1
  84. package/bundles/cdk-tree.umd.min.js +28 -3
  85. package/bundles/cdk-tree.umd.min.js.map +1 -1
  86. package/bundles/cdk.umd.js +1 -1
  87. package/bundles/cdk.umd.js.map +1 -1
  88. package/bundles/cdk.umd.min.js +1 -1
  89. package/bundles/cdk.umd.min.js.map +1 -1
  90. package/drag-drop/clone-node.d.ts +9 -0
  91. package/drag-drop/directives/drag-handle.d.ts +8 -2
  92. package/drag-drop/directives/drag-placeholder.d.ts +7 -1
  93. package/drag-drop/directives/drag-preview.d.ts +7 -1
  94. package/drag-drop/directives/drag.d.ts +3 -7
  95. package/drag-drop/directives/drop-list-group.d.ts +7 -1
  96. package/drag-drop/directives/drop-list.d.ts +7 -1
  97. package/drag-drop/index.d.ts +2 -2
  98. package/drag-drop/index.metadata.json +1 -1
  99. package/drag-drop/parent-position-tracker.d.ts +1 -1
  100. package/esm2015/a11y/aria-describer/aria-describer.js +21 -7
  101. package/esm2015/a11y/focus-trap/configurable-focus-trap-factory.js +3 -3
  102. package/esm2015/a11y/focus-trap/focus-trap.js +1 -1
  103. package/esm2015/a11y/interactivity-checker/interactivity-checker.js +43 -30
  104. package/esm2015/a11y/key-manager/list-key-manager.js +27 -2
  105. package/esm2015/a11y/live-announcer/live-announcer.js +1 -1
  106. package/esm2015/accordion/accordion-item.js +7 -7
  107. package/esm2015/accordion/accordion.js +9 -2
  108. package/esm2015/accordion/index.js +2 -1
  109. package/esm2015/clipboard/pending-copy.js +7 -6
  110. package/esm2015/drag-drop/clone-node.js +54 -0
  111. package/esm2015/drag-drop/directives/drag-handle.js +12 -5
  112. package/esm2015/drag-drop/directives/drag-placeholder.js +10 -3
  113. package/esm2015/drag-drop/directives/drag-preview.js +10 -3
  114. package/esm2015/drag-drop/directives/drag.js +19 -15
  115. package/esm2015/drag-drop/directives/drop-list-group.js +9 -2
  116. package/esm2015/drag-drop/directives/drop-list.js +19 -8
  117. package/esm2015/drag-drop/drag-ref.js +2 -29
  118. package/esm2015/drag-drop/index.js +3 -2
  119. package/esm2015/layout/breakpoints-observer.js +1 -1
  120. package/esm2015/overlay/dispatchers/base-overlay-dispatcher.js +51 -0
  121. package/esm2015/overlay/dispatchers/index.js +10 -0
  122. package/esm2015/overlay/dispatchers/overlay-keyboard-dispatcher.js +79 -0
  123. package/esm2015/overlay/dispatchers/overlay-outside-click-dispatcher.js +94 -0
  124. package/esm2015/overlay/index.js +5 -4
  125. package/esm2015/overlay/overlay-config.js +5 -1
  126. package/esm2015/overlay/overlay-directives.js +34 -8
  127. package/esm2015/overlay/overlay-module.js +2 -2
  128. package/esm2015/overlay/overlay-ref.js +24 -2
  129. package/esm2015/overlay/overlay-reference.js +1 -1
  130. package/esm2015/overlay/overlay.js +10 -5
  131. package/esm2015/overlay/position/connected-position-strategy.js +1 -5
  132. package/esm2015/overlay/position/flexible-connected-position-strategy.js +3 -3
  133. package/esm2015/overlay/position/overlay-position-builder.js +1 -1
  134. package/esm2015/overlay/public-api.js +2 -2
  135. package/esm2015/portal/dom-portal-outlet.js +5 -2
  136. package/esm2015/scrolling/public-api.js +2 -1
  137. package/esm2015/scrolling/scrolling-module.js +4 -1
  138. package/esm2015/scrolling/viewport-ruler.js +24 -10
  139. package/esm2015/scrolling/virtual-for-of.js +26 -12
  140. package/esm2015/scrolling/virtual-scroll-repeater.js +8 -0
  141. package/esm2015/scrolling/virtual-scroll-viewport.js +2 -2
  142. package/esm2015/table/cell.js +18 -3
  143. package/esm2015/table/coalesced-style-scheduler.js +87 -0
  144. package/esm2015/table/public-api.js +2 -1
  145. package/esm2015/table/sticky-styler.js +79 -45
  146. package/esm2015/table/table.js +33 -12
  147. package/esm2015/testing/component-harness.js +19 -1
  148. package/esm2015/testing/harness-environment.js +7 -1
  149. package/esm2015/testing/testbed/fake-events/dispatch-events.js +5 -4
  150. package/esm2015/testing/testbed/fake-events/event-objects.js +10 -7
  151. package/esm2015/testing/testbed/fake-events/type-in-element.js +4 -4
  152. package/esm2015/testing/testbed/unit-test-element.js +20 -12
  153. package/esm2015/tree/control/nested-tree-control.js +7 -3
  154. package/esm2015/tree/tree.js +9 -23
  155. package/esm2015/version.js +1 -1
  156. package/fesm2015/a11y.js +88 -38
  157. package/fesm2015/a11y.js.map +1 -1
  158. package/fesm2015/accordion.js +13 -6
  159. package/fesm2015/accordion.js.map +1 -1
  160. package/fesm2015/cdk.js +1 -1
  161. package/fesm2015/cdk.js.map +1 -1
  162. package/fesm2015/clipboard.js +6 -5
  163. package/fesm2015/clipboard.js.map +1 -1
  164. package/fesm2015/drag-drop.js +669 -600
  165. package/fesm2015/drag-drop.js.map +1 -1
  166. package/fesm2015/overlay.js +215 -40
  167. package/fesm2015/overlay.js.map +1 -1
  168. package/fesm2015/portal.js +4 -1
  169. package/fesm2015/portal.js.map +1 -1
  170. package/fesm2015/scrolling.js +60 -21
  171. package/fesm2015/scrolling.js.map +1 -1
  172. package/fesm2015/table.js +214 -61
  173. package/fesm2015/table.js.map +1 -1
  174. package/fesm2015/testing/testbed.js +35 -23
  175. package/fesm2015/testing/testbed.js.map +1 -1
  176. package/fesm2015/testing.js +25 -1
  177. package/fesm2015/testing.js.map +1 -1
  178. package/fesm2015/tree.js +13 -23
  179. package/fesm2015/tree.js.map +1 -1
  180. package/overlay/dispatchers/base-overlay-dispatcher.d.ts +28 -0
  181. package/overlay/dispatchers/index.d.ts +9 -0
  182. package/overlay/{keyboard → dispatchers}/overlay-keyboard-dispatcher.d.ts +4 -10
  183. package/overlay/dispatchers/overlay-outside-click-dispatcher.d.ts +27 -0
  184. package/overlay/index.d.ts +4 -3
  185. package/overlay/index.metadata.json +1 -1
  186. package/overlay/overlay-config.d.ts +4 -0
  187. package/overlay/overlay-directives.d.ts +5 -0
  188. package/overlay/overlay-ref.d.ts +8 -2
  189. package/overlay/overlay-reference.d.ts +1 -0
  190. package/overlay/overlay.d.ts +4 -2
  191. package/overlay/position/connected-position-strategy.d.ts +0 -2
  192. package/overlay/public-api.d.ts +1 -1
  193. package/package.json +1 -1
  194. package/schematics/ng-add/index.js +1 -1
  195. package/scrolling/index.metadata.json +1 -1
  196. package/scrolling/public-api.d.ts +1 -0
  197. package/scrolling/scrolling-module.d.ts +3 -0
  198. package/scrolling/viewport-ruler.d.ts +2 -2
  199. package/scrolling/virtual-for-of.d.ts +2 -1
  200. package/scrolling/virtual-scroll-repeater.d.ts +16 -0
  201. package/scrolling/virtual-scroll-viewport.d.ts +4 -4
  202. package/table/cell.d.ts +13 -0
  203. package/table/coalesced-style-scheduler.d.ts +41 -0
  204. package/table/index.metadata.json +1 -1
  205. package/table/public-api.d.ts +1 -0
  206. package/table/sticky-styler.d.ts +7 -1
  207. package/table/table.d.ts +9 -1
  208. package/testing/component-harness.d.ts +12 -0
  209. package/testing/harness-environment.d.ts +1 -0
  210. package/testing/testbed/fake-events/dispatch-events.d.ts +3 -2
  211. package/testing/testbed/fake-events/event-objects.d.ts +2 -2
  212. package/testing/testbed/unit-test-element.d.ts +7 -0
  213. package/tree/control/nested-tree-control.d.ts +7 -2
  214. package/tree/index.metadata.json +1 -1
  215. package/tree/tree.d.ts +2 -4
  216. package/esm2015/overlay/keyboard/overlay-keyboard-dispatcher.js +0 -96
@@ -1,10 +1,10 @@
1
- import { ɵɵdefineInjectable, ɵɵinject, NgZone, Injectable, Inject, InjectionToken, Directive, ElementRef, Optional, Input, TemplateRef, EventEmitter, isDevMode, SkipSelf, ViewContainerRef, ChangeDetectorRef, ContentChildren, ContentChild, Output, NgModule } from '@angular/core';
1
+ import { ɵɵdefineInjectable, ɵɵinject, NgZone, Injectable, Inject, InjectionToken, Directive, Input, EventEmitter, isDevMode, ElementRef, ChangeDetectorRef, Optional, SkipSelf, Output, TemplateRef, ViewContainerRef, Self, ContentChildren, ContentChild, NgModule } from '@angular/core';
2
2
  import { DOCUMENT } from '@angular/common';
3
3
  import { ViewportRuler, ScrollDispatcher, CdkScrollableModule } from '@angular/cdk/scrolling';
4
4
  import { normalizePassiveListenerOptions, _getShadowRoot } from '@angular/cdk/platform';
5
- import { coerceBooleanProperty, coerceElement, coerceNumberProperty, coerceArray } from '@angular/cdk/coercion';
5
+ import { coerceBooleanProperty, coerceElement, coerceArray, coerceNumberProperty } from '@angular/cdk/coercion';
6
6
  import { Subject, Subscription, interval, animationFrameScheduler, Observable, merge } from 'rxjs';
7
- import { takeUntil, map, take, startWith, tap, switchMap } from 'rxjs/operators';
7
+ import { takeUntil, startWith, map, take, tap, switchMap } from 'rxjs/operators';
8
8
  import { Directionality } from '@angular/cdk/bidi';
9
9
 
10
10
  /**
@@ -211,6 +211,60 @@ class ParentPositionTracker {
211
211
  }
212
212
  }
213
213
 
214
+ /**
215
+ * @license
216
+ * Copyright Google LLC All Rights Reserved.
217
+ *
218
+ * Use of this source code is governed by an MIT-style license that can be
219
+ * found in the LICENSE file at https://angular.io/license
220
+ */
221
+ /** Creates a deep clone of an element. */
222
+ function deepCloneNode(node) {
223
+ const clone = node.cloneNode(true);
224
+ const descendantsWithId = clone.querySelectorAll('[id]');
225
+ const nodeName = node.nodeName.toLowerCase();
226
+ // Remove the `id` to avoid having multiple elements with the same id on the page.
227
+ clone.removeAttribute('id');
228
+ for (let i = 0; i < descendantsWithId.length; i++) {
229
+ descendantsWithId[i].removeAttribute('id');
230
+ }
231
+ if (nodeName === 'canvas') {
232
+ transferCanvasData(node, clone);
233
+ }
234
+ else if (nodeName === 'input' || nodeName === 'select' || nodeName === 'textarea') {
235
+ transferInputData(node, clone);
236
+ }
237
+ transferData('canvas', node, clone, transferCanvasData);
238
+ transferData('input, textarea, select', node, clone, transferInputData);
239
+ return clone;
240
+ }
241
+ /** Matches elements between an element and its clone and allows for their data to be cloned. */
242
+ function transferData(selector, node, clone, callback) {
243
+ const descendantElements = node.querySelectorAll(selector);
244
+ if (descendantElements.length) {
245
+ const cloneElements = clone.querySelectorAll(selector);
246
+ for (let i = 0; i < descendantElements.length; i++) {
247
+ callback(descendantElements[i], cloneElements[i]);
248
+ }
249
+ }
250
+ }
251
+ /** Transfers the data of one input element to another. */
252
+ function transferInputData(source, clone) {
253
+ clone.value = source.value;
254
+ }
255
+ /** Transfers the data of one canvas element to another. */
256
+ function transferCanvasData(source, clone) {
257
+ const context = clone.getContext('2d');
258
+ if (context) {
259
+ // In some cases `drawImage` can throw (e.g. if the canvas size is 0x0).
260
+ // We can't do much about it so just ignore the error.
261
+ try {
262
+ context.drawImage(source, 0, 0);
263
+ }
264
+ catch (_a) { }
265
+ }
266
+ }
267
+
214
268
  /**
215
269
  * @license
216
270
  * Copyright Google LLC All Rights Reserved.
@@ -1163,34 +1217,6 @@ function getTransform(x, y) {
1163
1217
  // blur the elements for sub-pixel transforms.
1164
1218
  return `translate3d(${Math.round(x)}px, ${Math.round(y)}px, 0)`;
1165
1219
  }
1166
- /** Creates a deep clone of an element. */
1167
- function deepCloneNode(node) {
1168
- const clone = node.cloneNode(true);
1169
- const descendantsWithId = clone.querySelectorAll('[id]');
1170
- const descendantCanvases = node.querySelectorAll('canvas');
1171
- // Remove the `id` to avoid having multiple elements with the same id on the page.
1172
- clone.removeAttribute('id');
1173
- for (let i = 0; i < descendantsWithId.length; i++) {
1174
- descendantsWithId[i].removeAttribute('id');
1175
- }
1176
- // `cloneNode` won't transfer the content of `canvas` elements so we have to do it ourselves.
1177
- // We match up the cloned canvas to their sources using their index in the DOM.
1178
- if (descendantCanvases.length) {
1179
- const cloneCanvases = clone.querySelectorAll('canvas');
1180
- for (let i = 0; i < descendantCanvases.length; i++) {
1181
- const correspondingCloneContext = cloneCanvases[i].getContext('2d');
1182
- if (correspondingCloneContext) {
1183
- // In some cases `drawImage` can throw (e.g. if the canvas size is 0x0).
1184
- // We can't do much about it so just ignore the error.
1185
- try {
1186
- correspondingCloneContext.drawImage(descendantCanvases[i], 0, 0);
1187
- }
1188
- catch (_a) { }
1189
- }
1190
- }
1191
- }
1192
- return clone;
1193
- }
1194
1220
  /** Clamps a value between a minimum and a maximum. */
1195
1221
  function clamp(value, min, max) {
1196
1222
  return Math.max(min, Math.min(max, value));
@@ -2361,115 +2387,41 @@ DragDrop.ctorParameters = () => [
2361
2387
  * found in the LICENSE file at https://angular.io/license
2362
2388
  */
2363
2389
  /**
2364
- * Injection token that can be used for a `CdkDrag` to provide itself as a parent to the
2365
- * drag-specific child directive (`CdkDragHandle`, `CdkDragPreview` etc.). Used primarily
2366
- * to avoid circular imports.
2367
- * @docs-private
2390
+ * Injection token that can be used to reference instances of `CdkDropListGroup`. It serves as
2391
+ * alternative token to the actual `CdkDropListGroup` class which could cause unnecessary
2392
+ * retention of the class and its directive metadata.
2368
2393
  */
2369
- const CDK_DRAG_PARENT = new InjectionToken('CDK_DRAG_PARENT');
2370
-
2394
+ const CDK_DROP_LIST_GROUP = new InjectionToken('CdkDropListGroup');
2371
2395
  /**
2372
- * @license
2373
- * Copyright Google LLC All Rights Reserved.
2374
- *
2375
- * Use of this source code is governed by an MIT-style license that can be
2376
- * found in the LICENSE file at https://angular.io/license
2396
+ * Declaratively connects sibling `cdkDropList` instances together. All of the `cdkDropList`
2397
+ * elements that are placed inside a `cdkDropListGroup` will be connected to each other
2398
+ * automatically. Can be used as an alternative to the `cdkDropListConnectedTo` input
2399
+ * from `cdkDropList`.
2377
2400
  */
2378
- /** Handle that can be used to drag and CdkDrag instance. */
2379
- class CdkDragHandle {
2380
- constructor(element, parentDrag) {
2381
- this.element = element;
2382
- /** Emits when the state of the handle has changed. */
2383
- this._stateChanges = new Subject();
2401
+ class CdkDropListGroup {
2402
+ constructor() {
2403
+ /** Drop lists registered inside the group. */
2404
+ this._items = new Set();
2384
2405
  this._disabled = false;
2385
- this._parentDrag = parentDrag;
2386
- toggleNativeDragInteractions(element.nativeElement, false);
2387
2406
  }
2388
- /** Whether starting to drag through this handle is disabled. */
2407
+ /** Whether starting a dragging sequence from inside this group is disabled. */
2389
2408
  get disabled() { return this._disabled; }
2390
2409
  set disabled(value) {
2391
2410
  this._disabled = coerceBooleanProperty(value);
2392
- this._stateChanges.next(this);
2393
2411
  }
2394
2412
  ngOnDestroy() {
2395
- this._stateChanges.complete();
2396
- }
2397
- }
2398
- CdkDragHandle.decorators = [
2399
- { type: Directive, args: [{
2400
- selector: '[cdkDragHandle]',
2401
- host: {
2402
- 'class': 'cdk-drag-handle'
2403
- }
2404
- },] }
2405
- ];
2406
- CdkDragHandle.ctorParameters = () => [
2407
- { type: ElementRef },
2408
- { type: undefined, decorators: [{ type: Inject, args: [CDK_DRAG_PARENT,] }, { type: Optional }] }
2409
- ];
2410
- CdkDragHandle.propDecorators = {
2411
- disabled: [{ type: Input, args: ['cdkDragHandleDisabled',] }]
2412
- };
2413
-
2414
- /**
2415
- * @license
2416
- * Copyright Google LLC All Rights Reserved.
2417
- *
2418
- * Use of this source code is governed by an MIT-style license that can be
2419
- * found in the LICENSE file at https://angular.io/license
2420
- */
2421
- /**
2422
- * Element that will be used as a template for the placeholder of a CdkDrag when
2423
- * it is being dragged. The placeholder is displayed in place of the element being dragged.
2424
- */
2425
- class CdkDragPlaceholder {
2426
- constructor(templateRef) {
2427
- this.templateRef = templateRef;
2428
- }
2429
- }
2430
- CdkDragPlaceholder.decorators = [
2431
- { type: Directive, args: [{
2432
- selector: 'ng-template[cdkDragPlaceholder]'
2433
- },] }
2434
- ];
2435
- CdkDragPlaceholder.ctorParameters = () => [
2436
- { type: TemplateRef }
2437
- ];
2438
- CdkDragPlaceholder.propDecorators = {
2439
- data: [{ type: Input }]
2440
- };
2441
-
2442
- /**
2443
- * @license
2444
- * Copyright Google LLC All Rights Reserved.
2445
- *
2446
- * Use of this source code is governed by an MIT-style license that can be
2447
- * found in the LICENSE file at https://angular.io/license
2448
- */
2449
- /**
2450
- * Element that will be used as a template for the preview
2451
- * of a CdkDrag when it is being dragged.
2452
- */
2453
- class CdkDragPreview {
2454
- constructor(templateRef) {
2455
- this.templateRef = templateRef;
2456
- this._matchSize = false;
2413
+ this._items.clear();
2457
2414
  }
2458
- /** Whether the preview should preserve the same size as the item that is being dragged. */
2459
- get matchSize() { return this._matchSize; }
2460
- set matchSize(value) { this._matchSize = coerceBooleanProperty(value); }
2461
2415
  }
2462
- CdkDragPreview.decorators = [
2416
+ CdkDropListGroup.decorators = [
2463
2417
  { type: Directive, args: [{
2464
- selector: 'ng-template[cdkDragPreview]'
2418
+ selector: '[cdkDropListGroup]',
2419
+ exportAs: 'cdkDropListGroup',
2420
+ providers: [{ provide: CDK_DROP_LIST_GROUP, useExisting: CdkDropListGroup }],
2465
2421
  },] }
2466
2422
  ];
2467
- CdkDragPreview.ctorParameters = () => [
2468
- { type: TemplateRef }
2469
- ];
2470
- CdkDragPreview.propDecorators = {
2471
- data: [{ type: Input }],
2472
- matchSize: [{ type: Input }]
2423
+ CdkDropListGroup.propDecorators = {
2424
+ disabled: [{ type: Input, args: ['cdkDropListGroupDisabled',] }]
2473
2425
  };
2474
2426
 
2475
2427
  /**
@@ -2492,250 +2444,204 @@ const CDK_DRAG_CONFIG = new InjectionToken('CDK_DRAG_CONFIG');
2492
2444
  * Use of this source code is governed by an MIT-style license that can be
2493
2445
  * found in the LICENSE file at https://angular.io/license
2494
2446
  */
2447
+ /** Counter used to generate unique ids for drop zones. */
2448
+ let _uniqueIdCounter = 0;
2495
2449
  /**
2496
- * Injection token that is used to provide a CdkDropList instance to CdkDrag.
2497
- * Used for avoiding circular imports.
2450
+ * Injection token that can be used to reference instances of `CdkDropList`. It serves as
2451
+ * alternative token to the actual `CdkDropList` class which could cause unnecessary
2452
+ * retention of the class and its directive metadata.
2498
2453
  */
2499
- const CDK_DROP_LIST = new InjectionToken('CDK_DROP_LIST');
2500
- /** Element that can be moved inside a CdkDropList container. */
2501
- class CdkDrag {
2454
+ const CDK_DROP_LIST = new InjectionToken('CdkDropList');
2455
+ const ɵ0 = undefined;
2456
+ /** Container that wraps a set of draggable items. */
2457
+ class CdkDropList {
2502
2458
  constructor(
2503
- /** Element that the draggable is attached to. */
2504
- element,
2505
- /** Droppable container that the draggable is a part of. */
2506
- dropContainer, _document, _ngZone, _viewContainerRef, config, _dir, dragDrop, _changeDetectorRef) {
2459
+ /** Element that the drop list is attached to. */
2460
+ element, dragDrop, _changeDetectorRef, _dir, _group,
2461
+ /**
2462
+ * @deprecated _scrollDispatcher parameter to become required.
2463
+ * @breaking-change 11.0.0
2464
+ */
2465
+ _scrollDispatcher, config) {
2507
2466
  this.element = element;
2508
- this.dropContainer = dropContainer;
2509
- this._document = _document;
2510
- this._ngZone = _ngZone;
2511
- this._viewContainerRef = _viewContainerRef;
2512
- this._dir = _dir;
2513
2467
  this._changeDetectorRef = _changeDetectorRef;
2468
+ this._dir = _dir;
2469
+ this._group = _group;
2470
+ this._scrollDispatcher = _scrollDispatcher;
2471
+ /** Emits when the list has been destroyed. */
2514
2472
  this._destroyed = new Subject();
2515
- /** Emits when the user starts dragging the item. */
2516
- this.started = new EventEmitter();
2517
- /** Emits when the user has released a drag item, before any animations have started. */
2518
- this.released = new EventEmitter();
2519
- /** Emits when the user stops dragging an item in the container. */
2520
- this.ended = new EventEmitter();
2521
- /** Emits when the user has moved the item into a new container. */
2473
+ /**
2474
+ * Other draggable containers that this container is connected to and into which the
2475
+ * container's items can be transferred. Can either be references to other drop containers,
2476
+ * or their unique IDs.
2477
+ */
2478
+ this.connectedTo = [];
2479
+ /**
2480
+ * Unique ID for the drop zone. Can be used as a reference
2481
+ * in the `connectedTo` of another `CdkDropList`.
2482
+ */
2483
+ this.id = `cdk-drop-list-${_uniqueIdCounter++}`;
2484
+ /**
2485
+ * Function that is used to determine whether an item
2486
+ * is allowed to be moved into a drop container.
2487
+ */
2488
+ this.enterPredicate = () => true;
2489
+ /** Emits when the user drops an item inside the container. */
2490
+ this.dropped = new EventEmitter();
2491
+ /**
2492
+ * Emits when the user has moved a new drag item into this container.
2493
+ */
2522
2494
  this.entered = new EventEmitter();
2523
- /** Emits when the user removes the item its container by dragging it into another container. */
2495
+ /**
2496
+ * Emits when the user removes an item from the container
2497
+ * by dragging it into another container.
2498
+ */
2524
2499
  this.exited = new EventEmitter();
2525
- /** Emits when the user drops the item inside a container. */
2526
- this.dropped = new EventEmitter();
2500
+ /** Emits as the user is swapping items while actively dragging. */
2501
+ this.sorted = new EventEmitter();
2527
2502
  /**
2528
- * Emits as the user is dragging the item. Use with caution,
2529
- * because this event will fire for every pixel that the user has dragged.
2503
+ * Keeps track of the items that are registered with this container. Historically we used to
2504
+ * do this with a `ContentChildren` query, however queries don't handle transplanted views very
2505
+ * well which means that we can't handle cases like dragging the headers of a `mat-table`
2506
+ * correctly. What we do instead is to have the items register themselves with the container
2507
+ * and then we sort them based on their position in the DOM.
2530
2508
  */
2531
- this.moved = new Observable((observer) => {
2532
- const subscription = this._dragRef.moved.pipe(map(movedEvent => ({
2533
- source: this,
2534
- pointerPosition: movedEvent.pointerPosition,
2535
- event: movedEvent.event,
2536
- delta: movedEvent.delta,
2537
- distance: movedEvent.distance
2538
- }))).subscribe(observer);
2539
- return () => {
2540
- subscription.unsubscribe();
2541
- };
2542
- });
2543
- this._dragRef = dragDrop.createDrag(element, {
2544
- dragStartThreshold: config && config.dragStartThreshold != null ?
2545
- config.dragStartThreshold : 5,
2546
- pointerDirectionChangeThreshold: config && config.pointerDirectionChangeThreshold != null ?
2547
- config.pointerDirectionChangeThreshold : 5,
2548
- zIndex: config === null || config === void 0 ? void 0 : config.zIndex
2549
- });
2550
- this._dragRef.data = this;
2509
+ this._unsortedItems = new Set();
2510
+ this._dropListRef = dragDrop.createDropList(element);
2511
+ this._dropListRef.data = this;
2551
2512
  if (config) {
2552
2513
  this._assignDefaults(config);
2553
2514
  }
2554
- // Note that usually the container is assigned when the drop list is picks up the item, but in
2555
- // some cases (mainly transplanted views with OnPush, see #18341) we may end up in a situation
2556
- // where there are no items on the first change detection pass, but the items get picked up as
2557
- // soon as the user triggers another pass by dragging. This is a problem, because the item would
2558
- // have to switch from standalone mode to drag mode in the middle of the dragging sequence which
2559
- // is too late since the two modes save different kinds of information. We work around it by
2560
- // assigning the drop container both from here and the list.
2561
- if (dropContainer) {
2562
- this._dragRef._withDropContainer(dropContainer._dropListRef);
2563
- dropContainer.addItem(this);
2564
- }
2565
- this._syncInputs(this._dragRef);
2566
- this._handleEvents(this._dragRef);
2567
- }
2568
- /** Whether starting to drag this element is disabled. */
2515
+ this._dropListRef.enterPredicate = (drag, drop) => {
2516
+ return this.enterPredicate(drag.data, drop.data);
2517
+ };
2518
+ this._setupInputSyncSubscription(this._dropListRef);
2519
+ this._handleEvents(this._dropListRef);
2520
+ CdkDropList._dropLists.push(this);
2521
+ if (_group) {
2522
+ _group._items.add(this);
2523
+ }
2524
+ }
2525
+ /** Whether starting a dragging sequence from this container is disabled. */
2569
2526
  get disabled() {
2570
- return this._disabled || (this.dropContainer && this.dropContainer.disabled);
2527
+ return this._disabled || (!!this._group && this._group.disabled);
2571
2528
  }
2572
2529
  set disabled(value) {
2573
- this._disabled = coerceBooleanProperty(value);
2574
- this._dragRef.disabled = this._disabled;
2575
- }
2576
- /**
2577
- * Returns the element that is being used as a placeholder
2578
- * while the current element is being dragged.
2579
- */
2580
- getPlaceholderElement() {
2581
- return this._dragRef.getPlaceholderElement();
2582
- }
2583
- /** Returns the root draggable element. */
2584
- getRootElement() {
2585
- return this._dragRef.getRootElement();
2530
+ // Usually we sync the directive and ref state right before dragging starts, in order to have
2531
+ // a single point of failure and to avoid having to use setters for everything. `disabled` is
2532
+ // a special case, because it can prevent the `beforeStarted` event from firing, which can lock
2533
+ // the user in a disabled state, so we also need to sync it as it's being set.
2534
+ this._dropListRef.disabled = this._disabled = coerceBooleanProperty(value);
2586
2535
  }
2587
- /** Resets a standalone drag item to its initial position. */
2588
- reset() {
2589
- this._dragRef.reset();
2536
+ /** Registers an items with the drop list. */
2537
+ addItem(item) {
2538
+ this._unsortedItems.add(item);
2539
+ if (this._dropListRef.isDragging()) {
2540
+ this._syncItemsWithRef();
2541
+ }
2590
2542
  }
2591
- /**
2592
- * Gets the pixel coordinates of the draggable outside of a drop container.
2593
- */
2594
- getFreeDragPosition() {
2595
- return this._dragRef.getFreeDragPosition();
2543
+ /** Removes an item from the drop list. */
2544
+ removeItem(item) {
2545
+ this._unsortedItems.delete(item);
2546
+ if (this._dropListRef.isDragging()) {
2547
+ this._syncItemsWithRef();
2548
+ }
2596
2549
  }
2597
- ngAfterViewInit() {
2598
- // We need to wait for the zone to stabilize, in order for the reference
2599
- // element to be in the proper place in the DOM. This is mostly relevant
2600
- // for draggable elements inside portals since they get stamped out in
2601
- // their original DOM position and then they get transferred to the portal.
2602
- this._ngZone.onStable.asObservable()
2603
- .pipe(take(1), takeUntil(this._destroyed))
2604
- .subscribe(() => {
2605
- this._updateRootElement();
2606
- // Listen for any newly-added handles.
2607
- this._handles.changes.pipe(startWith(this._handles),
2608
- // Sync the new handles with the DragRef.
2609
- tap((handles) => {
2610
- const childHandleElements = handles
2611
- .filter(handle => handle._parentDrag === this)
2612
- .map(handle => handle.element);
2613
- this._dragRef.withHandles(childHandleElements);
2614
- }),
2615
- // Listen if the state of any of the handles changes.
2616
- switchMap((handles) => {
2617
- return merge(...handles.map(item => {
2618
- return item._stateChanges.pipe(startWith(item));
2619
- }));
2620
- }), takeUntil(this._destroyed)).subscribe(handleInstance => {
2621
- // Enabled/disable the handle that changed in the DragRef.
2622
- const dragRef = this._dragRef;
2623
- const handle = handleInstance.element.nativeElement;
2624
- handleInstance.disabled ? dragRef.disableHandle(handle) : dragRef.enableHandle(handle);
2625
- });
2626
- if (this.freeDragPosition) {
2627
- this._dragRef.setFreeDragPosition(this.freeDragPosition);
2628
- }
2550
+ /** Gets the registered items in the list, sorted by their position in the DOM. */
2551
+ getSortedItems() {
2552
+ return Array.from(this._unsortedItems).sort((a, b) => {
2553
+ const documentPosition = a._dragRef.getVisibleElement().compareDocumentPosition(b._dragRef.getVisibleElement());
2554
+ // `compareDocumentPosition` returns a bitmask so we have to use a bitwise operator.
2555
+ // https://developer.mozilla.org/en-US/docs/Web/API/Node/compareDocumentPosition
2556
+ // tslint:disable-next-line:no-bitwise
2557
+ return documentPosition & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1;
2629
2558
  });
2630
2559
  }
2631
- ngOnChanges(changes) {
2632
- const rootSelectorChange = changes['rootElementSelector'];
2633
- const positionChange = changes['freeDragPosition'];
2634
- // We don't have to react to the first change since it's being
2635
- // handled in `ngAfterViewInit` where it needs to be deferred.
2636
- if (rootSelectorChange && !rootSelectorChange.firstChange) {
2637
- this._updateRootElement();
2638
- }
2639
- // Skip the first change since it's being handled in `ngAfterViewInit`.
2640
- if (positionChange && !positionChange.firstChange && this.freeDragPosition) {
2641
- this._dragRef.setFreeDragPosition(this.freeDragPosition);
2642
- }
2643
- }
2644
2560
  ngOnDestroy() {
2645
- if (this.dropContainer) {
2646
- this.dropContainer.removeItem(this);
2561
+ const index = CdkDropList._dropLists.indexOf(this);
2562
+ if (index > -1) {
2563
+ CdkDropList._dropLists.splice(index, 1);
2564
+ }
2565
+ if (this._group) {
2566
+ this._group._items.delete(this);
2647
2567
  }
2568
+ this._unsortedItems.clear();
2569
+ this._dropListRef.dispose();
2648
2570
  this._destroyed.next();
2649
2571
  this._destroyed.complete();
2650
- this._dragRef.dispose();
2651
- }
2652
- /** Syncs the root element with the `DragRef`. */
2653
- _updateRootElement() {
2654
- const element = this.element.nativeElement;
2655
- const rootElement = this.rootElementSelector ?
2656
- getClosestMatchingAncestor(element, this.rootElementSelector) : element;
2657
- if (rootElement && rootElement.nodeType !== this._document.ELEMENT_NODE) {
2658
- throw Error(`cdkDrag must be attached to an element node. ` +
2659
- `Currently attached to "${rootElement.nodeName}".`);
2660
- }
2661
- this._dragRef.withRootElement(rootElement || element);
2662
2572
  }
2663
- /** Gets the boundary element, based on the `boundaryElement` value. */
2664
- _getBoundaryElement() {
2665
- const boundary = this.boundaryElement;
2666
- if (!boundary) {
2667
- return null;
2668
- }
2669
- if (typeof boundary === 'string') {
2670
- return getClosestMatchingAncestor(this.element.nativeElement, boundary);
2671
- }
2672
- const element = coerceElement(boundary);
2673
- if (isDevMode() && !element.contains(this.element.nativeElement)) {
2674
- throw Error('Draggable element is not inside of the node passed into cdkDragBoundary.');
2573
+ /** Syncs the inputs of the CdkDropList with the options of the underlying DropListRef. */
2574
+ _setupInputSyncSubscription(ref) {
2575
+ if (this._dir) {
2576
+ this._dir.change
2577
+ .pipe(startWith(this._dir.value), takeUntil(this._destroyed))
2578
+ .subscribe(value => ref.withDirection(value));
2675
2579
  }
2676
- return element;
2677
- }
2678
- /** Syncs the inputs of the CdkDrag with the options of the underlying DragRef. */
2679
- _syncInputs(ref) {
2680
2580
  ref.beforeStarted.subscribe(() => {
2681
- if (!ref.isDragging()) {
2682
- const dir = this._dir;
2683
- const dragStartDelay = this.dragStartDelay;
2684
- const placeholder = this._placeholderTemplate ? {
2685
- template: this._placeholderTemplate.templateRef,
2686
- context: this._placeholderTemplate.data,
2687
- viewContainer: this._viewContainerRef
2688
- } : null;
2689
- const preview = this._previewTemplate ? {
2690
- template: this._previewTemplate.templateRef,
2691
- context: this._previewTemplate.data,
2692
- matchSize: this._previewTemplate.matchSize,
2693
- viewContainer: this._viewContainerRef
2694
- } : null;
2695
- ref.disabled = this.disabled;
2696
- ref.lockAxis = this.lockAxis;
2697
- ref.dragStartDelay = (typeof dragStartDelay === 'object' && dragStartDelay) ?
2698
- dragStartDelay : coerceNumberProperty(dragStartDelay);
2699
- ref.constrainPosition = this.constrainPosition;
2700
- ref.previewClass = this.previewClass;
2701
- ref
2702
- .withBoundaryElement(this._getBoundaryElement())
2703
- .withPlaceholderTemplate(placeholder)
2704
- .withPreviewTemplate(preview);
2705
- if (dir) {
2706
- ref.withDirection(dir.value);
2581
+ const siblings = coerceArray(this.connectedTo).map(drop => {
2582
+ if (typeof drop === 'string') {
2583
+ const correspondingDropList = CdkDropList._dropLists.find(list => list.id === drop);
2584
+ if (!correspondingDropList && isDevMode()) {
2585
+ console.warn(`CdkDropList could not find connected drop list with id "${drop}"`);
2586
+ }
2587
+ return correspondingDropList;
2707
2588
  }
2589
+ return drop;
2590
+ });
2591
+ if (this._group) {
2592
+ this._group._items.forEach(drop => {
2593
+ if (siblings.indexOf(drop) === -1) {
2594
+ siblings.push(drop);
2595
+ }
2596
+ });
2597
+ }
2598
+ // Note that we resolve the scrollable parents here so that we delay the resolution
2599
+ // as long as possible, ensuring that the element is in its final place in the DOM.
2600
+ // @breaking-change 11.0.0 Remove null check for _scrollDispatcher once it's required.
2601
+ if (!this._scrollableParentsResolved && this._scrollDispatcher) {
2602
+ const scrollableParents = this._scrollDispatcher
2603
+ .getAncestorScrollContainers(this.element)
2604
+ .map(scrollable => scrollable.getElementRef().nativeElement);
2605
+ this._dropListRef.withScrollableParents(scrollableParents);
2606
+ // Only do this once since it involves traversing the DOM and the parents
2607
+ // shouldn't be able to change without the drop list being destroyed.
2608
+ this._scrollableParentsResolved = true;
2708
2609
  }
2610
+ ref.disabled = this.disabled;
2611
+ ref.lockAxis = this.lockAxis;
2612
+ ref.sortingDisabled = coerceBooleanProperty(this.sortingDisabled);
2613
+ ref.autoScrollDisabled = coerceBooleanProperty(this.autoScrollDisabled);
2614
+ ref
2615
+ .connectedTo(siblings.filter(drop => drop && drop !== this).map(list => list._dropListRef))
2616
+ .withOrientation(this.orientation);
2709
2617
  });
2710
2618
  }
2711
- /** Handles the events from the underlying `DragRef`. */
2619
+ /** Handles events from the underlying DropListRef. */
2712
2620
  _handleEvents(ref) {
2713
- ref.started.subscribe(() => {
2714
- this.started.emit({ source: this });
2715
- // Since all of these events run outside of change detection,
2716
- // we need to ensure that everything is marked correctly.
2717
- this._changeDetectorRef.markForCheck();
2718
- });
2719
- ref.released.subscribe(() => {
2720
- this.released.emit({ source: this });
2721
- });
2722
- ref.ended.subscribe(event => {
2723
- this.ended.emit({ source: this, distance: event.distance });
2724
- // Since all of these events run outside of change detection,
2725
- // we need to ensure that everything is marked correctly.
2621
+ ref.beforeStarted.subscribe(() => {
2622
+ this._syncItemsWithRef();
2726
2623
  this._changeDetectorRef.markForCheck();
2727
2624
  });
2728
2625
  ref.entered.subscribe(event => {
2729
2626
  this.entered.emit({
2730
- container: event.container.data,
2731
- item: this,
2627
+ container: this,
2628
+ item: event.item.data,
2732
2629
  currentIndex: event.currentIndex
2733
2630
  });
2734
2631
  });
2735
2632
  ref.exited.subscribe(event => {
2736
2633
  this.exited.emit({
2737
- container: event.container.data,
2738
- item: this
2634
+ container: this,
2635
+ item: event.item.data
2636
+ });
2637
+ this._changeDetectorRef.markForCheck();
2638
+ });
2639
+ ref.sorted.subscribe(event => {
2640
+ this.sorted.emit({
2641
+ previousIndex: event.previousIndex,
2642
+ currentIndex: event.currentIndex,
2643
+ container: this,
2644
+ item: event.item.data
2739
2645
  });
2740
2646
  });
2741
2647
  ref.dropped.subscribe(event => {
@@ -2744,91 +2650,75 @@ class CdkDrag {
2744
2650
  currentIndex: event.currentIndex,
2745
2651
  previousContainer: event.previousContainer.data,
2746
2652
  container: event.container.data,
2653
+ item: event.item.data,
2747
2654
  isPointerOverContainer: event.isPointerOverContainer,
2748
- item: this,
2749
2655
  distance: event.distance
2750
2656
  });
2657
+ // Mark for check since all of these events run outside of change
2658
+ // detection and we're not guaranteed for something else to have triggered it.
2659
+ this._changeDetectorRef.markForCheck();
2751
2660
  });
2752
2661
  }
2753
2662
  /** Assigns the default input values based on a provided config object. */
2754
2663
  _assignDefaults(config) {
2755
- const { lockAxis, dragStartDelay, constrainPosition, previewClass, boundaryElement, draggingDisabled, rootElementSelector } = config;
2664
+ const { lockAxis, draggingDisabled, sortingDisabled, listAutoScrollDisabled, listOrientation } = config;
2756
2665
  this.disabled = draggingDisabled == null ? false : draggingDisabled;
2757
- this.dragStartDelay = dragStartDelay || 0;
2666
+ this.sortingDisabled = sortingDisabled == null ? false : sortingDisabled;
2667
+ this.autoScrollDisabled = listAutoScrollDisabled == null ? false : listAutoScrollDisabled;
2668
+ this.orientation = listOrientation || 'vertical';
2758
2669
  if (lockAxis) {
2759
2670
  this.lockAxis = lockAxis;
2760
2671
  }
2761
- if (constrainPosition) {
2762
- this.constrainPosition = constrainPosition;
2763
- }
2764
- if (previewClass) {
2765
- this.previewClass = previewClass;
2766
- }
2767
- if (boundaryElement) {
2768
- this.boundaryElement = boundaryElement;
2769
- }
2770
- if (rootElementSelector) {
2771
- this.rootElementSelector = rootElementSelector;
2772
- }
2672
+ }
2673
+ /** Syncs up the registered drag items with underlying drop list ref. */
2674
+ _syncItemsWithRef() {
2675
+ this._dropListRef.withItems(this.getSortedItems().map(item => item._dragRef));
2773
2676
  }
2774
2677
  }
2775
- CdkDrag.decorators = [
2678
+ /** Keeps track of the drop lists that are currently on the page. */
2679
+ CdkDropList._dropLists = [];
2680
+ CdkDropList.decorators = [
2776
2681
  { type: Directive, args: [{
2777
- selector: '[cdkDrag]',
2778
- exportAs: 'cdkDrag',
2682
+ selector: '[cdkDropList], cdk-drop-list',
2683
+ exportAs: 'cdkDropList',
2684
+ providers: [
2685
+ // Prevent child drop lists from picking up the same group as their parent.
2686
+ { provide: CDK_DROP_LIST_GROUP, useValue: ɵ0 },
2687
+ { provide: CDK_DROP_LIST, useExisting: CdkDropList },
2688
+ ],
2779
2689
  host: {
2780
- 'class': 'cdk-drag',
2781
- '[class.cdk-drag-disabled]': 'disabled',
2782
- '[class.cdk-drag-dragging]': '_dragRef.isDragging()',
2783
- },
2784
- providers: [{ provide: CDK_DRAG_PARENT, useExisting: CdkDrag }]
2690
+ 'class': 'cdk-drop-list',
2691
+ '[id]': 'id',
2692
+ '[class.cdk-drop-list-disabled]': 'disabled',
2693
+ '[class.cdk-drop-list-dragging]': '_dropListRef.isDragging()',
2694
+ '[class.cdk-drop-list-receiving]': '_dropListRef.isReceiving()',
2695
+ }
2785
2696
  },] }
2786
2697
  ];
2787
- CdkDrag.ctorParameters = () => [
2698
+ CdkDropList.ctorParameters = () => [
2788
2699
  { type: ElementRef },
2789
- { type: undefined, decorators: [{ type: Inject, args: [CDK_DROP_LIST,] }, { type: Optional }, { type: SkipSelf }] },
2790
- { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] }] },
2791
- { type: NgZone },
2792
- { type: ViewContainerRef },
2793
- { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [CDK_DRAG_CONFIG,] }] },
2794
- { type: Directionality, decorators: [{ type: Optional }] },
2795
2700
  { type: DragDrop },
2796
- { type: ChangeDetectorRef }
2701
+ { type: ChangeDetectorRef },
2702
+ { type: Directionality, decorators: [{ type: Optional }] },
2703
+ { type: CdkDropListGroup, decorators: [{ type: Optional }, { type: Inject, args: [CDK_DROP_LIST_GROUP,] }, { type: SkipSelf }] },
2704
+ { type: ScrollDispatcher },
2705
+ { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [CDK_DRAG_CONFIG,] }] }
2797
2706
  ];
2798
- CdkDrag.propDecorators = {
2799
- _handles: [{ type: ContentChildren, args: [CdkDragHandle, { descendants: true },] }],
2800
- _previewTemplate: [{ type: ContentChild, args: [CdkDragPreview,] }],
2801
- _placeholderTemplate: [{ type: ContentChild, args: [CdkDragPlaceholder,] }],
2802
- data: [{ type: Input, args: ['cdkDragData',] }],
2803
- lockAxis: [{ type: Input, args: ['cdkDragLockAxis',] }],
2804
- rootElementSelector: [{ type: Input, args: ['cdkDragRootElement',] }],
2805
- boundaryElement: [{ type: Input, args: ['cdkDragBoundary',] }],
2806
- dragStartDelay: [{ type: Input, args: ['cdkDragStartDelay',] }],
2807
- freeDragPosition: [{ type: Input, args: ['cdkDragFreeDragPosition',] }],
2808
- disabled: [{ type: Input, args: ['cdkDragDisabled',] }],
2809
- constrainPosition: [{ type: Input, args: ['cdkDragConstrainPosition',] }],
2810
- previewClass: [{ type: Input, args: ['cdkDragPreviewClass',] }],
2811
- started: [{ type: Output, args: ['cdkDragStarted',] }],
2812
- released: [{ type: Output, args: ['cdkDragReleased',] }],
2813
- ended: [{ type: Output, args: ['cdkDragEnded',] }],
2814
- entered: [{ type: Output, args: ['cdkDragEntered',] }],
2815
- exited: [{ type: Output, args: ['cdkDragExited',] }],
2816
- dropped: [{ type: Output, args: ['cdkDragDropped',] }],
2817
- moved: [{ type: Output, args: ['cdkDragMoved',] }]
2707
+ CdkDropList.propDecorators = {
2708
+ connectedTo: [{ type: Input, args: ['cdkDropListConnectedTo',] }],
2709
+ data: [{ type: Input, args: ['cdkDropListData',] }],
2710
+ orientation: [{ type: Input, args: ['cdkDropListOrientation',] }],
2711
+ id: [{ type: Input }],
2712
+ lockAxis: [{ type: Input, args: ['cdkDropListLockAxis',] }],
2713
+ disabled: [{ type: Input, args: ['cdkDropListDisabled',] }],
2714
+ sortingDisabled: [{ type: Input, args: ['cdkDropListSortingDisabled',] }],
2715
+ enterPredicate: [{ type: Input, args: ['cdkDropListEnterPredicate',] }],
2716
+ autoScrollDisabled: [{ type: Input, args: ['cdkDropListAutoScrollDisabled',] }],
2717
+ dropped: [{ type: Output, args: ['cdkDropListDropped',] }],
2718
+ entered: [{ type: Output, args: ['cdkDropListEntered',] }],
2719
+ exited: [{ type: Output, args: ['cdkDropListExited',] }],
2720
+ sorted: [{ type: Output, args: ['cdkDropListSorted',] }]
2818
2721
  };
2819
- /** Gets the closest ancestor of an element that matches a selector. */
2820
- function getClosestMatchingAncestor(element, selector) {
2821
- let currentElement = element.parentElement;
2822
- while (currentElement) {
2823
- // IE doesn't support `matches` so we have to fall back to `msMatchesSelector`.
2824
- if (currentElement.matches ? currentElement.matches(selector) :
2825
- currentElement.msMatchesSelector(selector)) {
2826
- return currentElement;
2827
- }
2828
- currentElement = currentElement.parentElement;
2829
- }
2830
- return null;
2831
- }
2832
2722
 
2833
2723
  /**
2834
2724
  * @license
@@ -2838,34 +2728,61 @@ function getClosestMatchingAncestor(element, selector) {
2838
2728
  * found in the LICENSE file at https://angular.io/license
2839
2729
  */
2840
2730
  /**
2841
- * Declaratively connects sibling `cdkDropList` instances together. All of the `cdkDropList`
2842
- * elements that are placed inside a `cdkDropListGroup` will be connected to each other
2843
- * automatically. Can be used as an alternative to the `cdkDropListConnectedTo` input
2844
- * from `cdkDropList`.
2731
+ * Injection token that can be used for a `CdkDrag` to provide itself as a parent to the
2732
+ * drag-specific child directive (`CdkDragHandle`, `CdkDragPreview` etc.). Used primarily
2733
+ * to avoid circular imports.
2734
+ * @docs-private
2845
2735
  */
2846
- class CdkDropListGroup {
2847
- constructor() {
2848
- /** Drop lists registered inside the group. */
2849
- this._items = new Set();
2736
+ const CDK_DRAG_PARENT = new InjectionToken('CDK_DRAG_PARENT');
2737
+
2738
+ /**
2739
+ * @license
2740
+ * Copyright Google LLC All Rights Reserved.
2741
+ *
2742
+ * Use of this source code is governed by an MIT-style license that can be
2743
+ * found in the LICENSE file at https://angular.io/license
2744
+ */
2745
+ /**
2746
+ * Injection token that can be used to reference instances of `CdkDragHandle`. It serves as
2747
+ * alternative token to the actual `CdkDragHandle` class which could cause unnecessary
2748
+ * retention of the class and its directive metadata.
2749
+ */
2750
+ const CDK_DRAG_HANDLE = new InjectionToken('CdkDragHandle');
2751
+ /** Handle that can be used to drag a CdkDrag instance. */
2752
+ class CdkDragHandle {
2753
+ constructor(element, parentDrag) {
2754
+ this.element = element;
2755
+ /** Emits when the state of the handle has changed. */
2756
+ this._stateChanges = new Subject();
2850
2757
  this._disabled = false;
2758
+ this._parentDrag = parentDrag;
2759
+ toggleNativeDragInteractions(element.nativeElement, false);
2851
2760
  }
2852
- /** Whether starting a dragging sequence from inside this group is disabled. */
2761
+ /** Whether starting to drag through this handle is disabled. */
2853
2762
  get disabled() { return this._disabled; }
2854
2763
  set disabled(value) {
2855
2764
  this._disabled = coerceBooleanProperty(value);
2765
+ this._stateChanges.next(this);
2856
2766
  }
2857
2767
  ngOnDestroy() {
2858
- this._items.clear();
2768
+ this._stateChanges.complete();
2859
2769
  }
2860
2770
  }
2861
- CdkDropListGroup.decorators = [
2771
+ CdkDragHandle.decorators = [
2862
2772
  { type: Directive, args: [{
2863
- selector: '[cdkDropListGroup]',
2864
- exportAs: 'cdkDropListGroup',
2773
+ selector: '[cdkDragHandle]',
2774
+ host: {
2775
+ 'class': 'cdk-drag-handle'
2776
+ },
2777
+ providers: [{ provide: CDK_DRAG_HANDLE, useExisting: CdkDragHandle }],
2865
2778
  },] }
2866
2779
  ];
2867
- CdkDropListGroup.propDecorators = {
2868
- disabled: [{ type: Input, args: ['cdkDropListGroupDisabled',] }]
2780
+ CdkDragHandle.ctorParameters = () => [
2781
+ { type: ElementRef },
2782
+ { type: undefined, decorators: [{ type: Inject, args: [CDK_DRAG_PARENT,] }, { type: Optional }, { type: SkipSelf }] }
2783
+ ];
2784
+ CdkDragHandle.propDecorators = {
2785
+ disabled: [{ type: Input, args: ['cdkDragHandleDisabled',] }]
2869
2786
  };
2870
2787
 
2871
2788
  /**
@@ -2875,192 +2792,327 @@ CdkDropListGroup.propDecorators = {
2875
2792
  * Use of this source code is governed by an MIT-style license that can be
2876
2793
  * found in the LICENSE file at https://angular.io/license
2877
2794
  */
2878
- /** Counter used to generate unique ids for drop zones. */
2879
- let _uniqueIdCounter = 0;
2880
- const ɵ0 = undefined;
2881
- /** Container that wraps a set of draggable items. */
2882
- class CdkDropList {
2795
+ /**
2796
+ * Injection token that can be used to reference instances of `CdkDragPlaceholder`. It serves as
2797
+ * alternative token to the actual `CdkDragPlaceholder` class which could cause unnecessary
2798
+ * retention of the class and its directive metadata.
2799
+ */
2800
+ const CDK_DRAG_PLACEHOLDER = new InjectionToken('CdkDragPlaceholder');
2801
+ /**
2802
+ * Element that will be used as a template for the placeholder of a CdkDrag when
2803
+ * it is being dragged. The placeholder is displayed in place of the element being dragged.
2804
+ */
2805
+ class CdkDragPlaceholder {
2806
+ constructor(templateRef) {
2807
+ this.templateRef = templateRef;
2808
+ }
2809
+ }
2810
+ CdkDragPlaceholder.decorators = [
2811
+ { type: Directive, args: [{
2812
+ selector: 'ng-template[cdkDragPlaceholder]',
2813
+ providers: [{ provide: CDK_DRAG_PLACEHOLDER, useExisting: CdkDragPlaceholder }],
2814
+ },] }
2815
+ ];
2816
+ CdkDragPlaceholder.ctorParameters = () => [
2817
+ { type: TemplateRef }
2818
+ ];
2819
+ CdkDragPlaceholder.propDecorators = {
2820
+ data: [{ type: Input }]
2821
+ };
2822
+
2823
+ /**
2824
+ * @license
2825
+ * Copyright Google LLC All Rights Reserved.
2826
+ *
2827
+ * Use of this source code is governed by an MIT-style license that can be
2828
+ * found in the LICENSE file at https://angular.io/license
2829
+ */
2830
+ /**
2831
+ * Injection token that can be used to reference instances of `CdkDragPreview`. It serves as
2832
+ * alternative token to the actual `CdkDragPreview` class which could cause unnecessary
2833
+ * retention of the class and its directive metadata.
2834
+ */
2835
+ const CDK_DRAG_PREVIEW = new InjectionToken('CdkDragPreview');
2836
+ /**
2837
+ * Element that will be used as a template for the preview
2838
+ * of a CdkDrag when it is being dragged.
2839
+ */
2840
+ class CdkDragPreview {
2841
+ constructor(templateRef) {
2842
+ this.templateRef = templateRef;
2843
+ this._matchSize = false;
2844
+ }
2845
+ /** Whether the preview should preserve the same size as the item that is being dragged. */
2846
+ get matchSize() { return this._matchSize; }
2847
+ set matchSize(value) { this._matchSize = coerceBooleanProperty(value); }
2848
+ }
2849
+ CdkDragPreview.decorators = [
2850
+ { type: Directive, args: [{
2851
+ selector: 'ng-template[cdkDragPreview]',
2852
+ providers: [{ provide: CDK_DRAG_PREVIEW, useExisting: CdkDragPreview }],
2853
+ },] }
2854
+ ];
2855
+ CdkDragPreview.ctorParameters = () => [
2856
+ { type: TemplateRef }
2857
+ ];
2858
+ CdkDragPreview.propDecorators = {
2859
+ data: [{ type: Input }],
2860
+ matchSize: [{ type: Input }]
2861
+ };
2862
+
2863
+ /**
2864
+ * @license
2865
+ * Copyright Google LLC All Rights Reserved.
2866
+ *
2867
+ * Use of this source code is governed by an MIT-style license that can be
2868
+ * found in the LICENSE file at https://angular.io/license
2869
+ */
2870
+ /** Element that can be moved inside a CdkDropList container. */
2871
+ class CdkDrag {
2883
2872
  constructor(
2884
- /** Element that the drop list is attached to. */
2885
- element, dragDrop, _changeDetectorRef, _dir, _group,
2886
- /**
2887
- * @deprecated _scrollDispatcher parameter to become required.
2888
- * @breaking-change 11.0.0
2889
- */
2890
- _scrollDispatcher, config) {
2873
+ /** Element that the draggable is attached to. */
2874
+ element,
2875
+ /** Droppable container that the draggable is a part of. */
2876
+ dropContainer, _document, _ngZone, _viewContainerRef, config, _dir, dragDrop, _changeDetectorRef, _selfHandle) {
2891
2877
  this.element = element;
2892
- this._changeDetectorRef = _changeDetectorRef;
2878
+ this.dropContainer = dropContainer;
2879
+ this._document = _document;
2880
+ this._ngZone = _ngZone;
2881
+ this._viewContainerRef = _viewContainerRef;
2893
2882
  this._dir = _dir;
2894
- this._group = _group;
2895
- this._scrollDispatcher = _scrollDispatcher;
2896
- /** Emits when the list has been destroyed. */
2883
+ this._changeDetectorRef = _changeDetectorRef;
2884
+ this._selfHandle = _selfHandle;
2897
2885
  this._destroyed = new Subject();
2898
- /**
2899
- * Other draggable containers that this container is connected to and into which the
2900
- * container's items can be transferred. Can either be references to other drop containers,
2901
- * or their unique IDs.
2902
- */
2903
- this.connectedTo = [];
2904
- /**
2905
- * Unique ID for the drop zone. Can be used as a reference
2906
- * in the `connectedTo` of another `CdkDropList`.
2907
- */
2908
- this.id = `cdk-drop-list-${_uniqueIdCounter++}`;
2909
- /**
2910
- * Function that is used to determine whether an item
2911
- * is allowed to be moved into a drop container.
2912
- */
2913
- this.enterPredicate = () => true;
2914
- /** Emits when the user drops an item inside the container. */
2915
- this.dropped = new EventEmitter();
2916
- /**
2917
- * Emits when the user has moved a new drag item into this container.
2918
- */
2886
+ /** Emits when the user starts dragging the item. */
2887
+ this.started = new EventEmitter();
2888
+ /** Emits when the user has released a drag item, before any animations have started. */
2889
+ this.released = new EventEmitter();
2890
+ /** Emits when the user stops dragging an item in the container. */
2891
+ this.ended = new EventEmitter();
2892
+ /** Emits when the user has moved the item into a new container. */
2919
2893
  this.entered = new EventEmitter();
2920
- /**
2921
- * Emits when the user removes an item from the container
2922
- * by dragging it into another container.
2923
- */
2894
+ /** Emits when the user removes the item its container by dragging it into another container. */
2924
2895
  this.exited = new EventEmitter();
2925
- /** Emits as the user is swapping items while actively dragging. */
2926
- this.sorted = new EventEmitter();
2896
+ /** Emits when the user drops the item inside a container. */
2897
+ this.dropped = new EventEmitter();
2927
2898
  /**
2928
- * Keeps track of the items that are registered with this container. Historically we used to
2929
- * do this with a `ContentChildren` query, however queries don't handle transplanted views very
2930
- * well which means that we can't handle cases like dragging the headers of a `mat-table`
2931
- * correctly. What we do instead is to have the items register themselves with the container
2932
- * and then we sort them based on their position in the DOM.
2899
+ * Emits as the user is dragging the item. Use with caution,
2900
+ * because this event will fire for every pixel that the user has dragged.
2933
2901
  */
2934
- this._unsortedItems = new Set();
2935
- this._dropListRef = dragDrop.createDropList(element);
2936
- this._dropListRef.data = this;
2902
+ this.moved = new Observable((observer) => {
2903
+ const subscription = this._dragRef.moved.pipe(map(movedEvent => ({
2904
+ source: this,
2905
+ pointerPosition: movedEvent.pointerPosition,
2906
+ event: movedEvent.event,
2907
+ delta: movedEvent.delta,
2908
+ distance: movedEvent.distance
2909
+ }))).subscribe(observer);
2910
+ return () => {
2911
+ subscription.unsubscribe();
2912
+ };
2913
+ });
2914
+ this._dragRef = dragDrop.createDrag(element, {
2915
+ dragStartThreshold: config && config.dragStartThreshold != null ?
2916
+ config.dragStartThreshold : 5,
2917
+ pointerDirectionChangeThreshold: config && config.pointerDirectionChangeThreshold != null ?
2918
+ config.pointerDirectionChangeThreshold : 5,
2919
+ zIndex: config === null || config === void 0 ? void 0 : config.zIndex
2920
+ });
2921
+ this._dragRef.data = this;
2937
2922
  if (config) {
2938
2923
  this._assignDefaults(config);
2939
2924
  }
2940
- this._dropListRef.enterPredicate = (drag, drop) => {
2941
- return this.enterPredicate(drag.data, drop.data);
2942
- };
2943
- this._setupInputSyncSubscription(this._dropListRef);
2944
- this._handleEvents(this._dropListRef);
2945
- CdkDropList._dropLists.push(this);
2946
- if (_group) {
2947
- _group._items.add(this);
2925
+ // Note that usually the container is assigned when the drop list is picks up the item, but in
2926
+ // some cases (mainly transplanted views with OnPush, see #18341) we may end up in a situation
2927
+ // where there are no items on the first change detection pass, but the items get picked up as
2928
+ // soon as the user triggers another pass by dragging. This is a problem, because the item would
2929
+ // have to switch from standalone mode to drag mode in the middle of the dragging sequence which
2930
+ // is too late since the two modes save different kinds of information. We work around it by
2931
+ // assigning the drop container both from here and the list.
2932
+ if (dropContainer) {
2933
+ this._dragRef._withDropContainer(dropContainer._dropListRef);
2934
+ dropContainer.addItem(this);
2948
2935
  }
2936
+ this._syncInputs(this._dragRef);
2937
+ this._handleEvents(this._dragRef);
2949
2938
  }
2950
- /** Whether starting a dragging sequence from this container is disabled. */
2939
+ /** Whether starting to drag this element is disabled. */
2951
2940
  get disabled() {
2952
- return this._disabled || (!!this._group && this._group.disabled);
2941
+ return this._disabled || (this.dropContainer && this.dropContainer.disabled);
2953
2942
  }
2954
2943
  set disabled(value) {
2955
- // Usually we sync the directive and ref state right before dragging starts, in order to have
2956
- // a single point of failure and to avoid having to use setters for everything. `disabled` is
2957
- // a special case, because it can prevent the `beforeStarted` event from firing, which can lock
2958
- // the user in a disabled state, so we also need to sync it as it's being set.
2959
- this._dropListRef.disabled = this._disabled = coerceBooleanProperty(value);
2944
+ this._disabled = coerceBooleanProperty(value);
2945
+ this._dragRef.disabled = this._disabled;
2960
2946
  }
2961
- /** Registers an items with the drop list. */
2962
- addItem(item) {
2963
- this._unsortedItems.add(item);
2964
- if (this._dropListRef.isDragging()) {
2965
- this._syncItemsWithRef();
2947
+ /**
2948
+ * Returns the element that is being used as a placeholder
2949
+ * while the current element is being dragged.
2950
+ */
2951
+ getPlaceholderElement() {
2952
+ return this._dragRef.getPlaceholderElement();
2953
+ }
2954
+ /** Returns the root draggable element. */
2955
+ getRootElement() {
2956
+ return this._dragRef.getRootElement();
2957
+ }
2958
+ /** Resets a standalone drag item to its initial position. */
2959
+ reset() {
2960
+ this._dragRef.reset();
2961
+ }
2962
+ /**
2963
+ * Gets the pixel coordinates of the draggable outside of a drop container.
2964
+ */
2965
+ getFreeDragPosition() {
2966
+ return this._dragRef.getFreeDragPosition();
2967
+ }
2968
+ ngAfterViewInit() {
2969
+ // We need to wait for the zone to stabilize, in order for the reference
2970
+ // element to be in the proper place in the DOM. This is mostly relevant
2971
+ // for draggable elements inside portals since they get stamped out in
2972
+ // their original DOM position and then they get transferred to the portal.
2973
+ this._ngZone.onStable.asObservable()
2974
+ .pipe(take(1), takeUntil(this._destroyed))
2975
+ .subscribe(() => {
2976
+ this._updateRootElement();
2977
+ // Listen for any newly-added handles.
2978
+ this._handles.changes.pipe(startWith(this._handles),
2979
+ // Sync the new handles with the DragRef.
2980
+ tap((handles) => {
2981
+ const childHandleElements = handles
2982
+ .filter(handle => handle._parentDrag === this)
2983
+ .map(handle => handle.element);
2984
+ // Usually handles are only allowed to be a descendant of the drag element, but if
2985
+ // the consumer defined a different drag root, we should allow the drag element
2986
+ // itself to be a handle too.
2987
+ if (this._selfHandle && this.rootElementSelector) {
2988
+ childHandleElements.push(this.element);
2989
+ }
2990
+ this._dragRef.withHandles(childHandleElements);
2991
+ }),
2992
+ // Listen if the state of any of the handles changes.
2993
+ switchMap((handles) => {
2994
+ return merge(...handles.map(item => {
2995
+ return item._stateChanges.pipe(startWith(item));
2996
+ }));
2997
+ }), takeUntil(this._destroyed)).subscribe(handleInstance => {
2998
+ // Enabled/disable the handle that changed in the DragRef.
2999
+ const dragRef = this._dragRef;
3000
+ const handle = handleInstance.element.nativeElement;
3001
+ handleInstance.disabled ? dragRef.disableHandle(handle) : dragRef.enableHandle(handle);
3002
+ });
3003
+ if (this.freeDragPosition) {
3004
+ this._dragRef.setFreeDragPosition(this.freeDragPosition);
3005
+ }
3006
+ });
3007
+ }
3008
+ ngOnChanges(changes) {
3009
+ const rootSelectorChange = changes['rootElementSelector'];
3010
+ const positionChange = changes['freeDragPosition'];
3011
+ // We don't have to react to the first change since it's being
3012
+ // handled in `ngAfterViewInit` where it needs to be deferred.
3013
+ if (rootSelectorChange && !rootSelectorChange.firstChange) {
3014
+ this._updateRootElement();
2966
3015
  }
2967
- }
2968
- /** Removes an item from the drop list. */
2969
- removeItem(item) {
2970
- this._unsortedItems.delete(item);
2971
- if (this._dropListRef.isDragging()) {
2972
- this._syncItemsWithRef();
3016
+ // Skip the first change since it's being handled in `ngAfterViewInit`.
3017
+ if (positionChange && !positionChange.firstChange && this.freeDragPosition) {
3018
+ this._dragRef.setFreeDragPosition(this.freeDragPosition);
2973
3019
  }
2974
3020
  }
2975
- /** Gets the registered items in the list, sorted by their position in the DOM. */
2976
- getSortedItems() {
2977
- return Array.from(this._unsortedItems).sort((a, b) => {
2978
- const documentPosition = a._dragRef.getVisibleElement().compareDocumentPosition(b._dragRef.getVisibleElement());
2979
- // `compareDocumentPosition` returns a bitmask so we have to use a bitwise operator.
2980
- // https://developer.mozilla.org/en-US/docs/Web/API/Node/compareDocumentPosition
2981
- // tslint:disable-next-line:no-bitwise
2982
- return documentPosition & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1;
2983
- });
2984
- }
2985
3021
  ngOnDestroy() {
2986
- const index = CdkDropList._dropLists.indexOf(this);
2987
- if (index > -1) {
2988
- CdkDropList._dropLists.splice(index, 1);
2989
- }
2990
- if (this._group) {
2991
- this._group._items.delete(this);
3022
+ if (this.dropContainer) {
3023
+ this.dropContainer.removeItem(this);
2992
3024
  }
2993
- this._unsortedItems.clear();
2994
- this._dropListRef.dispose();
2995
3025
  this._destroyed.next();
2996
3026
  this._destroyed.complete();
3027
+ this._dragRef.dispose();
2997
3028
  }
2998
- /** Syncs the inputs of the CdkDropList with the options of the underlying DropListRef. */
2999
- _setupInputSyncSubscription(ref) {
3000
- if (this._dir) {
3001
- this._dir.change
3002
- .pipe(startWith(this._dir.value), takeUntil(this._destroyed))
3003
- .subscribe(value => ref.withDirection(value));
3029
+ /** Syncs the root element with the `DragRef`. */
3030
+ _updateRootElement() {
3031
+ const element = this.element.nativeElement;
3032
+ const rootElement = this.rootElementSelector ?
3033
+ getClosestMatchingAncestor(element, this.rootElementSelector) : element;
3034
+ if (rootElement && rootElement.nodeType !== this._document.ELEMENT_NODE) {
3035
+ throw Error(`cdkDrag must be attached to an element node. ` +
3036
+ `Currently attached to "${rootElement.nodeName}".`);
3037
+ }
3038
+ this._dragRef.withRootElement(rootElement || element);
3039
+ }
3040
+ /** Gets the boundary element, based on the `boundaryElement` value. */
3041
+ _getBoundaryElement() {
3042
+ const boundary = this.boundaryElement;
3043
+ if (!boundary) {
3044
+ return null;
3045
+ }
3046
+ if (typeof boundary === 'string') {
3047
+ return getClosestMatchingAncestor(this.element.nativeElement, boundary);
3048
+ }
3049
+ const element = coerceElement(boundary);
3050
+ if (isDevMode() && !element.contains(this.element.nativeElement)) {
3051
+ throw Error('Draggable element is not inside of the node passed into cdkDragBoundary.');
3004
3052
  }
3053
+ return element;
3054
+ }
3055
+ /** Syncs the inputs of the CdkDrag with the options of the underlying DragRef. */
3056
+ _syncInputs(ref) {
3005
3057
  ref.beforeStarted.subscribe(() => {
3006
- const siblings = coerceArray(this.connectedTo).map(drop => {
3007
- return typeof drop === 'string' ?
3008
- CdkDropList._dropLists.find(list => list.id === drop) : drop;
3009
- });
3010
- if (this._group) {
3011
- this._group._items.forEach(drop => {
3012
- if (siblings.indexOf(drop) === -1) {
3013
- siblings.push(drop);
3014
- }
3015
- });
3016
- }
3017
- // Note that we resolve the scrollable parents here so that we delay the resolution
3018
- // as long as possible, ensuring that the element is in its final place in the DOM.
3019
- // @breaking-change 11.0.0 Remove null check for _scrollDispatcher once it's required.
3020
- if (!this._scrollableParentsResolved && this._scrollDispatcher) {
3021
- const scrollableParents = this._scrollDispatcher
3022
- .getAncestorScrollContainers(this.element)
3023
- .map(scrollable => scrollable.getElementRef().nativeElement);
3024
- this._dropListRef.withScrollableParents(scrollableParents);
3025
- // Only do this once since it involves traversing the DOM and the parents
3026
- // shouldn't be able to change without the drop list being destroyed.
3027
- this._scrollableParentsResolved = true;
3058
+ if (!ref.isDragging()) {
3059
+ const dir = this._dir;
3060
+ const dragStartDelay = this.dragStartDelay;
3061
+ const placeholder = this._placeholderTemplate ? {
3062
+ template: this._placeholderTemplate.templateRef,
3063
+ context: this._placeholderTemplate.data,
3064
+ viewContainer: this._viewContainerRef
3065
+ } : null;
3066
+ const preview = this._previewTemplate ? {
3067
+ template: this._previewTemplate.templateRef,
3068
+ context: this._previewTemplate.data,
3069
+ matchSize: this._previewTemplate.matchSize,
3070
+ viewContainer: this._viewContainerRef
3071
+ } : null;
3072
+ ref.disabled = this.disabled;
3073
+ ref.lockAxis = this.lockAxis;
3074
+ ref.dragStartDelay = (typeof dragStartDelay === 'object' && dragStartDelay) ?
3075
+ dragStartDelay : coerceNumberProperty(dragStartDelay);
3076
+ ref.constrainPosition = this.constrainPosition;
3077
+ ref.previewClass = this.previewClass;
3078
+ ref
3079
+ .withBoundaryElement(this._getBoundaryElement())
3080
+ .withPlaceholderTemplate(placeholder)
3081
+ .withPreviewTemplate(preview);
3082
+ if (dir) {
3083
+ ref.withDirection(dir.value);
3084
+ }
3028
3085
  }
3029
- ref.disabled = this.disabled;
3030
- ref.lockAxis = this.lockAxis;
3031
- ref.sortingDisabled = coerceBooleanProperty(this.sortingDisabled);
3032
- ref.autoScrollDisabled = coerceBooleanProperty(this.autoScrollDisabled);
3033
- ref
3034
- .connectedTo(siblings.filter(drop => drop && drop !== this).map(list => list._dropListRef))
3035
- .withOrientation(this.orientation);
3036
3086
  });
3037
3087
  }
3038
- /** Handles events from the underlying DropListRef. */
3088
+ /** Handles the events from the underlying `DragRef`. */
3039
3089
  _handleEvents(ref) {
3040
- ref.beforeStarted.subscribe(() => {
3041
- this._syncItemsWithRef();
3090
+ ref.started.subscribe(() => {
3091
+ this.started.emit({ source: this });
3092
+ // Since all of these events run outside of change detection,
3093
+ // we need to ensure that everything is marked correctly.
3094
+ this._changeDetectorRef.markForCheck();
3095
+ });
3096
+ ref.released.subscribe(() => {
3097
+ this.released.emit({ source: this });
3098
+ });
3099
+ ref.ended.subscribe(event => {
3100
+ this.ended.emit({ source: this, distance: event.distance });
3101
+ // Since all of these events run outside of change detection,
3102
+ // we need to ensure that everything is marked correctly.
3042
3103
  this._changeDetectorRef.markForCheck();
3043
3104
  });
3044
3105
  ref.entered.subscribe(event => {
3045
3106
  this.entered.emit({
3046
- container: this,
3047
- item: event.item.data,
3107
+ container: event.container.data,
3108
+ item: this,
3048
3109
  currentIndex: event.currentIndex
3049
3110
  });
3050
3111
  });
3051
3112
  ref.exited.subscribe(event => {
3052
3113
  this.exited.emit({
3053
- container: this,
3054
- item: event.item.data
3055
- });
3056
- this._changeDetectorRef.markForCheck();
3057
- });
3058
- ref.sorted.subscribe(event => {
3059
- this.sorted.emit({
3060
- previousIndex: event.previousIndex,
3061
- currentIndex: event.currentIndex,
3062
- container: this,
3063
- item: event.item.data
3114
+ container: event.container.data,
3115
+ item: this
3064
3116
  });
3065
3117
  });
3066
3118
  ref.dropped.subscribe(event => {
@@ -3069,75 +3121,92 @@ class CdkDropList {
3069
3121
  currentIndex: event.currentIndex,
3070
3122
  previousContainer: event.previousContainer.data,
3071
3123
  container: event.container.data,
3072
- item: event.item.data,
3073
3124
  isPointerOverContainer: event.isPointerOverContainer,
3125
+ item: this,
3074
3126
  distance: event.distance
3075
3127
  });
3076
- // Mark for check since all of these events run outside of change
3077
- // detection and we're not guaranteed for something else to have triggered it.
3078
- this._changeDetectorRef.markForCheck();
3079
3128
  });
3080
3129
  }
3081
3130
  /** Assigns the default input values based on a provided config object. */
3082
3131
  _assignDefaults(config) {
3083
- const { lockAxis, draggingDisabled, sortingDisabled, listAutoScrollDisabled, listOrientation } = config;
3132
+ const { lockAxis, dragStartDelay, constrainPosition, previewClass, boundaryElement, draggingDisabled, rootElementSelector } = config;
3084
3133
  this.disabled = draggingDisabled == null ? false : draggingDisabled;
3085
- this.sortingDisabled = sortingDisabled == null ? false : sortingDisabled;
3086
- this.autoScrollDisabled = listAutoScrollDisabled == null ? false : listAutoScrollDisabled;
3087
- this.orientation = listOrientation || 'vertical';
3134
+ this.dragStartDelay = dragStartDelay || 0;
3088
3135
  if (lockAxis) {
3089
3136
  this.lockAxis = lockAxis;
3090
3137
  }
3091
- }
3092
- /** Syncs up the registered drag items with underlying drop list ref. */
3093
- _syncItemsWithRef() {
3094
- this._dropListRef.withItems(this.getSortedItems().map(item => item._dragRef));
3138
+ if (constrainPosition) {
3139
+ this.constrainPosition = constrainPosition;
3140
+ }
3141
+ if (previewClass) {
3142
+ this.previewClass = previewClass;
3143
+ }
3144
+ if (boundaryElement) {
3145
+ this.boundaryElement = boundaryElement;
3146
+ }
3147
+ if (rootElementSelector) {
3148
+ this.rootElementSelector = rootElementSelector;
3149
+ }
3095
3150
  }
3096
3151
  }
3097
- /** Keeps track of the drop lists that are currently on the page. */
3098
- CdkDropList._dropLists = [];
3099
- CdkDropList.decorators = [
3152
+ CdkDrag.decorators = [
3100
3153
  { type: Directive, args: [{
3101
- selector: '[cdkDropList], cdk-drop-list',
3102
- exportAs: 'cdkDropList',
3103
- providers: [
3104
- // Prevent child drop lists from picking up the same group as their parent.
3105
- { provide: CdkDropListGroup, useValue: ɵ0 },
3106
- { provide: CDK_DROP_LIST, useExisting: CdkDropList },
3107
- ],
3154
+ selector: '[cdkDrag]',
3155
+ exportAs: 'cdkDrag',
3108
3156
  host: {
3109
- 'class': 'cdk-drop-list',
3110
- '[id]': 'id',
3111
- '[class.cdk-drop-list-disabled]': 'disabled',
3112
- '[class.cdk-drop-list-dragging]': '_dropListRef.isDragging()',
3113
- '[class.cdk-drop-list-receiving]': '_dropListRef.isReceiving()',
3114
- }
3157
+ 'class': 'cdk-drag',
3158
+ '[class.cdk-drag-disabled]': 'disabled',
3159
+ '[class.cdk-drag-dragging]': '_dragRef.isDragging()',
3160
+ },
3161
+ providers: [{ provide: CDK_DRAG_PARENT, useExisting: CdkDrag }]
3115
3162
  },] }
3116
3163
  ];
3117
- CdkDropList.ctorParameters = () => [
3164
+ CdkDrag.ctorParameters = () => [
3118
3165
  { type: ElementRef },
3166
+ { type: undefined, decorators: [{ type: Inject, args: [CDK_DROP_LIST,] }, { type: Optional }, { type: SkipSelf }] },
3167
+ { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] }] },
3168
+ { type: NgZone },
3169
+ { type: ViewContainerRef },
3170
+ { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [CDK_DRAG_CONFIG,] }] },
3171
+ { type: Directionality, decorators: [{ type: Optional }] },
3119
3172
  { type: DragDrop },
3120
3173
  { type: ChangeDetectorRef },
3121
- { type: Directionality, decorators: [{ type: Optional }] },
3122
- { type: CdkDropListGroup, decorators: [{ type: Optional }, { type: SkipSelf }] },
3123
- { type: ScrollDispatcher },
3124
- { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [CDK_DRAG_CONFIG,] }] }
3174
+ { type: CdkDragHandle, decorators: [{ type: Optional }, { type: Self }, { type: Inject, args: [CDK_DRAG_HANDLE,] }] }
3125
3175
  ];
3126
- CdkDropList.propDecorators = {
3127
- connectedTo: [{ type: Input, args: ['cdkDropListConnectedTo',] }],
3128
- data: [{ type: Input, args: ['cdkDropListData',] }],
3129
- orientation: [{ type: Input, args: ['cdkDropListOrientation',] }],
3130
- id: [{ type: Input }],
3131
- lockAxis: [{ type: Input, args: ['cdkDropListLockAxis',] }],
3132
- disabled: [{ type: Input, args: ['cdkDropListDisabled',] }],
3133
- sortingDisabled: [{ type: Input, args: ['cdkDropListSortingDisabled',] }],
3134
- enterPredicate: [{ type: Input, args: ['cdkDropListEnterPredicate',] }],
3135
- autoScrollDisabled: [{ type: Input, args: ['cdkDropListAutoScrollDisabled',] }],
3136
- dropped: [{ type: Output, args: ['cdkDropListDropped',] }],
3137
- entered: [{ type: Output, args: ['cdkDropListEntered',] }],
3138
- exited: [{ type: Output, args: ['cdkDropListExited',] }],
3139
- sorted: [{ type: Output, args: ['cdkDropListSorted',] }]
3176
+ CdkDrag.propDecorators = {
3177
+ _handles: [{ type: ContentChildren, args: [CDK_DRAG_HANDLE, { descendants: true },] }],
3178
+ _previewTemplate: [{ type: ContentChild, args: [CDK_DRAG_PREVIEW,] }],
3179
+ _placeholderTemplate: [{ type: ContentChild, args: [CDK_DRAG_PLACEHOLDER,] }],
3180
+ data: [{ type: Input, args: ['cdkDragData',] }],
3181
+ lockAxis: [{ type: Input, args: ['cdkDragLockAxis',] }],
3182
+ rootElementSelector: [{ type: Input, args: ['cdkDragRootElement',] }],
3183
+ boundaryElement: [{ type: Input, args: ['cdkDragBoundary',] }],
3184
+ dragStartDelay: [{ type: Input, args: ['cdkDragStartDelay',] }],
3185
+ freeDragPosition: [{ type: Input, args: ['cdkDragFreeDragPosition',] }],
3186
+ disabled: [{ type: Input, args: ['cdkDragDisabled',] }],
3187
+ constrainPosition: [{ type: Input, args: ['cdkDragConstrainPosition',] }],
3188
+ previewClass: [{ type: Input, args: ['cdkDragPreviewClass',] }],
3189
+ started: [{ type: Output, args: ['cdkDragStarted',] }],
3190
+ released: [{ type: Output, args: ['cdkDragReleased',] }],
3191
+ ended: [{ type: Output, args: ['cdkDragEnded',] }],
3192
+ entered: [{ type: Output, args: ['cdkDragEntered',] }],
3193
+ exited: [{ type: Output, args: ['cdkDragExited',] }],
3194
+ dropped: [{ type: Output, args: ['cdkDragDropped',] }],
3195
+ moved: [{ type: Output, args: ['cdkDragMoved',] }]
3140
3196
  };
3197
+ /** Gets the closest ancestor of an element that matches a selector. */
3198
+ function getClosestMatchingAncestor(element, selector) {
3199
+ let currentElement = element.parentElement;
3200
+ while (currentElement) {
3201
+ // IE doesn't support `matches` so we have to fall back to `msMatchesSelector`.
3202
+ if (currentElement.matches ? currentElement.matches(selector) :
3203
+ currentElement.msMatchesSelector(selector)) {
3204
+ return currentElement;
3205
+ }
3206
+ currentElement = currentElement.parentElement;
3207
+ }
3208
+ return null;
3209
+ }
3141
3210
 
3142
3211
  /**
3143
3212
  * @license
@@ -3185,5 +3254,5 @@ DragDropModule.decorators = [
3185
3254
  * Generated bundle index. Do not edit.
3186
3255
  */
3187
3256
 
3188
- export { CDK_DRAG_CONFIG, CDK_DROP_LIST, CdkDrag, CdkDragHandle, CdkDragPlaceholder, CdkDragPreview, CdkDropList, CdkDropListGroup, DragDrop, DragDropModule, DragDropRegistry, DragRef, DropListRef, copyArrayItem, moveItemInArray, transferArrayItem, CDK_DRAG_PARENT as ɵangular_material_src_cdk_drag_drop_drag_drop_b };
3257
+ export { CDK_DRAG_CONFIG, CDK_DRAG_HANDLE, CDK_DRAG_PLACEHOLDER, CDK_DRAG_PREVIEW, CDK_DROP_LIST_GROUP, CdkDrag, CdkDragHandle, CdkDragPlaceholder, CdkDragPreview, CdkDropList, CdkDropListGroup, DragDrop, DragDropModule, DragDropRegistry, DragRef, DropListRef, copyArrayItem, moveItemInArray, transferArrayItem, CDK_DROP_LIST as ɵangular_material_src_cdk_drag_drop_drag_drop_b, CDK_DRAG_PARENT as ɵangular_material_src_cdk_drag_drop_drag_drop_c };
3189
3258
  //# sourceMappingURL=drag-drop.js.map