@angular/cdk 7.1.1 → 7.2.0

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 (122) hide show
  1. package/bundles/cdk-a11y.umd.js +5 -1
  2. package/bundles/cdk-a11y.umd.js.map +1 -1
  3. package/bundles/cdk-a11y.umd.min.js +1 -1
  4. package/bundles/cdk-a11y.umd.min.js.map +1 -1
  5. package/bundles/cdk-drag-drop.umd.js +2030 -1049
  6. package/bundles/cdk-drag-drop.umd.js.map +1 -1
  7. package/bundles/cdk-drag-drop.umd.min.js +2 -1
  8. package/bundles/cdk-drag-drop.umd.min.js.map +1 -1
  9. package/bundles/cdk-stepper.umd.js +11 -3
  10. package/bundles/cdk-stepper.umd.js.map +1 -1
  11. package/bundles/cdk-stepper.umd.min.js +1 -1
  12. package/bundles/cdk-stepper.umd.min.js.map +1 -1
  13. package/bundles/cdk-text-field.umd.js +41 -16
  14. package/bundles/cdk-text-field.umd.js.map +1 -1
  15. package/bundles/cdk-text-field.umd.min.js +1 -1
  16. package/bundles/cdk-text-field.umd.min.js.map +1 -1
  17. package/bundles/cdk-tree.umd.js +1 -1
  18. package/bundles/cdk-tree.umd.js.map +1 -1
  19. package/bundles/cdk-tree.umd.min.js +1 -1
  20. package/bundles/cdk-tree.umd.min.js.map +1 -1
  21. package/bundles/cdk.umd.js +1 -1
  22. package/bundles/cdk.umd.js.map +1 -1
  23. package/bundles/cdk.umd.min.js +1 -1
  24. package/bundles/cdk.umd.min.js.map +1 -1
  25. package/drag-drop/typings/{drag-handle.d.ts → directives/drag-handle.d.ts} +0 -0
  26. package/drag-drop/typings/{drag-placeholder.d.ts → directives/drag-placeholder.d.ts} +0 -0
  27. package/drag-drop/typings/{drag-preview.d.ts → directives/drag-preview.d.ts} +0 -0
  28. package/drag-drop/typings/directives/drag.d.ts +108 -0
  29. package/{typings/esm5/drag-drop → drag-drop/typings/directives}/drop-list-group.d.ts +3 -0
  30. package/drag-drop/typings/directives/drop-list.d.ts +135 -0
  31. package/drag-drop/typings/drag-drop-registry.d.ts +8 -3
  32. package/drag-drop/typings/drag-events.d.ts +14 -7
  33. package/{typings/esm5/drag-drop/drag.d.ts → drag-drop/typings/drag-ref.d.ts} +143 -82
  34. package/drag-drop/typings/drop-list-container.d.ts +19 -3
  35. package/drag-drop/typings/{drop-list.d.ts → drop-list-ref.d.ts} +132 -84
  36. package/drag-drop/typings/index.d.ts +1 -0
  37. package/drag-drop/typings/index.metadata.json +1 -1
  38. package/drag-drop/typings/public-api.d.ts +13 -6
  39. package/esm2015/a11y.js +5 -1
  40. package/esm2015/a11y.js.map +1 -1
  41. package/esm2015/cdk.js +1 -1
  42. package/esm2015/cdk.js.map +1 -1
  43. package/esm2015/drag-drop.js +1546 -811
  44. package/esm2015/drag-drop.js.map +1 -1
  45. package/esm2015/stepper.js +11 -4
  46. package/esm2015/stepper.js.map +1 -1
  47. package/esm2015/text-field.js +28 -16
  48. package/esm2015/text-field.js.map +1 -1
  49. package/esm2015/tree.js +2 -2
  50. package/esm2015/tree.js.map +1 -1
  51. package/esm5/a11y.es5.js +5 -1
  52. package/esm5/a11y.es5.js.map +1 -1
  53. package/esm5/cdk.es5.js +1 -1
  54. package/esm5/cdk.es5.js.map +1 -1
  55. package/esm5/drag-drop.es5.js +2025 -1045
  56. package/esm5/drag-drop.es5.js.map +1 -1
  57. package/esm5/stepper.es5.js +11 -4
  58. package/esm5/stepper.es5.js.map +1 -1
  59. package/esm5/text-field.es5.js +41 -16
  60. package/esm5/text-field.es5.js.map +1 -1
  61. package/esm5/tree.es5.js +2 -2
  62. package/esm5/tree.es5.js.map +1 -1
  63. package/package.json +4 -4
  64. package/schematics/ng-generate/drag-drop/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.ts +2 -2
  65. package/schematics/ng-update/upgrade-data.js +2 -1
  66. package/schematics/ng-update/upgrade-data.js.map +1 -1
  67. package/schematics/ng-update/upgrade-rules/index.js +3 -2
  68. package/schematics/ng-update/upgrade-rules/index.js.map +1 -1
  69. package/schematics/utils/ast/ng-module-imports.d.ts +1 -1
  70. package/schematics/utils/ast/ng-module-imports.js +25 -13
  71. package/schematics/utils/ast/ng-module-imports.js.map +1 -1
  72. package/schematics/utils/get-project.js +2 -1
  73. package/schematics/utils/get-project.js.map +1 -1
  74. package/schematics/utils/parse5-element.js +3 -2
  75. package/schematics/utils/parse5-element.js.map +1 -1
  76. package/schematics/utils/project-targets.js +2 -1
  77. package/schematics/utils/project-targets.js.map +1 -1
  78. package/schematics/utils/version-agnostic-typescript.js +3 -2
  79. package/schematics/utils/version-agnostic-typescript.js.map +1 -1
  80. package/stepper/typings/index.metadata.json +1 -1
  81. package/stepper/typings/stepper.d.ts +6 -0
  82. package/text-field/typings/autosize.d.ts +6 -0
  83. package/text-field/typings/index.metadata.json +1 -1
  84. package/typings/drag-drop/{drag-handle.d.ts → directives/drag-handle.d.ts} +0 -0
  85. package/typings/drag-drop/{drag-placeholder.d.ts → directives/drag-placeholder.d.ts} +0 -0
  86. package/typings/drag-drop/{drag-preview.d.ts → directives/drag-preview.d.ts} +0 -0
  87. package/typings/drag-drop/directives/drag.d.ts +108 -0
  88. package/typings/drag-drop/{drop-list-group.d.ts → directives/drop-list-group.d.ts} +3 -0
  89. package/typings/drag-drop/directives/drop-list.d.ts +135 -0
  90. package/typings/drag-drop/drag-drop-registry.d.ts +8 -3
  91. package/typings/drag-drop/drag-events.d.ts +14 -7
  92. package/typings/drag-drop/{drag.d.ts → drag-ref.d.ts} +143 -82
  93. package/typings/drag-drop/drop-list-container.d.ts +19 -3
  94. package/typings/{esm5/drag-drop/drop-list.d.ts → drag-drop/drop-list-ref.d.ts} +132 -84
  95. package/typings/drag-drop/index.d.ts +1 -0
  96. package/typings/drag-drop/index.metadata.json +1 -1
  97. package/typings/drag-drop/public-api.d.ts +13 -6
  98. package/typings/esm5/drag-drop/{drag-handle.d.ts → directives/drag-handle.d.ts} +0 -0
  99. package/typings/esm5/drag-drop/{drag-placeholder.d.ts → directives/drag-placeholder.d.ts} +0 -0
  100. package/typings/esm5/drag-drop/{drag-preview.d.ts → directives/drag-preview.d.ts} +0 -0
  101. package/typings/esm5/drag-drop/directives/drag.d.ts +108 -0
  102. package/{drag-drop/typings → typings/esm5/drag-drop/directives}/drop-list-group.d.ts +3 -0
  103. package/typings/esm5/drag-drop/directives/drop-list.d.ts +135 -0
  104. package/typings/esm5/drag-drop/drag-drop-registry.d.ts +8 -3
  105. package/typings/esm5/drag-drop/drag-events.d.ts +14 -7
  106. package/{drag-drop/typings/drag.d.ts → typings/esm5/drag-drop/drag-ref.d.ts} +143 -82
  107. package/typings/esm5/drag-drop/drop-list-container.d.ts +19 -3
  108. package/typings/{drag-drop/drop-list.d.ts → esm5/drag-drop/drop-list-ref.d.ts} +132 -84
  109. package/typings/esm5/drag-drop/index.d.ts +1 -0
  110. package/typings/esm5/drag-drop/index.metadata.json +1 -1
  111. package/typings/esm5/drag-drop/public-api.d.ts +13 -6
  112. package/typings/esm5/index.metadata.json +1 -1
  113. package/typings/esm5/stepper/index.metadata.json +1 -1
  114. package/typings/esm5/stepper/stepper.d.ts +6 -0
  115. package/typings/esm5/text-field/autosize.d.ts +6 -0
  116. package/typings/esm5/text-field/index.metadata.json +1 -1
  117. package/typings/index.metadata.json +1 -1
  118. package/typings/schematics/utils/ast/ng-module-imports.d.ts +1 -1
  119. package/typings/stepper/index.metadata.json +1 -1
  120. package/typings/stepper/stepper.d.ts +6 -0
  121. package/typings/text-field/autosize.d.ts +6 -0
  122. package/typings/text-field/index.metadata.json +1 -1
@@ -5,14 +5,114 @@
5
5
  * Use of this source code is governed by an MIT-style license that can be
6
6
  * found in the LICENSE file at https://angular.io/license
7
7
  */
8
- import { Injectable, NgZone, Inject, ContentChildren, ElementRef, EventEmitter, forwardRef, Input, Output, Optional, Directive, ChangeDetectorRef, SkipSelf, ContentChild, InjectionToken, ViewContainerRef, TemplateRef, NgModule, defineInjectable, inject } from '@angular/core';
8
+ import { InjectionToken, Injectable, NgZone, Inject, NgModule, ContentChildren, ElementRef, EventEmitter, forwardRef, Input, Output, Optional, Directive, ChangeDetectorRef, SkipSelf, ContentChild, ViewContainerRef, TemplateRef, defineInjectable, inject } from '@angular/core';
9
9
  import { DOCUMENT } from '@angular/common';
10
10
  import { normalizePassiveListenerOptions } from '@angular/cdk/platform';
11
- import { Subject, Observable, Subscription } from 'rxjs';
11
+ import { Subject, Subscription, Observable } from 'rxjs';
12
12
  import { coerceBooleanProperty, coerceArray } from '@angular/cdk/coercion';
13
13
  import { Directionality } from '@angular/cdk/bidi';
14
14
  import { ViewportRuler } from '@angular/cdk/scrolling';
15
- import { startWith, take } from 'rxjs/operators';
15
+ import { startWith, take, map } from 'rxjs/operators';
16
+
17
+ /**
18
+ * @fileoverview added by tsickle
19
+ * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
20
+ */
21
+ /**
22
+ * Injection token that is used to provide a CdkDropList instance to CdkDrag.
23
+ * Used for avoiding circular imports.
24
+ * @type {?}
25
+ */
26
+ const CDK_DROP_LIST = new InjectionToken('CDK_DROP_LIST');
27
+ /**
28
+ * Injection token that is used to provide a CdkDropList instance to CdkDrag.
29
+ * Used for avoiding circular imports.
30
+ * @deprecated Use `CDK_DROP_LIST` instead.
31
+ * \@breaking-change 8.0.0
32
+ * @type {?}
33
+ */
34
+ const CDK_DROP_LIST_CONTAINER = CDK_DROP_LIST;
35
+
36
+ /**
37
+ * @fileoverview added by tsickle
38
+ * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
39
+ */
40
+
41
+ /**
42
+ * @fileoverview added by tsickle
43
+ * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
44
+ */
45
+
46
+ /**
47
+ * Moves an item one index in an array to another.
48
+ * @template T
49
+ * @param {?} array Array in which to move the item.
50
+ * @param {?} fromIndex Starting index of the item.
51
+ * @param {?} toIndex Index to which the item should be moved.
52
+ * @return {?}
53
+ */
54
+ function moveItemInArray(array, fromIndex, toIndex) {
55
+ /** @type {?} */
56
+ const from = clamp(fromIndex, array.length - 1);
57
+ /** @type {?} */
58
+ const to = clamp(toIndex, array.length - 1);
59
+ if (from === to) {
60
+ return;
61
+ }
62
+ /** @type {?} */
63
+ const target = array[from];
64
+ /** @type {?} */
65
+ const delta = to < from ? -1 : 1;
66
+ for (let i = from; i !== to; i += delta) {
67
+ array[i] = array[i + delta];
68
+ }
69
+ array[to] = target;
70
+ }
71
+ /**
72
+ * Moves an item from one array to another.
73
+ * @template T
74
+ * @param {?} currentArray Array from which to transfer the item.
75
+ * @param {?} targetArray Array into which to put the item.
76
+ * @param {?} currentIndex Index of the item in its current array.
77
+ * @param {?} targetIndex Index at which to insert the item.
78
+ * @return {?}
79
+ */
80
+ function transferArrayItem(currentArray, targetArray, currentIndex, targetIndex) {
81
+ /** @type {?} */
82
+ const from = clamp(currentIndex, currentArray.length - 1);
83
+ /** @type {?} */
84
+ const to = clamp(targetIndex, targetArray.length);
85
+ if (currentArray.length) {
86
+ targetArray.splice(to, 0, currentArray.splice(from, 1)[0]);
87
+ }
88
+ }
89
+ /**
90
+ * Copies an item from one array to another, leaving it in its
91
+ * original position in current array.
92
+ * @template T
93
+ * @param {?} currentArray Array from which to copy the item.
94
+ * @param {?} targetArray Array into which is copy the item.
95
+ * @param {?} currentIndex Index of the item in its current array.
96
+ * @param {?} targetIndex Index at which to insert the item.
97
+ *
98
+ * @return {?}
99
+ */
100
+ function copyArrayItem(currentArray, targetArray, currentIndex, targetIndex) {
101
+ /** @type {?} */
102
+ const to = clamp(targetIndex, targetArray.length);
103
+ if (currentArray.length) {
104
+ targetArray.splice(to, 0, currentArray[currentIndex]);
105
+ }
106
+ }
107
+ /**
108
+ * Clamps a number between zero and a maximum.
109
+ * @param {?} value
110
+ * @param {?} max
111
+ * @return {?}
112
+ */
113
+ function clamp(value, max) {
114
+ return Math.max(0, Math.min(max, value));
115
+ }
16
116
 
17
117
  /**
18
118
  * @fileoverview added by tsickle
@@ -69,9 +169,10 @@ class DragDropRegistry {
69
169
  */
70
170
  this.pointerUp = new Subject();
71
171
  /**
72
- * Listener used to prevent `touchmove` and `wheel` events while the element is being dragged.
172
+ * Event listener that will prevent the default browser action while the user is dragging.
173
+ * @param event Event whose default action should be prevented.
73
174
  */
74
- this._preventScrollListener = (event) => {
175
+ this._preventDefaultWhileDragging = (event) => {
75
176
  if (this._activeDragInstances.size) {
76
177
  event.preventDefault();
77
178
  }
@@ -105,7 +206,7 @@ class DragDropRegistry {
105
206
  this._ngZone.runOutsideAngular(() => {
106
207
  // The event handler has to be explicitly active,
107
208
  // because newer browsers make it passive by default.
108
- this._document.addEventListener('touchmove', this._preventScrollListener, activeCapturingEventOptions);
209
+ this._document.addEventListener('touchmove', this._preventDefaultWhileDragging, activeCapturingEventOptions);
109
210
  });
110
211
  }
111
212
  }
@@ -126,7 +227,7 @@ class DragDropRegistry {
126
227
  this._dragInstances.delete(drag);
127
228
  this.stopDragging(drag);
128
229
  if (this._dragInstances.size === 0) {
129
- this._document.removeEventListener('touchmove', this._preventScrollListener, activeCapturingEventOptions);
230
+ this._document.removeEventListener('touchmove', this._preventDefaultWhileDragging, activeCapturingEventOptions);
130
231
  }
131
232
  }
132
233
  /**
@@ -149,18 +250,26 @@ class DragDropRegistry {
149
250
  // use `preventDefault` to prevent the page from scrolling while the user is dragging.
150
251
  this._globalListeners
151
252
  .set(moveEvent, {
152
- handler: e => this.pointerMove.next(e),
253
+ handler: (e) => this.pointerMove.next((/** @type {?} */ (e))),
153
254
  options: activeCapturingEventOptions
154
255
  })
155
256
  .set(upEvent, {
156
- handler: e => this.pointerUp.next(e),
257
+ handler: (e) => this.pointerUp.next((/** @type {?} */ (e))),
157
258
  options: true
259
+ })
260
+ // Preventing the default action on `mousemove` isn't enough to disable text selection
261
+ // on Safari so we need to prevent the selection event as well. Alternatively this can
262
+ // be done by setting `user-select: none` on the `body`, however it has causes a style
263
+ // recalculation which can be expensive on pages with a lot of elements.
264
+ .set('selectstart', {
265
+ handler: this._preventDefaultWhileDragging,
266
+ options: activeCapturingEventOptions
158
267
  });
159
268
  // TODO(crisbeto): prevent mouse wheel scrolling while
160
269
  // dragging until we've set up proper scroll handling.
161
270
  if (!isTouchEvent) {
162
271
  this._globalListeners.set('wheel', {
163
- handler: this._preventScrollListener,
272
+ handler: this._preventDefaultWhileDragging,
164
273
  options: activeCapturingEventOptions
165
274
  });
166
275
  }
@@ -192,6 +301,8 @@ class DragDropRegistry {
192
301
  }
193
302
  /**
194
303
  * Gets a drop container by its id.
304
+ * @deprecated No longer being used. To be removed.
305
+ * \@breaking-change 8.0.0
195
306
  * @param {?} id
196
307
  * @return {?}
197
308
  */
@@ -391,17 +502,6 @@ CdkDragPreview.propDecorators = {
391
502
  data: [{ type: Input }]
392
503
  };
393
504
 
394
- /**
395
- * @fileoverview added by tsickle
396
- * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
397
- */
398
- /**
399
- * Injection token that is used to provide a CdkDropList instance to CdkDrag.
400
- * Used for avoiding circular imports.
401
- * @type {?}
402
- */
403
- const CDK_DROP_LIST_CONTAINER = new InjectionToken('CDK_DROP_LIST_CONTAINER');
404
-
405
505
  /**
406
506
  * @fileoverview added by tsickle
407
507
  * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
@@ -461,21 +561,6 @@ function parseCssPropertyValue(computedStyle, name) {
461
561
  * @fileoverview added by tsickle
462
562
  * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
463
563
  */
464
- /**
465
- * Injection token that can be used to configure the behavior of `CdkDrag`.
466
- * @type {?}
467
- */
468
- const CDK_DRAG_CONFIG = new InjectionToken('CDK_DRAG_CONFIG', {
469
- providedIn: 'root',
470
- factory: CDK_DRAG_CONFIG_FACTORY
471
- });
472
- /**
473
- * \@docs-private
474
- * @return {?}
475
- */
476
- function CDK_DRAG_CONFIG_FACTORY() {
477
- return { dragStartThreshold: 5, pointerDirectionChangeThreshold: 5 };
478
- }
479
564
  /**
480
565
  * Options that can be used to bind a passive event listener.
481
566
  * @type {?}
@@ -495,29 +580,30 @@ const activeEventListenerOptions = normalizePassiveListenerOptions({ passive: fa
495
580
  */
496
581
  const MOUSE_EVENT_IGNORE_TIME = 800;
497
582
  /**
498
- * Element that can be moved inside a CdkDropList container.
583
+ * Reference to a draggable item. Used to manipulate or dispose of the item.
584
+ * \@docs-private
499
585
  * @template T
500
586
  */
501
- class CdkDrag {
587
+ class DragRef {
502
588
  /**
503
589
  * @param {?} element
504
- * @param {?} dropContainer
505
- * @param {?} document
590
+ * @param {?} _document
506
591
  * @param {?} _ngZone
507
592
  * @param {?} _viewContainerRef
508
593
  * @param {?} _viewportRuler
509
594
  * @param {?} _dragDropRegistry
510
595
  * @param {?} _config
511
- * @param {?} _dir
596
+ * @param {?=} dropContainer
597
+ * @param {?=} _dir
512
598
  */
513
- constructor(element, dropContainer, document, _ngZone, _viewContainerRef, _viewportRuler, _dragDropRegistry, _config, _dir) {
514
- this.element = element;
515
- this.dropContainer = dropContainer;
599
+ constructor(element, _document, _ngZone, _viewContainerRef, _viewportRuler, _dragDropRegistry, _config, dropContainer, _dir) {
600
+ this._document = _document;
516
601
  this._ngZone = _ngZone;
517
602
  this._viewContainerRef = _viewContainerRef;
518
603
  this._viewportRuler = _viewportRuler;
519
604
  this._dragDropRegistry = _dragDropRegistry;
520
605
  this._config = _config;
606
+ this.dropContainer = dropContainer;
521
607
  this._dir = _dir;
522
608
  /**
523
609
  * CSS `transform` applied to the element when it isn't being dragged. We need a
@@ -548,30 +634,46 @@ class CdkDrag {
548
634
  */
549
635
  this._pointerUpSubscription = Subscription.EMPTY;
550
636
  /**
551
- * Subscription to the stream that initializes the root element.
637
+ * Cached reference to the boundary element.
552
638
  */
553
- this._rootElementInitSubscription = Subscription.EMPTY;
639
+ this._boundaryElement = null;
640
+ /**
641
+ * Elements that can be used to drag the draggable item.
642
+ */
643
+ this._handles = [];
644
+ /**
645
+ * Whether the native interactions on the element are enabled.
646
+ */
647
+ this._nativeInteractionsEnabled = true;
554
648
  this._disabled = false;
649
+ /**
650
+ * Emits as the drag sequence is being prepared.
651
+ */
652
+ this.beforeStarted = new Subject();
555
653
  /**
556
654
  * Emits when the user starts dragging the item.
557
655
  */
558
- this.started = new EventEmitter();
656
+ this.started = new Subject();
657
+ /**
658
+ * Emits when the user has released a drag item, before any animations have started.
659
+ */
660
+ this.released = new Subject();
559
661
  /**
560
662
  * Emits when the user stops dragging an item in the container.
561
663
  */
562
- this.ended = new EventEmitter();
664
+ this.ended = new Subject();
563
665
  /**
564
666
  * Emits when the user has moved the item into a new container.
565
667
  */
566
- this.entered = new EventEmitter();
668
+ this.entered = new Subject();
567
669
  /**
568
670
  * Emits when the user removes the item its container by dragging it into another container.
569
671
  */
570
- this.exited = new EventEmitter();
672
+ this.exited = new Subject();
571
673
  /**
572
674
  * Emits when the user drops the item inside a container.
573
675
  */
574
- this.dropped = new EventEmitter();
676
+ this.dropped = new Subject();
575
677
  /**
576
678
  * Emits as the user is dragging the item. Use with caution,
577
679
  * because this event will fire for every pixel that the user has dragged.
@@ -589,12 +691,11 @@ class CdkDrag {
589
691
  * Handler for the `mousedown`/`touchstart` events.
590
692
  */
591
693
  this._pointerDown = (event) => {
592
- /** @type {?} */
593
- const handles = this.getChildHandles();
694
+ this.beforeStarted.next();
594
695
  // Delegate the event based on whether it started from a handle or the element itself.
595
- if (handles.length) {
696
+ if (this._handles.length) {
596
697
  /** @type {?} */
597
- const targetHandle = handles.find(handle => {
698
+ const targetHandle = this._handles.find(handle => {
598
699
  /** @type {?} */
599
700
  const element = handle.element.nativeElement;
600
701
  /** @type {?} */
@@ -613,9 +714,9 @@ class CdkDrag {
613
714
  * Handler that is invoked when the user moves their pointer after they've initiated a drag.
614
715
  */
615
716
  this._pointerMove = (event) => {
616
- /** @type {?} */
617
- const pointerPosition = this._getConstrainedPointerPosition(event);
618
717
  if (!this._hasStartedDragging) {
718
+ /** @type {?} */
719
+ const pointerPosition = this._getPointerPositionOnPage(event);
619
720
  /** @type {?} */
620
721
  const distanceX = Math.abs(pointerPosition.x - this._pickupPositionOnPage.x);
621
722
  /** @type {?} */
@@ -630,19 +731,29 @@ class CdkDrag {
630
731
  }
631
732
  return;
632
733
  }
734
+ // We only need the preview dimensions if we have a boundary element.
735
+ if (this._boundaryElement) {
736
+ // Cache the preview element rect if we haven't cached it already or if
737
+ // we cached it too early before the element dimensions were computed.
738
+ if (!this._previewRect || (!this._previewRect.width && !this._previewRect.height)) {
739
+ this._previewRect = (this._preview || this._rootElement).getBoundingClientRect();
740
+ }
741
+ }
742
+ /** @type {?} */
743
+ const constrainedPointerPosition = this._getConstrainedPointerPosition(event);
633
744
  this._hasMoved = true;
634
745
  event.preventDefault();
635
- this._updatePointerDirectionDelta(pointerPosition);
746
+ this._updatePointerDirectionDelta(constrainedPointerPosition);
636
747
  if (this.dropContainer) {
637
- this._updateActiveDropContainer(pointerPosition);
748
+ this._updateActiveDropContainer(constrainedPointerPosition);
638
749
  }
639
750
  else {
640
751
  /** @type {?} */
641
752
  const activeTransform = this._activeTransform;
642
753
  activeTransform.x =
643
- pointerPosition.x - this._pickupPositionOnPage.x + this._passiveTransform.x;
754
+ constrainedPointerPosition.x - this._pickupPositionOnPage.x + this._passiveTransform.x;
644
755
  activeTransform.y =
645
- pointerPosition.y - this._pickupPositionOnPage.y + this._passiveTransform.y;
756
+ constrainedPointerPosition.y - this._pickupPositionOnPage.y + this._passiveTransform.y;
646
757
  /** @type {?} */
647
758
  const transform = getTransform(activeTransform.x, activeTransform.y);
648
759
  // Preserve the previous `transform` value, if there was one.
@@ -662,7 +773,7 @@ class CdkDrag {
662
773
  this._ngZone.run(() => {
663
774
  this._moveEvents.next({
664
775
  source: this,
665
- pointerPosition,
776
+ pointerPosition: constrainedPointerPosition,
666
777
  event,
667
778
  delta: this._pointerDirectionDelta
668
779
  });
@@ -672,31 +783,39 @@ class CdkDrag {
672
783
  /**
673
784
  * Handler that is invoked when the user lifts their pointer up, after initiating a drag.
674
785
  */
675
- this._pointerUp = () => {
676
- if (!this._isDragging()) {
786
+ this._pointerUp = (event) => {
787
+ // Note that here we use `isDragging` from the service, rather than from `this`.
788
+ // The difference is that the one from the service reflects whether a dragging sequence
789
+ // has been initiated, whereas the one on `this` includes whether the user has passed
790
+ // the minimum dragging threshold.
791
+ if (!this._dragDropRegistry.isDragging(this)) {
677
792
  return;
678
793
  }
679
794
  this._removeSubscriptions();
680
795
  this._dragDropRegistry.stopDragging(this);
796
+ if (this._handles) {
797
+ this._rootElement.style.webkitTapHighlightColor = this._rootElementTapHighlight;
798
+ }
681
799
  if (!this._hasStartedDragging) {
682
800
  return;
683
801
  }
802
+ this.released.next({ source: this });
684
803
  if (!this.dropContainer) {
685
804
  // Convert the active transform into a passive one. This means that next time
686
805
  // the user starts dragging the item, its position will be calculated relatively
687
806
  // to the new passive transform.
688
807
  this._passiveTransform.x = this._activeTransform.x;
689
808
  this._passiveTransform.y = this._activeTransform.y;
690
- this._ngZone.run(() => this.ended.emit({ source: this }));
809
+ this._ngZone.run(() => this.ended.next({ source: this }));
691
810
  this._dragDropRegistry.stopDragging(this);
692
811
  return;
693
812
  }
694
813
  this._animatePreviewToPlaceholder().then(() => {
695
- this._cleanupDragArtifacts();
814
+ this._cleanupDragArtifacts(event);
696
815
  this._dragDropRegistry.stopDragging(this);
697
816
  });
698
817
  };
699
- this._document = document;
818
+ this.withRootElement(element);
700
819
  _dragDropRegistry.registerDragItem(this);
701
820
  }
702
821
  /**
@@ -704,7 +823,7 @@ class CdkDrag {
704
823
  * @return {?}
705
824
  */
706
825
  get disabled() {
707
- return this._disabled || (this.dropContainer && this.dropContainer.disabled);
826
+ return this._disabled || !!(this.dropContainer && this.dropContainer.disabled);
708
827
  }
709
828
  /**
710
829
  * @param {?} value
@@ -728,6 +847,114 @@ class CdkDrag {
728
847
  getRootElement() {
729
848
  return this._rootElement;
730
849
  }
850
+ /**
851
+ * Registers the handles that can be used to drag the element.
852
+ * @template THIS
853
+ * @this {THIS}
854
+ * @param {?} handles
855
+ * @return {THIS}
856
+ */
857
+ withHandles(handles) {
858
+ // TODO(crisbeto): have this accept HTMLElement[] | ElementRef<HTMLElement>[]
859
+ (/** @type {?} */ (this))._handles = handles;
860
+ handles.forEach(handle => toggleNativeDragInteractions(handle.element.nativeElement, false));
861
+ (/** @type {?} */ (this))._toggleNativeDragInteractions();
862
+ return (/** @type {?} */ (this));
863
+ }
864
+ /**
865
+ * Registers the template that should be used for the drag preview.
866
+ * @template THIS
867
+ * @this {THIS}
868
+ * @param {?} template
869
+ * @return {THIS}
870
+ */
871
+ withPreviewTemplate(template) {
872
+ // TODO(crisbeto): have this accept a TemplateRef
873
+ (/** @type {?} */ (this))._previewTemplate = template;
874
+ return (/** @type {?} */ (this));
875
+ }
876
+ /**
877
+ * Registers the template that should be used for the drag placeholder.
878
+ * @template THIS
879
+ * @this {THIS}
880
+ * @param {?} template
881
+ * @return {THIS}
882
+ */
883
+ withPlaceholderTemplate(template) {
884
+ // TODO(crisbeto): have this accept a TemplateRef
885
+ (/** @type {?} */ (this))._placeholderTemplate = template;
886
+ return (/** @type {?} */ (this));
887
+ }
888
+ /**
889
+ * Sets an alternate drag root element. The root element is the element that will be moved as
890
+ * the user is dragging. Passing an alternate root element is useful when trying to enable
891
+ * dragging on an element that you might not have access to.
892
+ * @template THIS
893
+ * @this {THIS}
894
+ * @param {?} rootElement
895
+ * @return {THIS}
896
+ */
897
+ withRootElement(rootElement) {
898
+ /** @type {?} */
899
+ const element = rootElement instanceof ElementRef ? rootElement.nativeElement : rootElement;
900
+ if (element !== (/** @type {?} */ (this))._rootElement) {
901
+ if ((/** @type {?} */ (this))._rootElement) {
902
+ (/** @type {?} */ (this))._removeRootElementListeners((/** @type {?} */ (this))._rootElement);
903
+ }
904
+ element.addEventListener('mousedown', (/** @type {?} */ (this))._pointerDown, activeEventListenerOptions);
905
+ element.addEventListener('touchstart', (/** @type {?} */ (this))._pointerDown, passiveEventListenerOptions);
906
+ (/** @type {?} */ (this))._rootElement = element;
907
+ }
908
+ return (/** @type {?} */ (this));
909
+ }
910
+ /**
911
+ * Element to which the draggable's position will be constrained.
912
+ * @template THIS
913
+ * @this {THIS}
914
+ * @param {?} boundaryElement
915
+ * @return {THIS}
916
+ */
917
+ withBoundaryElement(boundaryElement) {
918
+ (/** @type {?} */ (this))._boundaryElement = boundaryElement instanceof ElementRef ?
919
+ boundaryElement.nativeElement : boundaryElement;
920
+ return (/** @type {?} */ (this));
921
+ }
922
+ /**
923
+ * Removes the dragging functionality from the DOM element.
924
+ * @return {?}
925
+ */
926
+ dispose() {
927
+ this._removeRootElementListeners(this._rootElement);
928
+ // Do this check before removing from the registry since it'll
929
+ // stop being considered as dragged once it is removed.
930
+ if (this.isDragging()) {
931
+ // Since we move out the element to the end of the body while it's being
932
+ // dragged, we have to make sure that it's removed if it gets destroyed.
933
+ removeElement(this._rootElement);
934
+ }
935
+ this._destroyPreview();
936
+ this._destroyPlaceholder();
937
+ this._dragDropRegistry.removeDragItem(this);
938
+ this._removeSubscriptions();
939
+ this.beforeStarted.complete();
940
+ this.started.complete();
941
+ this.released.complete();
942
+ this.ended.complete();
943
+ this.entered.complete();
944
+ this.exited.complete();
945
+ this.dropped.complete();
946
+ this._moveEvents.complete();
947
+ this._handles = [];
948
+ this._boundaryElement = this._rootElement = this._placeholderTemplate =
949
+ this._previewTemplate = this._nextSibling = (/** @type {?} */ (null));
950
+ }
951
+ /**
952
+ * Checks whether the element is currently being dragged.
953
+ * @return {?}
954
+ */
955
+ isDragging() {
956
+ return this._hasStartedDragging && this._dragDropRegistry.isDragging(this);
957
+ }
731
958
  /**
732
959
  * Resets a standalone drag item to its initial position.
733
960
  * @return {?}
@@ -738,61 +965,72 @@ class CdkDrag {
738
965
  this._passiveTransform = { x: 0, y: 0 };
739
966
  }
740
967
  /**
968
+ * Unsubscribes from the global subscriptions.
969
+ * @private
741
970
  * @return {?}
742
971
  */
743
- ngAfterViewInit() {
744
- // We need to wait for the zone to stabilize, in order for the reference
745
- // element to be in the proper place in the DOM. This is mostly relevant
746
- // for draggable elements inside portals since they get stamped out in
747
- // their original DOM position and then they get transferred to the portal.
748
- this._rootElementInitSubscription = this._ngZone.onStable.asObservable()
749
- .pipe(take(1))
750
- .subscribe(() => {
751
- /** @type {?} */
752
- const rootElement = this._rootElement = this._getRootElement();
753
- rootElement.addEventListener('mousedown', this._pointerDown, activeEventListenerOptions);
754
- rootElement.addEventListener('touchstart', this._pointerDown, passiveEventListenerOptions);
755
- this._handles.changes.pipe(startWith(null)).subscribe(() => toggleNativeDragInteractions(rootElement, this.getChildHandles().length > 0));
756
- });
972
+ _removeSubscriptions() {
973
+ this._pointerMoveSubscription.unsubscribe();
974
+ this._pointerUpSubscription.unsubscribe();
757
975
  }
758
976
  /**
977
+ * Destroys the preview element and its ViewRef.
978
+ * @private
759
979
  * @return {?}
760
980
  */
761
- ngOnDestroy() {
762
- // The directive might have been destroyed before the root element is initialized.
763
- if (this._rootElement) {
764
- this._rootElement.removeEventListener('mousedown', this._pointerDown, activeEventListenerOptions);
765
- this._rootElement.removeEventListener('touchstart', this._pointerDown, passiveEventListenerOptions);
766
- // Do this check before removing from the registry since it'll
767
- // stop being considered as dragged once it is removed.
768
- if (this._isDragging()) {
769
- // Since we move out the element to the end of the body while it's being
770
- // dragged, we have to make sure that it's removed if it gets destroyed.
771
- this._removeElement(this._rootElement);
772
- }
981
+ _destroyPreview() {
982
+ if (this._preview) {
983
+ removeElement(this._preview);
773
984
  }
774
- this._rootElementInitSubscription.unsubscribe();
775
- this._destroyPreview();
776
- this._destroyPlaceholder();
777
- this._nextSibling = null;
778
- this._dragDropRegistry.removeDragItem(this);
779
- this._removeSubscriptions();
780
- this._moveEvents.complete();
985
+ if (this._previewRef) {
986
+ this._previewRef.destroy();
987
+ }
988
+ this._preview = this._previewRef = (/** @type {?} */ (null));
781
989
  }
782
990
  /**
783
- * Checks whether the element is currently being dragged.
991
+ * Destroys the placeholder element and its ViewRef.
992
+ * @private
784
993
  * @return {?}
785
994
  */
786
- _isDragging() {
787
- return this._dragDropRegistry.isDragging(this);
995
+ _destroyPlaceholder() {
996
+ if (this._placeholder) {
997
+ removeElement(this._placeholder);
998
+ }
999
+ if (this._placeholderRef) {
1000
+ this._placeholderRef.destroy();
1001
+ }
1002
+ this._placeholder = this._placeholderRef = (/** @type {?} */ (null));
788
1003
  }
789
1004
  /**
790
- * Gets only handles that are not inside descendant `CdkDrag` instances.
1005
+ * Starts the dragging sequence.
791
1006
  * @private
1007
+ * @param {?} event
792
1008
  * @return {?}
793
1009
  */
794
- getChildHandles() {
795
- return this._handles.filter(handle => handle._parentDrag === this);
1010
+ _startDragSequence(event) {
1011
+ // Emit the event on the item before the one on the container.
1012
+ this.started.next({ source: this });
1013
+ if (isTouchEvent(event)) {
1014
+ this._lastTouchEventTime = Date.now();
1015
+ }
1016
+ if (this.dropContainer) {
1017
+ /** @type {?} */
1018
+ const element = this._rootElement;
1019
+ // Grab the `nextSibling` before the preview and placeholder
1020
+ // have been created so we don't get the preview by accident.
1021
+ this._nextSibling = element.nextSibling;
1022
+ /** @type {?} */
1023
+ const preview = this._preview = this._createPreviewElement();
1024
+ /** @type {?} */
1025
+ const placeholder = this._placeholder = this._createPlaceholderElement();
1026
+ // We move the element out at the end of the body and we make it hidden, because keeping it in
1027
+ // place will throw off the consumer's `:last-child` selectors. We can't remove the element
1028
+ // from the DOM completely, because iOS will stop firing all subsequent events in the chain.
1029
+ element.style.display = 'none';
1030
+ this._document.body.appendChild((/** @type {?} */ (element.parentNode)).replaceChild(placeholder, element));
1031
+ this._document.body.appendChild(preview);
1032
+ this.dropContainer.start();
1033
+ }
796
1034
  }
797
1035
  /**
798
1036
  * Sets up the different variables and subscriptions
@@ -808,13 +1046,15 @@ class CdkDrag {
808
1046
  // starting another sequence for a draggable parent somewhere up the DOM tree.
809
1047
  event.stopPropagation();
810
1048
  /** @type {?} */
811
- const isDragging = this._isDragging();
1049
+ const isDragging = this.isDragging();
1050
+ /** @type {?} */
1051
+ const isTouchSequence = isTouchEvent(event);
812
1052
  /** @type {?} */
813
- const isTouchEvent = this._isTouchEvent(event);
1053
+ const isAuxiliaryMouseButton = !isTouchSequence && ((/** @type {?} */ (event))).button !== 0;
814
1054
  /** @type {?} */
815
- const isAuxiliaryMouseButton = !isTouchEvent && ((/** @type {?} */ (event))).button !== 0;
1055
+ const rootElement = this._rootElement;
816
1056
  /** @type {?} */
817
- const isSyntheticEvent = !isTouchEvent && this._lastTouchEventTime &&
1057
+ const isSyntheticEvent = !isTouchSequence && this._lastTouchEventTime &&
818
1058
  this._lastTouchEventTime + MOUSE_EVENT_IGNORE_TIME > Date.now();
819
1059
  // If the event started from an element with the native HTML drag&drop, it'll interfere
820
1060
  // with our own dragging (e.g. `img` tags do it by default). Prevent the default action
@@ -834,11 +1074,22 @@ class CdkDrag {
834
1074
  if (this._initialTransform == null) {
835
1075
  this._initialTransform = this._rootElement.style.transform || '';
836
1076
  }
1077
+ // If we've got handles, we need to disable the tap highlight on the entire root element,
1078
+ // otherwise iOS will still add it, even though all the drag interactions on the handle
1079
+ // are disabled.
1080
+ if (this._handles.length) {
1081
+ this._rootElementTapHighlight = rootElement.style.webkitTapHighlightColor;
1082
+ rootElement.style.webkitTapHighlightColor = 'transparent';
1083
+ }
1084
+ this._toggleNativeDragInteractions();
837
1085
  this._hasStartedDragging = this._hasMoved = false;
838
- this._initialContainer = this.dropContainer;
1086
+ this._initialContainer = (/** @type {?} */ (this.dropContainer));
839
1087
  this._pointerMoveSubscription = this._dragDropRegistry.pointerMove.subscribe(this._pointerMove);
840
1088
  this._pointerUpSubscription = this._dragDropRegistry.pointerUp.subscribe(this._pointerUp);
841
1089
  this._scrollPosition = this._viewportRuler.getViewportScrollPosition();
1090
+ if (this._boundaryElement) {
1091
+ this._boundaryRect = this._boundaryElement.getBoundingClientRect();
1092
+ }
842
1093
  // If we have a custom preview template, the element won't be visible anyway so we avoid the
843
1094
  // extra `getBoundingClientRect` calls and just move the preview next to the cursor.
844
1095
  this._pickupPositionInElement = this._previewTemplate ? { x: 0, y: 0 } :
@@ -849,43 +1100,13 @@ class CdkDrag {
849
1100
  this._pointerPositionAtLastDirectionChange = { x: pointerPosition.x, y: pointerPosition.y };
850
1101
  this._dragDropRegistry.startDragging(this, event);
851
1102
  }
852
- /**
853
- * Starts the dragging sequence.
854
- * @private
855
- * @param {?} event
856
- * @return {?}
857
- */
858
- _startDragSequence(event) {
859
- // Emit the event on the item before the one on the container.
860
- this.started.emit({ source: this });
861
- if (this._isTouchEvent(event)) {
862
- this._lastTouchEventTime = Date.now();
863
- }
864
- if (this.dropContainer) {
865
- /** @type {?} */
866
- const element = this._rootElement;
867
- // Grab the `nextSibling` before the preview and placeholder
868
- // have been created so we don't get the preview by accident.
869
- this._nextSibling = element.nextSibling;
870
- /** @type {?} */
871
- const preview = this._preview = this._createPreviewElement();
872
- /** @type {?} */
873
- const placeholder = this._placeholder = this._createPlaceholderElement();
874
- // We move the element out at the end of the body and we make it hidden, because keeping it in
875
- // place will throw off the consumer's `:last-child` selectors. We can't remove the element
876
- // from the DOM completely, because iOS will stop firing all subsequent events in the chain.
877
- element.style.display = 'none';
878
- this._document.body.appendChild((/** @type {?} */ (element.parentNode)).replaceChild(placeholder, element));
879
- this._document.body.appendChild(preview);
880
- this.dropContainer.start();
881
- }
882
- }
883
1103
  /**
884
1104
  * Cleans up the DOM artifacts that were added to facilitate the element being dragged.
885
1105
  * @private
1106
+ * @param {?} event
886
1107
  * @return {?}
887
1108
  */
888
- _cleanupDragArtifacts() {
1109
+ _cleanupDragArtifacts(event) {
889
1110
  // Restore the element's visibility and insert it at its old position in the DOM.
890
1111
  // It's important that we maintain the position, because moving the element around in the DOM
891
1112
  // can throw off `NgFor` which does smart diffing and re-creates elements only when necessary,
@@ -899,19 +1120,26 @@ class CdkDrag {
899
1120
  }
900
1121
  this._destroyPreview();
901
1122
  this._destroyPlaceholder();
1123
+ this._boundaryRect = this._previewRect = undefined;
902
1124
  // Re-enter the NgZone since we bound `document` events on the outside.
903
1125
  this._ngZone.run(() => {
904
1126
  /** @type {?} */
905
- const currentIndex = this.dropContainer.getItemIndex(this);
906
- this.ended.emit({ source: this });
907
- this.dropped.emit({
1127
+ const container = (/** @type {?} */ (this.dropContainer));
1128
+ /** @type {?} */
1129
+ const currentIndex = container.getItemIndex(this);
1130
+ const { x, y } = this._getPointerPositionOnPage(event);
1131
+ /** @type {?} */
1132
+ const isPointerOverContainer = container._isOverContainer(x, y);
1133
+ this.ended.next({ source: this });
1134
+ this.dropped.next({
908
1135
  item: this,
909
1136
  currentIndex,
910
1137
  previousIndex: this._initialContainer.getItemIndex(this),
911
- container: this.dropContainer,
912
- previousContainer: this._initialContainer
1138
+ container: container,
1139
+ previousContainer: this._initialContainer,
1140
+ isPointerOverContainer
913
1141
  });
914
- this.dropContainer.drop(this, currentIndex, this._initialContainer);
1142
+ container.drop(this, currentIndex, this._initialContainer, isPointerOverContainer);
915
1143
  this.dropContainer = this._initialContainer;
916
1144
  });
917
1145
  }
@@ -925,27 +1153,27 @@ class CdkDrag {
925
1153
  _updateActiveDropContainer({ x, y }) {
926
1154
  // Drop container that draggable has been moved into.
927
1155
  /** @type {?} */
928
- let newContainer = this.dropContainer._getSiblingContainerFromPosition(this, x, y);
1156
+ let newContainer = (/** @type {?} */ (this.dropContainer))._getSiblingContainerFromPosition(this, x, y);
929
1157
  // If we couldn't find a new container to move the item into, and the item has left it's
930
- // initial container, check whether the it's allowed to return into its original container.
931
- // This handles the case where two containers are connected one way and the user tries to
932
- // undo dragging an item into a new container.
1158
+ // initial container, check whether the it's over the initial container. This handles the
1159
+ // case where two containers are connected one way and the user tries to undo dragging an
1160
+ // item into a new container.
933
1161
  if (!newContainer && this.dropContainer !== this._initialContainer &&
934
- this._initialContainer._canReturnItem(x, y)) {
1162
+ this._initialContainer._isOverContainer(x, y)) {
935
1163
  newContainer = this._initialContainer;
936
1164
  }
937
1165
  if (newContainer) {
938
1166
  this._ngZone.run(() => {
939
1167
  // Notify the old container that the item has left.
940
- this.exited.emit({ item: this, container: this.dropContainer });
941
- this.dropContainer.exit(this);
1168
+ this.exited.next({ item: this, container: (/** @type {?} */ (this.dropContainer)) });
1169
+ (/** @type {?} */ (this.dropContainer)).exit(this);
942
1170
  // Notify the new container that the item has entered.
943
- this.entered.emit({ item: this, container: (/** @type {?} */ (newContainer)) });
1171
+ this.entered.next({ item: this, container: (/** @type {?} */ (newContainer)) });
944
1172
  this.dropContainer = (/** @type {?} */ (newContainer));
945
1173
  this.dropContainer.enter(this, x, y);
946
1174
  });
947
1175
  }
948
- this.dropContainer._sortItem(this, x, y, this._pointerDirectionDelta);
1176
+ (/** @type {?} */ (this.dropContainer))._sortItem(this, x, y, this._pointerDirectionDelta);
949
1177
  this._preview.style.transform =
950
1178
  getTransform(x - this._pickupPositionInElement.x, y - this._pickupPositionInElement.y);
951
1179
  }
@@ -977,58 +1205,19 @@ class CdkDrag {
977
1205
  preview.style.transform = getTransform(elementRect.left, elementRect.top);
978
1206
  }
979
1207
  extendStyles(preview.style, {
1208
+ // It's important that we disable the pointer events on the preview, because
1209
+ // it can throw off the `document.elementFromPoint` calls in the `CdkDropList`.
1210
+ pointerEvents: 'none',
980
1211
  position: 'fixed',
981
1212
  top: '0',
982
1213
  left: '0',
983
1214
  zIndex: '1000'
984
1215
  });
1216
+ toggleNativeDragInteractions(preview, false);
985
1217
  preview.classList.add('cdk-drag-preview');
986
1218
  preview.setAttribute('dir', this._dir ? this._dir.value : 'ltr');
987
1219
  return preview;
988
1220
  }
989
- /**
990
- * Creates an element that will be shown instead of the current element while dragging.
991
- * @private
992
- * @return {?}
993
- */
994
- _createPlaceholderElement() {
995
- /** @type {?} */
996
- let placeholder;
997
- if (this._placeholderTemplate) {
998
- this._placeholderRef = this._viewContainerRef.createEmbeddedView(this._placeholderTemplate.templateRef, this._placeholderTemplate.data);
999
- placeholder = this._placeholderRef.rootNodes[0];
1000
- }
1001
- else {
1002
- placeholder = deepCloneNode(this._rootElement);
1003
- }
1004
- placeholder.classList.add('cdk-drag-placeholder');
1005
- return placeholder;
1006
- }
1007
- /**
1008
- * Figures out the coordinates at which an element was picked up.
1009
- * @private
1010
- * @param {?} referenceElement Element that initiated the dragging.
1011
- * @param {?} event Event that initiated the dragging.
1012
- * @return {?}
1013
- */
1014
- _getPointerPositionInElement(referenceElement, event) {
1015
- /** @type {?} */
1016
- const elementRect = this._rootElement.getBoundingClientRect();
1017
- /** @type {?} */
1018
- const handleElement = referenceElement === this._rootElement ? null : referenceElement;
1019
- /** @type {?} */
1020
- const referenceRect = handleElement ? handleElement.getBoundingClientRect() : elementRect;
1021
- /** @type {?} */
1022
- const point = this._isTouchEvent(event) ? event.targetTouches[0] : event;
1023
- /** @type {?} */
1024
- const x = point.pageX - referenceRect.left - this._scrollPosition.left;
1025
- /** @type {?} */
1026
- const y = point.pageY - referenceRect.top - this._scrollPosition.top;
1027
- return {
1028
- x: referenceRect.left - elementRect.left + x,
1029
- y: referenceRect.top - elementRect.top + y
1030
- };
1031
- }
1032
1221
  /**
1033
1222
  * Animates the preview element from its current position to the location of the drop placeholder.
1034
1223
  * @private
@@ -1074,15 +1263,47 @@ class CdkDrag {
1074
1263
  });
1075
1264
  }
1076
1265
  /**
1077
- * Helper to remove an element from the DOM and to do all the necessary null checks.
1266
+ * Creates an element that will be shown instead of the current element while dragging.
1078
1267
  * @private
1079
- * @param {?} element Element to be removed.
1080
1268
  * @return {?}
1081
1269
  */
1082
- _removeElement(element) {
1083
- if (element && element.parentNode) {
1084
- element.parentNode.removeChild(element);
1270
+ _createPlaceholderElement() {
1271
+ /** @type {?} */
1272
+ let placeholder;
1273
+ if (this._placeholderTemplate) {
1274
+ this._placeholderRef = this._viewContainerRef.createEmbeddedView(this._placeholderTemplate.templateRef, this._placeholderTemplate.data);
1275
+ placeholder = this._placeholderRef.rootNodes[0];
1276
+ }
1277
+ else {
1278
+ placeholder = deepCloneNode(this._rootElement);
1085
1279
  }
1280
+ placeholder.classList.add('cdk-drag-placeholder');
1281
+ return placeholder;
1282
+ }
1283
+ /**
1284
+ * Figures out the coordinates at which an element was picked up.
1285
+ * @private
1286
+ * @param {?} referenceElement Element that initiated the dragging.
1287
+ * @param {?} event Event that initiated the dragging.
1288
+ * @return {?}
1289
+ */
1290
+ _getPointerPositionInElement(referenceElement, event) {
1291
+ /** @type {?} */
1292
+ const elementRect = this._rootElement.getBoundingClientRect();
1293
+ /** @type {?} */
1294
+ const handleElement = referenceElement === this._rootElement ? null : referenceElement;
1295
+ /** @type {?} */
1296
+ const referenceRect = handleElement ? handleElement.getBoundingClientRect() : elementRect;
1297
+ /** @type {?} */
1298
+ const point = isTouchEvent(event) ? event.targetTouches[0] : event;
1299
+ /** @type {?} */
1300
+ const x = point.pageX - referenceRect.left - this._scrollPosition.left;
1301
+ /** @type {?} */
1302
+ const y = point.pageY - referenceRect.top - this._scrollPosition.top;
1303
+ return {
1304
+ x: referenceRect.left - elementRect.left + x,
1305
+ y: referenceRect.top - elementRect.top + y
1306
+ };
1086
1307
  }
1087
1308
  /**
1088
1309
  * Determines the point of the page that was touched by the user.
@@ -1091,8 +1312,9 @@ class CdkDrag {
1091
1312
  * @return {?}
1092
1313
  */
1093
1314
  _getPointerPositionOnPage(event) {
1315
+ // `touches` will be empty for start/end events so we have to fall back to `changedTouches`.
1094
1316
  /** @type {?} */
1095
- const point = this._isTouchEvent(event) ? event.touches[0] : event;
1317
+ const point = isTouchEvent(event) ? (event.touches[0] || event.changedTouches[0]) : event;
1096
1318
  return {
1097
1319
  x: point.pageX - this._scrollPosition.left,
1098
1320
  y: point.pageY - this._scrollPosition.top
@@ -1115,44 +1337,24 @@ class CdkDrag {
1115
1337
  else if (this.lockAxis === 'y' || dropContainerLock === 'y') {
1116
1338
  point.x = this._pickupPositionOnPage.x;
1117
1339
  }
1118
- return point;
1119
- }
1120
- /**
1121
- * Determines whether an event is a touch event.
1122
- * @private
1123
- * @param {?} event
1124
- * @return {?}
1125
- */
1126
- _isTouchEvent(event) {
1127
- return event.type.startsWith('touch');
1128
- }
1129
- /**
1130
- * Destroys the preview element and its ViewRef.
1131
- * @private
1132
- * @return {?}
1133
- */
1134
- _destroyPreview() {
1135
- if (this._preview) {
1136
- this._removeElement(this._preview);
1137
- }
1138
- if (this._previewRef) {
1139
- this._previewRef.destroy();
1140
- }
1141
- this._preview = this._previewRef = (/** @type {?} */ (null));
1142
- }
1143
- /**
1144
- * Destroys the placeholder element and its ViewRef.
1145
- * @private
1146
- * @return {?}
1147
- */
1148
- _destroyPlaceholder() {
1149
- if (this._placeholder) {
1150
- this._removeElement(this._placeholder);
1151
- }
1152
- if (this._placeholderRef) {
1153
- this._placeholderRef.destroy();
1340
+ if (this._boundaryRect) {
1341
+ const { x: pickupX, y: pickupY } = this._pickupPositionInElement;
1342
+ /** @type {?} */
1343
+ const boundaryRect = this._boundaryRect;
1344
+ /** @type {?} */
1345
+ const previewRect = (/** @type {?} */ (this._previewRect));
1346
+ /** @type {?} */
1347
+ const minY = boundaryRect.top + pickupY;
1348
+ /** @type {?} */
1349
+ const maxY = boundaryRect.bottom - (previewRect.height - pickupY);
1350
+ /** @type {?} */
1351
+ const minX = boundaryRect.left + pickupX;
1352
+ /** @type {?} */
1353
+ const maxX = boundaryRect.right - (previewRect.width - pickupX);
1354
+ point.x = clamp$1(point.x, minX, maxX);
1355
+ point.y = clamp$1(point.y, minY, maxY);
1154
1356
  }
1155
- this._placeholder = this._placeholderRef = (/** @type {?} */ (null));
1357
+ return point;
1156
1358
  }
1157
1359
  /**
1158
1360
  * Updates the current drag delta, based on the user's current pointer position on the page.
@@ -1186,78 +1388,31 @@ class CdkDrag {
1186
1388
  return delta;
1187
1389
  }
1188
1390
  /**
1189
- * Gets the root draggable element, based on the `rootElementSelector`.
1391
+ * Toggles the native drag interactions, based on how many handles are registered.
1190
1392
  * @private
1191
1393
  * @return {?}
1192
1394
  */
1193
- _getRootElement() {
1194
- if (this.rootElementSelector) {
1195
- /** @type {?} */
1196
- const selector = this.rootElementSelector;
1197
- /** @type {?} */
1198
- let currentElement = (/** @type {?} */ (this.element.nativeElement.parentElement));
1199
- while (currentElement) {
1200
- // IE doesn't support `matches` so we have to fall back to `msMatchesSelector`.
1201
- if (currentElement.matches ? currentElement.matches(selector) :
1202
- ((/** @type {?} */ (currentElement))).msMatchesSelector(selector)) {
1203
- return currentElement;
1204
- }
1205
- currentElement = currentElement.parentElement;
1206
- }
1395
+ _toggleNativeDragInteractions() {
1396
+ /** @type {?} */
1397
+ const shouldEnable = this._handles.length > 0;
1398
+ // We go through the trouble of keeping track of whether the interactions are enabled,
1399
+ // because we want to avoid triggering style recalculations unless we really have to.
1400
+ if (shouldEnable !== this._nativeInteractionsEnabled) {
1401
+ this._nativeInteractionsEnabled = shouldEnable;
1402
+ toggleNativeDragInteractions(this._rootElement, shouldEnable);
1207
1403
  }
1208
- return this.element.nativeElement;
1209
1404
  }
1210
1405
  /**
1211
- * Unsubscribes from the global subscriptions.
1406
+ * Removes the manually-added event listeners from the root element.
1212
1407
  * @private
1408
+ * @param {?} element
1213
1409
  * @return {?}
1214
1410
  */
1215
- _removeSubscriptions() {
1216
- this._pointerMoveSubscription.unsubscribe();
1217
- this._pointerUpSubscription.unsubscribe();
1411
+ _removeRootElementListeners(element) {
1412
+ element.removeEventListener('mousedown', this._pointerDown, activeEventListenerOptions);
1413
+ element.removeEventListener('touchstart', this._pointerDown, passiveEventListenerOptions);
1218
1414
  }
1219
1415
  }
1220
- CdkDrag.decorators = [
1221
- { type: Directive, args: [{
1222
- selector: '[cdkDrag]',
1223
- exportAs: 'cdkDrag',
1224
- host: {
1225
- 'class': 'cdk-drag',
1226
- '[class.cdk-drag-dragging]': '_hasStartedDragging && _isDragging()',
1227
- },
1228
- providers: [{
1229
- provide: CDK_DRAG_PARENT,
1230
- useExisting: CdkDrag
1231
- }]
1232
- },] },
1233
- ];
1234
- /** @nocollapse */
1235
- CdkDrag.ctorParameters = () => [
1236
- { type: ElementRef },
1237
- { type: undefined, decorators: [{ type: Inject, args: [CDK_DROP_LIST_CONTAINER,] }, { type: Optional }, { type: SkipSelf }] },
1238
- { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] }] },
1239
- { type: NgZone },
1240
- { type: ViewContainerRef },
1241
- { type: ViewportRuler },
1242
- { type: DragDropRegistry },
1243
- { type: undefined, decorators: [{ type: Inject, args: [CDK_DRAG_CONFIG,] }] },
1244
- { type: Directionality, decorators: [{ type: Optional }] }
1245
- ];
1246
- CdkDrag.propDecorators = {
1247
- _handles: [{ type: ContentChildren, args: [CdkDragHandle, { descendants: true },] }],
1248
- _previewTemplate: [{ type: ContentChild, args: [CdkDragPreview,] }],
1249
- _placeholderTemplate: [{ type: ContentChild, args: [CdkDragPlaceholder,] }],
1250
- data: [{ type: Input, args: ['cdkDragData',] }],
1251
- lockAxis: [{ type: Input, args: ['cdkDragLockAxis',] }],
1252
- rootElementSelector: [{ type: Input, args: ['cdkDragRootElement',] }],
1253
- disabled: [{ type: Input, args: ['cdkDragDisabled',] }],
1254
- started: [{ type: Output, args: ['cdkDragStarted',] }],
1255
- ended: [{ type: Output, args: ['cdkDragEnded',] }],
1256
- entered: [{ type: Output, args: ['cdkDragEntered',] }],
1257
- exited: [{ type: Output, args: ['cdkDragExited',] }],
1258
- dropped: [{ type: Output, args: ['cdkDragDropped',] }],
1259
- moved: [{ type: Output, args: ['cdkDragMoved',] }]
1260
- };
1261
1416
  /**
1262
1417
  * Gets a 3d `transform` that can be applied to an element.
1263
1418
  * @param {?} x Desired position of the element along the X axis.
@@ -1266,7 +1421,7 @@ CdkDrag.propDecorators = {
1266
1421
  */
1267
1422
  function getTransform(x, y) {
1268
1423
  // Round the transforms since some browsers will
1269
- // blur the elements, for sub-pixel transforms.
1424
+ // blur the elements for sub-pixel transforms.
1270
1425
  return `translate3d(${Math.round(x)}px, ${Math.round(y)}px, 0)`;
1271
1426
  }
1272
1427
  /**
@@ -1281,206 +1436,147 @@ function deepCloneNode(node) {
1281
1436
  clone.removeAttribute('id');
1282
1437
  return clone;
1283
1438
  }
1284
-
1285
- /**
1286
- * @fileoverview added by tsickle
1287
- * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
1288
- */
1289
-
1290
1439
  /**
1291
- * Moves an item one index in an array to another.
1292
- * @template T
1293
- * @param {?} array Array in which to move the item.
1294
- * @param {?} fromIndex Starting index of the item.
1295
- * @param {?} toIndex Index to which the item should be moved.
1440
+ * Clamps a value between a minimum and a maximum.
1441
+ * @param {?} value
1442
+ * @param {?} min
1443
+ * @param {?} max
1296
1444
  * @return {?}
1297
1445
  */
1298
- function moveItemInArray(array, fromIndex, toIndex) {
1299
- /** @type {?} */
1300
- const from = clamp(fromIndex, array.length - 1);
1301
- /** @type {?} */
1302
- const to = clamp(toIndex, array.length - 1);
1303
- if (from === to) {
1304
- return;
1305
- }
1306
- /** @type {?} */
1307
- const target = array[from];
1308
- /** @type {?} */
1309
- const delta = to < from ? -1 : 1;
1310
- for (let i = from; i !== to; i += delta) {
1311
- array[i] = array[i + delta];
1312
- }
1313
- array[to] = target;
1446
+ function clamp$1(value, min, max) {
1447
+ return Math.max(min, Math.min(max, value));
1314
1448
  }
1315
1449
  /**
1316
- * Moves an item from one array to another.
1317
- * @template T
1318
- * @param {?} currentArray Array from which to transfer the item.
1319
- * @param {?} targetArray Array into which to put the item.
1320
- * @param {?} currentIndex Index of the item in its current array.
1321
- * @param {?} targetIndex Index at which to insert the item.
1450
+ * Helper to remove an element from the DOM and to do all the necessary null checks.
1451
+ * @param {?} element Element to be removed.
1322
1452
  * @return {?}
1323
1453
  */
1324
- function transferArrayItem(currentArray, targetArray, currentIndex, targetIndex) {
1325
- /** @type {?} */
1326
- const from = clamp(currentIndex, currentArray.length - 1);
1327
- /** @type {?} */
1328
- const to = clamp(targetIndex, targetArray.length);
1329
- if (currentArray.length) {
1330
- targetArray.splice(to, 0, currentArray.splice(from, 1)[0]);
1454
+ function removeElement(element) {
1455
+ if (element && element.parentNode) {
1456
+ element.parentNode.removeChild(element);
1331
1457
  }
1332
1458
  }
1333
1459
  /**
1334
- * Copies an item from one array to another, leaving it in its
1335
- * original position in current array.
1336
- * @template T
1337
- * @param {?} currentArray Array from which to copy the item.
1338
- * @param {?} targetArray Array into which is copy the item.
1339
- * @param {?} currentIndex Index of the item in its current array.
1340
- * @param {?} targetIndex Index at which to insert the item.
1341
- *
1460
+ * Determines whether an event is a touch event.
1461
+ * @param {?} event
1342
1462
  * @return {?}
1343
1463
  */
1344
- function copyArrayItem(currentArray, targetArray, currentIndex, targetIndex) {
1345
- /** @type {?} */
1346
- const to = clamp(targetIndex, targetArray.length);
1347
- if (currentArray.length) {
1348
- targetArray.splice(to, 0, currentArray[currentIndex]);
1349
- }
1464
+ function isTouchEvent(event) {
1465
+ return event.type.startsWith('touch');
1350
1466
  }
1351
- /**
1352
- * Clamps a number between zero and a maximum.
1353
- * @param {?} value
1354
- * @param {?} max
1355
- * @return {?}
1356
- */
1357
- function clamp(value, max) {
1358
- return Math.max(0, Math.min(max, value));
1359
- }
1360
-
1361
- /**
1362
- * @fileoverview added by tsickle
1363
- * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
1364
- */
1365
- /**
1366
- * Declaratively connects sibling `cdkDropList` instances together. All of the `cdkDropList`
1367
- * elements that are placed inside a `cdkDropListGroup` will be connected to each other
1368
- * automatically. Can be used as an alternative to the `cdkDropListConnectedTo` input
1369
- * from `cdkDropList`.
1370
- * @template T
1371
- */
1372
- class CdkDropListGroup {
1373
- constructor() {
1374
- /**
1375
- * Drop lists registered inside the group.
1376
- */
1377
- this._items = new Set();
1378
- }
1379
- /**
1380
- * @return {?}
1381
- */
1382
- ngOnDestroy() {
1383
- this._items.clear();
1384
- }
1385
- }
1386
- CdkDropListGroup.decorators = [
1387
- { type: Directive, args: [{
1388
- selector: '[cdkDropListGroup]',
1389
- exportAs: 'cdkDropListGroup',
1390
- },] },
1391
- ];
1392
1467
 
1393
1468
  /**
1394
1469
  * @fileoverview added by tsickle
1395
1470
  * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
1396
1471
  */
1397
1472
  /**
1398
- * Counter used to generate unique ids for drop zones.
1473
+ * Injection token that can be used to configure the behavior of `CdkDrag`.
1399
1474
  * @type {?}
1400
1475
  */
1401
- let _uniqueIdCounter = 0;
1476
+ const CDK_DRAG_CONFIG = new InjectionToken('CDK_DRAG_CONFIG', {
1477
+ providedIn: 'root',
1478
+ factory: CDK_DRAG_CONFIG_FACTORY
1479
+ });
1402
1480
  /**
1403
- * Proximity, as a ratio to width/height, at which a
1404
- * dragged item will affect the drop container.
1405
- * @type {?}
1481
+ * \@docs-private
1482
+ * @return {?}
1406
1483
  */
1407
- const DROP_PROXIMITY_THRESHOLD = 0.05;
1408
- const ɵ0 = undefined;
1484
+ function CDK_DRAG_CONFIG_FACTORY() {
1485
+ return { dragStartThreshold: 5, pointerDirectionChangeThreshold: 5 };
1486
+ }
1409
1487
  /**
1410
- * Container that wraps a set of draggable items.
1488
+ * Element that can be moved inside a CdkDropList container.
1411
1489
  * @template T
1412
1490
  */
1413
- class CdkDropList {
1491
+ class CdkDrag {
1414
1492
  /**
1415
1493
  * @param {?} element
1494
+ * @param {?} dropContainer
1495
+ * @param {?} _document
1496
+ * @param {?} _ngZone
1497
+ * @param {?} _viewContainerRef
1498
+ * @param {?} _viewportRuler
1416
1499
  * @param {?} _dragDropRegistry
1417
- * @param {?} _changeDetectorRef
1418
- * @param {?=} _dir
1419
- * @param {?=} _group
1500
+ * @param {?} _config
1501
+ * @param {?} _dir
1420
1502
  */
1421
- constructor(element, _dragDropRegistry, _changeDetectorRef, _dir, _group) {
1503
+ constructor(element, dropContainer, _document, _ngZone, _viewContainerRef, _viewportRuler, _dragDropRegistry, _config, _dir) {
1422
1504
  this.element = element;
1505
+ this.dropContainer = dropContainer;
1506
+ this._document = _document;
1507
+ this._ngZone = _ngZone;
1508
+ this._viewContainerRef = _viewContainerRef;
1509
+ this._viewportRuler = _viewportRuler;
1423
1510
  this._dragDropRegistry = _dragDropRegistry;
1424
- this._changeDetectorRef = _changeDetectorRef;
1511
+ this._config = _config;
1425
1512
  this._dir = _dir;
1426
- this._group = _group;
1427
1513
  /**
1428
- * Other draggable containers that this container is connected to and into which the
1429
- * container's items can be transferred. Can either be references to other drop containers,
1430
- * or their unique IDs.
1431
- */
1432
- this.connectedTo = [];
1433
- /**
1434
- * Direction in which the list is oriented.
1514
+ * Subscription to the stream that initializes the root element.
1435
1515
  */
1436
- this.orientation = 'vertical';
1516
+ this._rootElementInitSubscription = Subscription.EMPTY;
1517
+ this._disabled = false;
1437
1518
  /**
1438
- * Unique ID for the drop zone. Can be used as a reference
1439
- * in the `connectedTo` of another `CdkDropList`.
1519
+ * Emits when the user starts dragging the item.
1440
1520
  */
1441
- this.id = `cdk-drop-list-${_uniqueIdCounter++}`;
1442
- this._disabled = false;
1521
+ this.started = new EventEmitter();
1443
1522
  /**
1444
- * Function that is used to determine whether an item
1445
- * is allowed to be moved into a drop container.
1523
+ * Emits when the user has released a drag item, before any animations have started.
1446
1524
  */
1447
- this.enterPredicate = () => true;
1525
+ this.released = new EventEmitter();
1448
1526
  /**
1449
- * Emits when the user drops an item inside the container.
1527
+ * Emits when the user stops dragging an item in the container.
1450
1528
  */
1451
- this.dropped = new EventEmitter();
1529
+ this.ended = new EventEmitter();
1452
1530
  /**
1453
- * Emits when the user has moved a new drag item into this container.
1531
+ * Emits when the user has moved the item into a new container.
1454
1532
  */
1455
1533
  this.entered = new EventEmitter();
1456
1534
  /**
1457
- * Emits when the user removes an item from the container
1458
- * by dragging it into another container.
1535
+ * Emits when the user removes the item its container by dragging it into another container.
1459
1536
  */
1460
1537
  this.exited = new EventEmitter();
1461
1538
  /**
1462
- * Emits as the user is swapping items while actively dragging.
1463
- */
1464
- this.sorted = new EventEmitter();
1465
- /**
1466
- * Whether an item in the container is being dragged.
1467
- */
1468
- this._dragging = false;
1469
- /**
1470
- * Cache of the dimensions of all the items and the sibling containers.
1539
+ * Emits when the user drops the item inside a container.
1471
1540
  */
1472
- this._positionCache = { items: [], siblings: [], self: (/** @type {?} */ ({})) };
1541
+ this.dropped = new EventEmitter();
1473
1542
  /**
1474
- * Keeps track of the item that was last swapped with the dragged item, as
1475
- * well as what direction the pointer was moving in when the swap occured.
1543
+ * Emits as the user is dragging the item. Use with caution,
1544
+ * because this event will fire for every pixel that the user has dragged.
1476
1545
  */
1477
- this._previousSwap = { drag: (/** @type {?} */ (null)), delta: 0 };
1546
+ this.moved = Observable.create((observer) => {
1547
+ /** @type {?} */
1548
+ const subscription = this._dragRef.moved.pipe(map(movedEvent => ({
1549
+ source: this,
1550
+ pointerPosition: movedEvent.pointerPosition,
1551
+ event: movedEvent.event,
1552
+ delta: movedEvent.delta
1553
+ }))).subscribe(observer);
1554
+ return () => {
1555
+ subscription.unsubscribe();
1556
+ };
1557
+ });
1558
+ /** @type {?} */
1559
+ const ref = this._dragRef = new DragRef(element, this._document, this._ngZone, this._viewContainerRef, this._viewportRuler, this._dragDropRegistry, this._config, this.dropContainer ? this.dropContainer._dropListRef : undefined, this._dir);
1560
+ ref.data = this;
1561
+ ref.beforeStarted.subscribe(() => {
1562
+ if (!ref.isDragging()) {
1563
+ ref.disabled = this.disabled;
1564
+ ref.lockAxis = this.lockAxis;
1565
+ ref
1566
+ .withBoundaryElement(this._getBoundaryElement())
1567
+ .withPlaceholderTemplate(this._placeholderTemplate)
1568
+ .withPreviewTemplate(this._previewTemplate);
1569
+ }
1570
+ });
1571
+ this._proxyEvents(ref);
1478
1572
  }
1479
1573
  /**
1480
- * Whether starting a dragging sequence from this container is disabled.
1574
+ * Whether starting to drag this element is disabled.
1481
1575
  * @return {?}
1482
1576
  */
1483
- get disabled() { return this._disabled; }
1577
+ get disabled() {
1578
+ return this._disabled || (this.dropContainer && this.dropContainer.disabled);
1579
+ }
1484
1580
  /**
1485
1581
  * @param {?} value
1486
1582
  * @return {?}
@@ -1489,426 +1585,1095 @@ class CdkDropList {
1489
1585
  this._disabled = coerceBooleanProperty(value);
1490
1586
  }
1491
1587
  /**
1588
+ * Returns the element that is being used as a placeholder
1589
+ * while the current element is being dragged.
1492
1590
  * @return {?}
1493
1591
  */
1494
- ngOnInit() {
1495
- this._dragDropRegistry.registerDropContainer(this);
1496
- if (this._group) {
1497
- this._group._items.add(this);
1498
- }
1592
+ getPlaceholderElement() {
1593
+ return this._dragRef.getPlaceholderElement();
1499
1594
  }
1500
1595
  /**
1596
+ * Returns the root draggable element.
1501
1597
  * @return {?}
1502
1598
  */
1503
- ngOnDestroy() {
1504
- this._dragDropRegistry.removeDropContainer(this);
1505
- if (this._group) {
1506
- this._group._items.delete(this);
1507
- }
1599
+ getRootElement() {
1600
+ return this._dragRef.getRootElement();
1508
1601
  }
1509
1602
  /**
1510
- * Starts dragging an item.
1603
+ * Resets a standalone drag item to its initial position.
1511
1604
  * @return {?}
1512
1605
  */
1513
- start() {
1514
- this._dragging = true;
1515
- this._activeDraggables = this._draggables.toArray();
1516
- this._cachePositions();
1517
- this._changeDetectorRef.markForCheck();
1606
+ reset() {
1607
+ this._dragRef.reset();
1518
1608
  }
1519
1609
  /**
1520
- * Drops an item into this container.
1521
- * @param {?} item Item being dropped into the container.
1522
- * @param {?} currentIndex Index at which the item should be inserted.
1523
- * @param {?} previousContainer Container from which the item got dragged in.
1524
1610
  * @return {?}
1525
1611
  */
1526
- drop(item, currentIndex, previousContainer) {
1527
- this._reset();
1528
- this.dropped.emit({
1529
- item,
1530
- currentIndex,
1531
- previousIndex: previousContainer.getItemIndex(item),
1532
- container: this,
1533
- // TODO(crisbeto): reconsider whether to make this null if the containers are the same.
1534
- previousContainer
1612
+ ngAfterViewInit() {
1613
+ // We need to wait for the zone to stabilize, in order for the reference
1614
+ // element to be in the proper place in the DOM. This is mostly relevant
1615
+ // for draggable elements inside portals since they get stamped out in
1616
+ // their original DOM position and then they get transferred to the portal.
1617
+ this._rootElementInitSubscription = this._ngZone.onStable.asObservable()
1618
+ .pipe(take(1))
1619
+ .subscribe(() => {
1620
+ /** @type {?} */
1621
+ const rootElement = this._getRootElement();
1622
+ if (rootElement.nodeType !== this._document.ELEMENT_NODE) {
1623
+ throw Error(`cdkDrag must be attached to an element node. ` +
1624
+ `Currently attached to "${rootElement.nodeName}".`);
1625
+ }
1626
+ this._dragRef.withRootElement(rootElement);
1627
+ this._handles.changes
1628
+ .pipe(startWith(this._handles))
1629
+ .subscribe((handleList) => {
1630
+ this._dragRef.withHandles(handleList.filter(handle => handle._parentDrag === this));
1631
+ });
1535
1632
  });
1536
1633
  }
1537
1634
  /**
1538
- * Emits an event to indicate that the user moved an item into the container.
1539
- * @param {?} item Item that was moved into the container.
1540
- * @param {?} pointerX Position of the item along the X axis.
1541
- * @param {?} pointerY Position of the item along the Y axis.
1542
1635
  * @return {?}
1543
1636
  */
1544
- enter(item, pointerX, pointerY) {
1545
- this.entered.emit({ item, container: this });
1546
- this.start();
1547
- // We use the coordinates of where the item entered the drop
1548
- // zone to figure out at which index it should be inserted.
1549
- /** @type {?} */
1550
- const newIndex = this._getItemIndexFromPointerPosition(item, pointerX, pointerY);
1551
- /** @type {?} */
1552
- const currentIndex = this._activeDraggables.indexOf(item);
1553
- /** @type {?} */
1554
- const newPositionReference = this._activeDraggables[newIndex];
1555
- /** @type {?} */
1556
- const placeholder = item.getPlaceholderElement();
1557
- // Since the item may be in the `activeDraggables` already (e.g. if the user dragged it
1558
- // into another container and back again), we have to ensure that it isn't duplicated.
1559
- if (currentIndex > -1) {
1560
- this._activeDraggables.splice(currentIndex, 1);
1561
- }
1562
- // Don't use items that are being dragged as a reference, because
1563
- // their element has been moved down to the bottom of the body.
1564
- if (newPositionReference && !this._dragDropRegistry.isDragging(newPositionReference)) {
1565
- /** @type {?} */
1566
- const element = newPositionReference.getRootElement();
1567
- (/** @type {?} */ (element.parentElement)).insertBefore(placeholder, element);
1568
- this._activeDraggables.splice(newIndex, 0, item);
1569
- }
1570
- else {
1571
- this.element.nativeElement.appendChild(placeholder);
1572
- this._activeDraggables.push(item);
1573
- }
1574
- // The transform needs to be cleared so it doesn't throw off the measurements.
1575
- placeholder.style.transform = '';
1576
- // Note that the positions were already cached when we called `start` above,
1577
- // but we need to refresh them since the amount of items has changed.
1578
- this._cachePositions();
1637
+ ngOnDestroy() {
1638
+ this._rootElementInitSubscription.unsubscribe();
1639
+ this._dragRef.dispose();
1579
1640
  }
1580
1641
  /**
1581
- * Removes an item from the container after it was dragged into another container by the user.
1582
- * @param {?} item Item that was dragged out.
1642
+ * Gets the root draggable element, based on the `rootElementSelector`.
1643
+ * @private
1583
1644
  * @return {?}
1584
1645
  */
1585
- exit(item) {
1586
- this._reset();
1587
- this.exited.emit({ item, container: this });
1646
+ _getRootElement() {
1647
+ /** @type {?} */
1648
+ const element = this.element.nativeElement;
1649
+ /** @type {?} */
1650
+ const rootElement = this.rootElementSelector ?
1651
+ getClosestMatchingAncestor(element, this.rootElementSelector) : null;
1652
+ return rootElement || element;
1588
1653
  }
1589
1654
  /**
1590
- * Figures out the index of an item in the container.
1591
- * @param {?} item Item whose index should be determined.
1655
+ * Gets the boundary element, based on the `boundaryElementSelector`.
1656
+ * @private
1592
1657
  * @return {?}
1593
1658
  */
1594
- getItemIndex(item) {
1595
- if (!this._dragging) {
1596
- return this._draggables.toArray().indexOf(item);
1597
- }
1598
- // Items are sorted always by top/left in the cache, however they flow differently in RTL.
1599
- // The rest of the logic still stands no matter what orientation we're in, however
1600
- // we need to invert the array when determining the index.
1659
+ _getBoundaryElement() {
1601
1660
  /** @type {?} */
1602
- const items = this.orientation === 'horizontal' && this._dir && this._dir.value === 'rtl' ?
1603
- this._positionCache.items.slice().reverse() : this._positionCache.items;
1604
- return findIndex(items, currentItem => currentItem.drag === item);
1661
+ const selector = this.boundaryElementSelector;
1662
+ return selector ? getClosestMatchingAncestor(this.element.nativeElement, selector) : null;
1605
1663
  }
1606
1664
  /**
1607
- * Sorts an item inside the container based on its position.
1608
- * @param {?} item Item to be sorted.
1609
- * @param {?} pointerX Position of the item along the X axis.
1610
- * @param {?} pointerY Position of the item along the Y axis.
1611
- * @param {?} pointerDelta
1665
+ * Proxies the events from a DragRef to events that
1666
+ * match the interfaces of the CdkDrag outputs.
1667
+ * @private
1668
+ * @param {?} ref
1612
1669
  * @return {?}
1613
1670
  */
1614
- _sortItem(item, pointerX, pointerY, pointerDelta) {
1615
- // Don't sort the item if it's out of range.
1616
- if (!this._isPointerNearDropContainer(pointerX, pointerY)) {
1617
- return;
1618
- }
1619
- /** @type {?} */
1620
- const siblings = this._positionCache.items;
1621
- /** @type {?} */
1622
- const newIndex = this._getItemIndexFromPointerPosition(item, pointerX, pointerY, pointerDelta);
1623
- if (newIndex === -1 && siblings.length > 0) {
1624
- return;
1625
- }
1626
- /** @type {?} */
1627
- const isHorizontal = this.orientation === 'horizontal';
1628
- /** @type {?} */
1629
- const currentIndex = findIndex(siblings, currentItem => currentItem.drag === item);
1630
- /** @type {?} */
1631
- const siblingAtNewPosition = siblings[newIndex];
1671
+ _proxyEvents(ref) {
1672
+ ref.started.subscribe(() => {
1673
+ this.started.emit({ source: this });
1674
+ });
1675
+ ref.released.subscribe(() => {
1676
+ this.released.emit({ source: this });
1677
+ });
1678
+ ref.ended.subscribe(() => {
1679
+ this.ended.emit({ source: this });
1680
+ });
1681
+ ref.entered.subscribe(event => {
1682
+ this.entered.emit({
1683
+ container: event.container.data,
1684
+ item: this
1685
+ });
1686
+ });
1687
+ ref.exited.subscribe(event => {
1688
+ this.exited.emit({
1689
+ container: event.container.data,
1690
+ item: this
1691
+ });
1692
+ });
1693
+ ref.dropped.subscribe(event => {
1694
+ this.dropped.emit({
1695
+ previousIndex: event.previousIndex,
1696
+ currentIndex: event.currentIndex,
1697
+ previousContainer: event.previousContainer.data,
1698
+ container: event.container.data,
1699
+ isPointerOverContainer: event.isPointerOverContainer,
1700
+ item: this
1701
+ });
1702
+ });
1703
+ }
1704
+ }
1705
+ CdkDrag.decorators = [
1706
+ { type: Directive, args: [{
1707
+ selector: '[cdkDrag]',
1708
+ exportAs: 'cdkDrag',
1709
+ host: {
1710
+ 'class': 'cdk-drag',
1711
+ '[class.cdk-drag-dragging]': '_dragRef.isDragging()',
1712
+ },
1713
+ providers: [{ provide: CDK_DRAG_PARENT, useExisting: CdkDrag }]
1714
+ },] },
1715
+ ];
1716
+ /** @nocollapse */
1717
+ CdkDrag.ctorParameters = () => [
1718
+ { type: ElementRef },
1719
+ { type: undefined, decorators: [{ type: Inject, args: [CDK_DROP_LIST,] }, { type: Optional }, { type: SkipSelf }] },
1720
+ { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] }] },
1721
+ { type: NgZone },
1722
+ { type: ViewContainerRef },
1723
+ { type: ViewportRuler },
1724
+ { type: DragDropRegistry },
1725
+ { type: undefined, decorators: [{ type: Inject, args: [CDK_DRAG_CONFIG,] }] },
1726
+ { type: Directionality, decorators: [{ type: Optional }] }
1727
+ ];
1728
+ CdkDrag.propDecorators = {
1729
+ _handles: [{ type: ContentChildren, args: [CdkDragHandle, { descendants: true },] }],
1730
+ _previewTemplate: [{ type: ContentChild, args: [CdkDragPreview,] }],
1731
+ _placeholderTemplate: [{ type: ContentChild, args: [CdkDragPlaceholder,] }],
1732
+ data: [{ type: Input, args: ['cdkDragData',] }],
1733
+ lockAxis: [{ type: Input, args: ['cdkDragLockAxis',] }],
1734
+ rootElementSelector: [{ type: Input, args: ['cdkDragRootElement',] }],
1735
+ boundaryElementSelector: [{ type: Input, args: ['cdkDragBoundary',] }],
1736
+ disabled: [{ type: Input, args: ['cdkDragDisabled',] }],
1737
+ started: [{ type: Output, args: ['cdkDragStarted',] }],
1738
+ released: [{ type: Output, args: ['cdkDragReleased',] }],
1739
+ ended: [{ type: Output, args: ['cdkDragEnded',] }],
1740
+ entered: [{ type: Output, args: ['cdkDragEntered',] }],
1741
+ exited: [{ type: Output, args: ['cdkDragExited',] }],
1742
+ dropped: [{ type: Output, args: ['cdkDragDropped',] }],
1743
+ moved: [{ type: Output, args: ['cdkDragMoved',] }]
1744
+ };
1745
+ /**
1746
+ * Gets the closest ancestor of an element that matches a selector.
1747
+ * @param {?} element
1748
+ * @param {?} selector
1749
+ * @return {?}
1750
+ */
1751
+ function getClosestMatchingAncestor(element, selector) {
1752
+ /** @type {?} */
1753
+ let currentElement = (/** @type {?} */ (element.parentElement));
1754
+ while (currentElement) {
1755
+ // IE doesn't support `matches` so we have to fall back to `msMatchesSelector`.
1756
+ if (currentElement.matches ? currentElement.matches(selector) :
1757
+ ((/** @type {?} */ (currentElement))).msMatchesSelector(selector)) {
1758
+ return currentElement;
1759
+ }
1760
+ currentElement = currentElement.parentElement;
1761
+ }
1762
+ return null;
1763
+ }
1764
+
1765
+ /**
1766
+ * @fileoverview added by tsickle
1767
+ * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
1768
+ */
1769
+ /**
1770
+ * Declaratively connects sibling `cdkDropList` instances together. All of the `cdkDropList`
1771
+ * elements that are placed inside a `cdkDropListGroup` will be connected to each other
1772
+ * automatically. Can be used as an alternative to the `cdkDropListConnectedTo` input
1773
+ * from `cdkDropList`.
1774
+ * @template T
1775
+ */
1776
+ class CdkDropListGroup {
1777
+ constructor() {
1778
+ /**
1779
+ * Drop lists registered inside the group.
1780
+ */
1781
+ this._items = new Set();
1782
+ this._disabled = false;
1783
+ }
1784
+ /**
1785
+ * Whether starting a dragging sequence from inside this group is disabled.
1786
+ * @return {?}
1787
+ */
1788
+ get disabled() { return this._disabled; }
1789
+ /**
1790
+ * @param {?} value
1791
+ * @return {?}
1792
+ */
1793
+ set disabled(value) {
1794
+ this._disabled = coerceBooleanProperty(value);
1795
+ }
1796
+ /**
1797
+ * @return {?}
1798
+ */
1799
+ ngOnDestroy() {
1800
+ this._items.clear();
1801
+ }
1802
+ }
1803
+ CdkDropListGroup.decorators = [
1804
+ { type: Directive, args: [{
1805
+ selector: '[cdkDropListGroup]',
1806
+ exportAs: 'cdkDropListGroup',
1807
+ },] },
1808
+ ];
1809
+ CdkDropListGroup.propDecorators = {
1810
+ disabled: [{ type: Input, args: ['cdkDropListGroupDisabled',] }]
1811
+ };
1812
+
1813
+ /**
1814
+ * @fileoverview added by tsickle
1815
+ * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
1816
+ */
1817
+ /**
1818
+ * Counter used to generate unique ids for drop refs.
1819
+ * @type {?}
1820
+ */
1821
+ let _uniqueIdCounter = 0;
1822
+ /**
1823
+ * Proximity, as a ratio to width/height, at which a
1824
+ * dragged item will affect the drop container.
1825
+ * @type {?}
1826
+ */
1827
+ const DROP_PROXIMITY_THRESHOLD = 0.05;
1828
+ /**
1829
+ * Reference to a drop list. Used to manipulate or dispose of the container.
1830
+ * \@docs-private
1831
+ * @template T
1832
+ */
1833
+ class DropListRef {
1834
+ /**
1835
+ * @param {?} element
1836
+ * @param {?} _dragDropRegistry
1837
+ * @param {?} _document
1838
+ * @param {?=} _dir
1839
+ */
1840
+ constructor(element, _dragDropRegistry, _document, _dir) {
1841
+ this.element = element;
1842
+ this._dragDropRegistry = _dragDropRegistry;
1843
+ this._dir = _dir;
1844
+ /**
1845
+ * Unique ID for the drop list.
1846
+ * @deprecated No longer being used. To be removed.
1847
+ * \@breaking-change 8.0.0
1848
+ */
1849
+ this.id = `cdk-drop-list-ref-${_uniqueIdCounter++}`;
1850
+ /**
1851
+ * Whether starting a dragging sequence from this container is disabled.
1852
+ */
1853
+ this.disabled = false;
1854
+ /**
1855
+ * Function that is used to determine whether an item
1856
+ * is allowed to be moved into a drop container.
1857
+ */
1858
+ this.enterPredicate = () => true;
1859
+ /**
1860
+ * Emits right before dragging has started.
1861
+ */
1862
+ this.beforeStarted = new Subject();
1863
+ /**
1864
+ * Emits when the user has moved a new drag item into this container.
1865
+ */
1866
+ this.entered = new Subject();
1867
+ /**
1868
+ * Emits when the user removes an item from the container
1869
+ * by dragging it into another container.
1870
+ */
1871
+ this.exited = new Subject();
1872
+ /**
1873
+ * Emits when the user drops an item inside the container.
1874
+ */
1875
+ this.dropped = new Subject();
1876
+ /**
1877
+ * Emits as the user is swapping items while actively dragging.
1878
+ */
1879
+ this.sorted = new Subject();
1880
+ /**
1881
+ * Whether an item in the list is being dragged.
1882
+ */
1883
+ this._isDragging = false;
1884
+ /**
1885
+ * Cache of the dimensions of all the items and the sibling containers.
1886
+ */
1887
+ this._positionCache = { items: [], siblings: [], self: (/** @type {?} */ ({})) };
1888
+ /**
1889
+ * Keeps track of the item that was last swapped with the dragged item, as
1890
+ * well as what direction the pointer was moving in when the swap occured.
1891
+ */
1892
+ this._previousSwap = { drag: (/** @type {?} */ (null)), delta: 0 };
1893
+ this._siblings = [];
1894
+ /**
1895
+ * Direction in which the list is oriented.
1896
+ */
1897
+ this._orientation = 'vertical';
1898
+ /**
1899
+ * Amount of connected siblings that currently have a dragged item.
1900
+ */
1901
+ this._activeSiblings = 0;
1902
+ _dragDropRegistry.registerDropContainer(this);
1903
+ this._document = _document;
1904
+ }
1905
+ /**
1906
+ * Removes the drop list functionality from the DOM element.
1907
+ * @return {?}
1908
+ */
1909
+ dispose() {
1910
+ this.beforeStarted.complete();
1911
+ this.entered.complete();
1912
+ this.exited.complete();
1913
+ this.dropped.complete();
1914
+ this.sorted.complete();
1915
+ this._dragDropRegistry.removeDropContainer(this);
1916
+ }
1917
+ /**
1918
+ * Whether an item from this list is currently being dragged.
1919
+ * @return {?}
1920
+ */
1921
+ isDragging() {
1922
+ return this._isDragging;
1923
+ }
1924
+ /**
1925
+ * Starts dragging an item.
1926
+ * @return {?}
1927
+ */
1928
+ start() {
1929
+ this.beforeStarted.next();
1930
+ this._isDragging = true;
1931
+ this._activeDraggables = this._draggables.slice();
1932
+ this._cachePositions();
1933
+ this._positionCache.siblings.forEach(sibling => sibling.drop._toggleIsReceiving(true));
1934
+ }
1935
+ /**
1936
+ * Emits an event to indicate that the user moved an item into the container.
1937
+ * @param {?} item Item that was moved into the container.
1938
+ * @param {?} pointerX Position of the item along the X axis.
1939
+ * @param {?} pointerY Position of the item along the Y axis.
1940
+ * @return {?}
1941
+ */
1942
+ enter(item, pointerX, pointerY) {
1943
+ this.entered.next({ item, container: this });
1944
+ this.start();
1945
+ // We use the coordinates of where the item entered the drop
1946
+ // zone to figure out at which index it should be inserted.
1947
+ /** @type {?} */
1948
+ const newIndex = this._getItemIndexFromPointerPosition(item, pointerX, pointerY);
1949
+ /** @type {?} */
1950
+ const currentIndex = this._activeDraggables.indexOf(item);
1951
+ /** @type {?} */
1952
+ const newPositionReference = this._activeDraggables[newIndex];
1953
+ /** @type {?} */
1954
+ const placeholder = item.getPlaceholderElement();
1955
+ // Since the item may be in the `activeDraggables` already (e.g. if the user dragged it
1956
+ // into another container and back again), we have to ensure that it isn't duplicated.
1957
+ if (currentIndex > -1) {
1958
+ this._activeDraggables.splice(currentIndex, 1);
1959
+ }
1960
+ // Don't use items that are being dragged as a reference, because
1961
+ // their element has been moved down to the bottom of the body.
1962
+ if (newPositionReference && !this._dragDropRegistry.isDragging(newPositionReference)) {
1963
+ /** @type {?} */
1964
+ const element = newPositionReference.getRootElement();
1965
+ (/** @type {?} */ (element.parentElement)).insertBefore(placeholder, element);
1966
+ this._activeDraggables.splice(newIndex, 0, item);
1967
+ }
1968
+ else {
1969
+ this.element.nativeElement.appendChild(placeholder);
1970
+ this._activeDraggables.push(item);
1971
+ }
1972
+ // The transform needs to be cleared so it doesn't throw off the measurements.
1973
+ placeholder.style.transform = '';
1974
+ // Note that the positions were already cached when we called `start` above,
1975
+ // but we need to refresh them since the amount of items has changed.
1976
+ this._cachePositions();
1977
+ }
1978
+ /**
1979
+ * Removes an item from the container after it was dragged into another container by the user.
1980
+ * @param {?} item Item that was dragged out.
1981
+ * @return {?}
1982
+ */
1983
+ exit(item) {
1984
+ this._reset();
1985
+ this.exited.next({ item, container: this });
1986
+ }
1987
+ /**
1988
+ * Drops an item into this container.
1989
+ * @param {?} item Item being dropped into the container.
1990
+ * @param {?} currentIndex Index at which the item should be inserted.
1991
+ * @param {?} previousContainer Container from which the item got dragged in.
1992
+ * @param {?} isPointerOverContainer Whether the user's pointer was over the
1993
+ * container when the item was dropped.
1994
+ * @return {?}
1995
+ */
1996
+ drop(item, currentIndex, previousContainer, isPointerOverContainer) {
1997
+ this._reset();
1998
+ this.dropped.next({
1999
+ item,
2000
+ currentIndex,
2001
+ previousIndex: previousContainer.getItemIndex(item),
2002
+ container: this,
2003
+ previousContainer,
2004
+ isPointerOverContainer
2005
+ });
2006
+ }
2007
+ /**
2008
+ * Sets the draggable items that are a part of this list.
2009
+ * @template THIS
2010
+ * @this {THIS}
2011
+ * @param {?} items Items that are a part of this list.
2012
+ * @return {THIS}
2013
+ */
2014
+ withItems(items) {
2015
+ (/** @type {?} */ (this))._draggables = items.slice();
2016
+ return (/** @type {?} */ (this));
2017
+ }
2018
+ /**
2019
+ * Sets the containers that are connected to this one. When two or more containers are
2020
+ * connected, the user will be allowed to transfer items between them.
2021
+ * @template THIS
2022
+ * @this {THIS}
2023
+ * @param {?} connectedTo Other containers that the current containers should be connected to.
2024
+ * @return {THIS}
2025
+ */
2026
+ connectedTo(connectedTo) {
2027
+ (/** @type {?} */ (this))._siblings = connectedTo.slice();
2028
+ return (/** @type {?} */ (this));
2029
+ }
2030
+ /**
2031
+ * Sets the orientation of the container.
2032
+ * @template THIS
2033
+ * @this {THIS}
2034
+ * @param {?} orientation New orientation for the container.
2035
+ * @return {THIS}
2036
+ */
2037
+ withOrientation(orientation) {
2038
+ (/** @type {?} */ (this))._orientation = orientation;
2039
+ return (/** @type {?} */ (this));
2040
+ }
2041
+ /**
2042
+ * Figures out the index of an item in the container.
2043
+ * @param {?} item Item whose index should be determined.
2044
+ * @return {?}
2045
+ */
2046
+ getItemIndex(item) {
2047
+ if (!this._isDragging) {
2048
+ return this._draggables.indexOf(item);
2049
+ }
2050
+ // Items are sorted always by top/left in the cache, however they flow differently in RTL.
2051
+ // The rest of the logic still stands no matter what orientation we're in, however
2052
+ // we need to invert the array when determining the index.
2053
+ /** @type {?} */
2054
+ const items = this._orientation === 'horizontal' && this._dir && this._dir.value === 'rtl' ?
2055
+ this._positionCache.items.slice().reverse() : this._positionCache.items;
2056
+ return findIndex(items, currentItem => currentItem.drag === item);
2057
+ }
2058
+ /**
2059
+ * Whether the list is able to receive the item that
2060
+ * is currently being dragged inside a connected drop list.
2061
+ * @return {?}
2062
+ */
2063
+ isReceiving() {
2064
+ return this._activeSiblings > 0;
2065
+ }
2066
+ /**
2067
+ * Sorts an item inside the container based on its position.
2068
+ * @param {?} item Item to be sorted.
2069
+ * @param {?} pointerX Position of the item along the X axis.
2070
+ * @param {?} pointerY Position of the item along the Y axis.
2071
+ * @param {?} pointerDelta Direction in which the pointer is moving along each axis.
2072
+ * @return {?}
2073
+ */
2074
+ _sortItem(item, pointerX, pointerY, pointerDelta) {
2075
+ // Don't sort the item if it's out of range.
2076
+ if (!this._isPointerNearDropContainer(pointerX, pointerY)) {
2077
+ return;
2078
+ }
2079
+ /** @type {?} */
2080
+ const siblings = this._positionCache.items;
2081
+ /** @type {?} */
2082
+ const newIndex = this._getItemIndexFromPointerPosition(item, pointerX, pointerY, pointerDelta);
2083
+ if (newIndex === -1 && siblings.length > 0) {
2084
+ return;
2085
+ }
2086
+ /** @type {?} */
2087
+ const isHorizontal = this._orientation === 'horizontal';
2088
+ /** @type {?} */
2089
+ const currentIndex = findIndex(siblings, currentItem => currentItem.drag === item);
2090
+ /** @type {?} */
2091
+ const siblingAtNewPosition = siblings[newIndex];
1632
2092
  /** @type {?} */
1633
2093
  const currentPosition = siblings[currentIndex].clientRect;
1634
2094
  /** @type {?} */
1635
2095
  const newPosition = siblingAtNewPosition.clientRect;
1636
2096
  /** @type {?} */
1637
- const delta = currentIndex > newIndex ? 1 : -1;
1638
- this._previousSwap.drag = siblingAtNewPosition.drag;
1639
- this._previousSwap.delta = isHorizontal ? pointerDelta.x : pointerDelta.y;
1640
- // How many pixels the item's placeholder should be offset.
2097
+ const delta = currentIndex > newIndex ? 1 : -1;
2098
+ this._previousSwap.drag = siblingAtNewPosition.drag;
2099
+ this._previousSwap.delta = isHorizontal ? pointerDelta.x : pointerDelta.y;
2100
+ // How many pixels the item's placeholder should be offset.
2101
+ /** @type {?} */
2102
+ const itemOffset = this._getItemOffsetPx(currentPosition, newPosition, delta);
2103
+ // How many pixels all the other items should be offset.
2104
+ /** @type {?} */
2105
+ const siblingOffset = this._getSiblingOffsetPx(currentIndex, siblings, delta);
2106
+ // Save the previous order of the items before moving the item to its new index.
2107
+ // We use this to check whether an item has been moved as a result of the sorting.
2108
+ /** @type {?} */
2109
+ const oldOrder = siblings.slice();
2110
+ // Shuffle the array in place.
2111
+ moveItemInArray(siblings, currentIndex, newIndex);
2112
+ this.sorted.next({
2113
+ previousIndex: currentIndex,
2114
+ currentIndex: newIndex,
2115
+ container: this,
2116
+ item
2117
+ });
2118
+ siblings.forEach((sibling, index) => {
2119
+ // Don't do anything if the position hasn't changed.
2120
+ if (oldOrder[index] === sibling) {
2121
+ return;
2122
+ }
2123
+ /** @type {?} */
2124
+ const isDraggedItem = sibling.drag === item;
2125
+ /** @type {?} */
2126
+ const offset = isDraggedItem ? itemOffset : siblingOffset;
2127
+ /** @type {?} */
2128
+ const elementToOffset = isDraggedItem ? item.getPlaceholderElement() :
2129
+ sibling.drag.getRootElement();
2130
+ // Update the offset to reflect the new position.
2131
+ sibling.offset += offset;
2132
+ // Since we're moving the items with a `transform`, we need to adjust their cached
2133
+ // client rects to reflect their new position, as well as swap their positions in the cache.
2134
+ // Note that we shouldn't use `getBoundingClientRect` here to update the cache, because the
2135
+ // elements may be mid-animation which will give us a wrong result.
2136
+ if (isHorizontal) {
2137
+ // Round the transforms since some browsers will
2138
+ // blur the elements, for sub-pixel transforms.
2139
+ elementToOffset.style.transform = `translate3d(${Math.round(sibling.offset)}px, 0, 0)`;
2140
+ adjustClientRect(sibling.clientRect, 0, offset);
2141
+ }
2142
+ else {
2143
+ elementToOffset.style.transform = `translate3d(0, ${Math.round(sibling.offset)}px, 0)`;
2144
+ adjustClientRect(sibling.clientRect, offset, 0);
2145
+ }
2146
+ });
2147
+ }
2148
+ /**
2149
+ * Refreshes the position cache of the items and sibling containers.
2150
+ * @private
2151
+ * @return {?}
2152
+ */
2153
+ _cachePositions() {
2154
+ /** @type {?} */
2155
+ const isHorizontal = this._orientation === 'horizontal';
2156
+ this._positionCache.self = this.element.nativeElement.getBoundingClientRect();
2157
+ this._positionCache.items = this._activeDraggables
2158
+ .map(drag => {
2159
+ /** @type {?} */
2160
+ const elementToMeasure = this._dragDropRegistry.isDragging(drag) ?
2161
+ // If the element is being dragged, we have to measure the
2162
+ // placeholder, because the element is hidden.
2163
+ drag.getPlaceholderElement() :
2164
+ drag.getRootElement();
2165
+ /** @type {?} */
2166
+ const clientRect = elementToMeasure.getBoundingClientRect();
2167
+ return {
2168
+ drag,
2169
+ offset: 0,
2170
+ // We need to clone the `clientRect` here, because all the values on it are readonly
2171
+ // and we need to be able to update them. Also we can't use a spread here, because
2172
+ // the values on a `ClientRect` aren't own properties. See:
2173
+ // https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect#Notes
2174
+ clientRect: {
2175
+ top: clientRect.top,
2176
+ right: clientRect.right,
2177
+ bottom: clientRect.bottom,
2178
+ left: clientRect.left,
2179
+ width: clientRect.width,
2180
+ height: clientRect.height
2181
+ }
2182
+ };
2183
+ })
2184
+ .sort((a, b) => {
2185
+ return isHorizontal ? a.clientRect.left - b.clientRect.left :
2186
+ a.clientRect.top - b.clientRect.top;
2187
+ });
2188
+ this._positionCache.siblings = this._siblings.map(drop => ({
2189
+ drop,
2190
+ clientRect: drop.element.nativeElement.getBoundingClientRect()
2191
+ }));
2192
+ }
2193
+ /**
2194
+ * Toggles whether the list can receive the item that is currently being dragged.
2195
+ * Usually called by a sibling that initiated the dragging.
2196
+ * @param {?} isDragging
2197
+ * @return {?}
2198
+ */
2199
+ _toggleIsReceiving(isDragging) {
2200
+ this._activeSiblings = Math.max(0, this._activeSiblings + (isDragging ? 1 : -1));
2201
+ }
2202
+ /**
2203
+ * Resets the container to its initial state.
2204
+ * @private
2205
+ * @return {?}
2206
+ */
2207
+ _reset() {
2208
+ this._isDragging = false;
2209
+ // TODO(crisbeto): may have to wait for the animations to finish.
2210
+ this._activeDraggables.forEach(item => item.getRootElement().style.transform = '');
2211
+ this._positionCache.siblings.forEach(sibling => sibling.drop._toggleIsReceiving(false));
2212
+ this._activeDraggables = [];
2213
+ this._positionCache.items = [];
2214
+ this._positionCache.siblings = [];
2215
+ this._previousSwap.drag = null;
2216
+ this._previousSwap.delta = 0;
2217
+ }
2218
+ /**
2219
+ * Gets the offset in pixels by which the items that aren't being dragged should be moved.
2220
+ * @private
2221
+ * @param {?} currentIndex Index of the item currently being dragged.
2222
+ * @param {?} siblings All of the items in the list.
2223
+ * @param {?} delta Direction in which the user is moving.
2224
+ * @return {?}
2225
+ */
2226
+ _getSiblingOffsetPx(currentIndex, siblings, delta) {
2227
+ /** @type {?} */
2228
+ const isHorizontal = this._orientation === 'horizontal';
1641
2229
  /** @type {?} */
1642
- const itemOffset = this._getItemOffsetPx(currentPosition, newPosition, delta);
1643
- // How many pixels all the other items should be offset.
2230
+ const currentPosition = siblings[currentIndex].clientRect;
1644
2231
  /** @type {?} */
1645
- const siblingOffset = this._getSiblingOffsetPx(currentIndex, siblings, delta);
1646
- // Save the previous order of the items before moving the item to its new index.
1647
- // We use this to check whether an item has been moved as a result of the sorting.
2232
+ const immediateSibling = siblings[currentIndex + delta * -1];
1648
2233
  /** @type {?} */
1649
- const oldOrder = siblings.slice();
1650
- // Shuffle the array in place.
1651
- moveItemInArray(siblings, currentIndex, newIndex);
1652
- this.sorted.emit({
1653
- previousIndex: currentIndex,
1654
- currentIndex: newIndex,
1655
- container: this,
1656
- item
1657
- });
1658
- siblings.forEach((sibling, index) => {
1659
- // Don't do anything if the position hasn't changed.
1660
- if (oldOrder[index] === sibling) {
1661
- return;
1662
- }
1663
- /** @type {?} */
1664
- const isDraggedItem = sibling.drag === item;
2234
+ let siblingOffset = currentPosition[isHorizontal ? 'width' : 'height'] * delta;
2235
+ if (immediateSibling) {
1665
2236
  /** @type {?} */
1666
- const offset = isDraggedItem ? itemOffset : siblingOffset;
2237
+ const start = isHorizontal ? 'left' : 'top';
1667
2238
  /** @type {?} */
1668
- const elementToOffset = isDraggedItem ? item.getPlaceholderElement() :
1669
- sibling.drag.getRootElement();
1670
- // Update the offset to reflect the new position.
1671
- sibling.offset += offset;
1672
- // Since we're moving the items with a `transform`, we need to adjust their cached
1673
- // client rects to reflect their new position, as well as swap their positions in the cache.
1674
- // Note that we shouldn't use `getBoundingClientRect` here to update the cache, because the
1675
- // elements may be mid-animation which will give us a wrong result.
1676
- if (isHorizontal) {
1677
- // Round the transforms since some browsers will
1678
- // blur the elements, for sub-pixel transforms.
1679
- elementToOffset.style.transform = `translate3d(${Math.round(sibling.offset)}px, 0, 0)`;
1680
- this._adjustClientRect(sibling.clientRect, 0, offset);
2239
+ const end = isHorizontal ? 'right' : 'bottom';
2240
+ // Get the spacing between the start of the current item and the end of the one immediately
2241
+ // after it in the direction in which the user is dragging, or vice versa. We add it to the
2242
+ // offset in order to push the element to where it will be when it's inline and is influenced
2243
+ // by the `margin` of its siblings.
2244
+ if (delta === -1) {
2245
+ siblingOffset -= immediateSibling.clientRect[start] - currentPosition[end];
1681
2246
  }
1682
2247
  else {
1683
- elementToOffset.style.transform = `translate3d(0, ${Math.round(sibling.offset)}px, 0)`;
1684
- this._adjustClientRect(sibling.clientRect, offset, 0);
2248
+ siblingOffset += currentPosition[start] - immediateSibling.clientRect[end];
2249
+ }
2250
+ }
2251
+ return siblingOffset;
2252
+ }
2253
+ /**
2254
+ * Checks whether the pointer coordinates are close to the drop container.
2255
+ * @private
2256
+ * @param {?} pointerX Coordinates along the X axis.
2257
+ * @param {?} pointerY Coordinates along the Y axis.
2258
+ * @return {?}
2259
+ */
2260
+ _isPointerNearDropContainer(pointerX, pointerY) {
2261
+ const { top, right, bottom, left, width, height } = this._positionCache.self;
2262
+ /** @type {?} */
2263
+ const xThreshold = width * DROP_PROXIMITY_THRESHOLD;
2264
+ /** @type {?} */
2265
+ const yThreshold = height * DROP_PROXIMITY_THRESHOLD;
2266
+ return pointerY > top - yThreshold && pointerY < bottom + yThreshold &&
2267
+ pointerX > left - xThreshold && pointerX < right + xThreshold;
2268
+ }
2269
+ /**
2270
+ * Gets the offset in pixels by which the item that is being dragged should be moved.
2271
+ * @private
2272
+ * @param {?} currentPosition Current position of the item.
2273
+ * @param {?} newPosition Position of the item where the current item should be moved.
2274
+ * @param {?} delta Direction in which the user is moving.
2275
+ * @return {?}
2276
+ */
2277
+ _getItemOffsetPx(currentPosition, newPosition, delta) {
2278
+ /** @type {?} */
2279
+ const isHorizontal = this._orientation === 'horizontal';
2280
+ /** @type {?} */
2281
+ let itemOffset = isHorizontal ? newPosition.left - currentPosition.left :
2282
+ newPosition.top - currentPosition.top;
2283
+ // Account for differences in the item width/height.
2284
+ if (delta === -1) {
2285
+ itemOffset += isHorizontal ? newPosition.width - currentPosition.width :
2286
+ newPosition.height - currentPosition.height;
2287
+ }
2288
+ return itemOffset;
2289
+ }
2290
+ /**
2291
+ * Gets the index of an item in the drop container, based on the position of the user's pointer.
2292
+ * @private
2293
+ * @param {?} item Item that is being sorted.
2294
+ * @param {?} pointerX Position of the user's pointer along the X axis.
2295
+ * @param {?} pointerY Position of the user's pointer along the Y axis.
2296
+ * @param {?=} delta Direction in which the user is moving their pointer.
2297
+ * @return {?}
2298
+ */
2299
+ _getItemIndexFromPointerPosition(item, pointerX, pointerY, delta) {
2300
+ /** @type {?} */
2301
+ const isHorizontal = this._orientation === 'horizontal';
2302
+ return findIndex(this._positionCache.items, ({ drag, clientRect }, _, array) => {
2303
+ if (drag === item) {
2304
+ // If there's only one item left in the container, it must be
2305
+ // the dragged item itself so we use it as a reference.
2306
+ return array.length < 2;
2307
+ }
2308
+ if (delta) {
2309
+ /** @type {?} */
2310
+ const direction = isHorizontal ? delta.x : delta.y;
2311
+ // If the user is still hovering over the same item as last time, and they didn't change
2312
+ // the direction in which they're dragging, we don't consider it a direction swap.
2313
+ if (drag === this._previousSwap.drag && direction === this._previousSwap.delta) {
2314
+ return false;
2315
+ }
1685
2316
  }
2317
+ return isHorizontal ?
2318
+ // Round these down since most browsers report client rects with
2319
+ // sub-pixel precision, whereas the pointer coordinates are rounded to pixels.
2320
+ pointerX >= Math.floor(clientRect.left) && pointerX <= Math.floor(clientRect.right) :
2321
+ pointerY >= Math.floor(clientRect.top) && pointerY <= Math.floor(clientRect.bottom);
2322
+ });
2323
+ }
2324
+ /**
2325
+ * Checks whether the user's pointer is positioned over the container.
2326
+ * @param {?} x Pointer position along the X axis.
2327
+ * @param {?} y Pointer position along the Y axis.
2328
+ * @return {?}
2329
+ */
2330
+ _isOverContainer(x, y) {
2331
+ return isInsideClientRect(this._positionCache.self, x, y);
2332
+ }
2333
+ /**
2334
+ * Figures out whether an item should be moved into a sibling
2335
+ * drop container, based on its current position.
2336
+ * @param {?} item Drag item that is being moved.
2337
+ * @param {?} x Position of the item along the X axis.
2338
+ * @param {?} y Position of the item along the Y axis.
2339
+ * @return {?}
2340
+ */
2341
+ _getSiblingContainerFromPosition(item, x, y) {
2342
+ /** @type {?} */
2343
+ const results = this._positionCache.siblings.filter(sibling => {
2344
+ return isInsideClientRect(sibling.clientRect, x, y);
2345
+ });
2346
+ // No drop containers are intersecting with the pointer.
2347
+ if (!results.length) {
2348
+ return null;
2349
+ }
2350
+ /** @type {?} */
2351
+ const elementFromPoint = this._document.elementFromPoint(x, y);
2352
+ // If there's no element at the pointer position, then
2353
+ // the client rect is probably scrolled out of the view.
2354
+ if (!elementFromPoint) {
2355
+ return null;
2356
+ }
2357
+ // The `ClientRect`, that we're using to find the container over which the user is
2358
+ // hovering, doesn't give us any information on whether the element has been scrolled
2359
+ // out of the view or whether it's overlapping with other containers. This means that
2360
+ // we could end up transferring the item into a container that's invisible or is positioned
2361
+ // below another one. We use the result from `elementFromPoint` to get the top-most element
2362
+ // at the pointer position and to find whether it's one of the intersecting drop containers.
2363
+ /** @type {?} */
2364
+ const result = results.find(sibling => {
2365
+ /** @type {?} */
2366
+ const element = sibling.drop.element.nativeElement;
2367
+ return element === elementFromPoint || element.contains(elementFromPoint);
1686
2368
  });
2369
+ return result && result.drop.enterPredicate(item, result.drop) ? result.drop : null;
2370
+ }
2371
+ }
2372
+ /**
2373
+ * Updates the top/left positions of a `ClientRect`, as well as their bottom/right counterparts.
2374
+ * @param {?} clientRect `ClientRect` that should be updated.
2375
+ * @param {?} top Amount to add to the `top` position.
2376
+ * @param {?} left Amount to add to the `left` position.
2377
+ * @return {?}
2378
+ */
2379
+ function adjustClientRect(clientRect, top, left) {
2380
+ clientRect.top += top;
2381
+ clientRect.bottom = clientRect.top + clientRect.height;
2382
+ clientRect.left += left;
2383
+ clientRect.right = clientRect.left + clientRect.width;
2384
+ }
2385
+ /**
2386
+ * Finds the index of an item that matches a predicate function. Used as an equivalent
2387
+ * of `Array.prototype.find` which isn't part of the standard Google typings.
2388
+ * @template T
2389
+ * @param {?} array Array in which to look for matches.
2390
+ * @param {?} predicate Function used to determine whether an item is a match.
2391
+ * @return {?}
2392
+ */
2393
+ function findIndex(array, predicate) {
2394
+ for (let i = 0; i < array.length; i++) {
2395
+ if (predicate(array[i], i, array)) {
2396
+ return i;
2397
+ }
2398
+ }
2399
+ return -1;
2400
+ }
2401
+ /**
2402
+ * Checks whether some coordinates are within a `ClientRect`.
2403
+ * @param {?} clientRect ClientRect that is being checked.
2404
+ * @param {?} x Coordinates along the X axis.
2405
+ * @param {?} y Coordinates along the Y axis.
2406
+ * @return {?}
2407
+ */
2408
+ function isInsideClientRect(clientRect, x, y) {
2409
+ const { top, bottom, left, right } = clientRect;
2410
+ return y >= top && y <= bottom && x >= left && x <= right;
2411
+ }
2412
+
2413
+ /**
2414
+ * @fileoverview added by tsickle
2415
+ * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
2416
+ */
2417
+ /**
2418
+ * Counter used to generate unique ids for drop zones.
2419
+ * @type {?}
2420
+ */
2421
+ let _uniqueIdCounter$1 = 0;
2422
+ const ɵ0 = undefined;
2423
+ // @breaking-change 8.0.0 `CdkDropList` implements `CdkDropListContainer` for backwards
2424
+ // compatiblity. The implements clause, as well as all the methods that it enforces can
2425
+ // be removed when `CdkDropListContainer` is deleted.
2426
+ /**
2427
+ * Container that wraps a set of draggable items.
2428
+ * @template T
2429
+ */
2430
+ class CdkDropList {
2431
+ /**
2432
+ * @param {?} element
2433
+ * @param {?} dragDropRegistry
2434
+ * @param {?} _changeDetectorRef
2435
+ * @param {?=} dir
2436
+ * @param {?=} _group
2437
+ * @param {?=} _document
2438
+ */
2439
+ constructor(element, dragDropRegistry, _changeDetectorRef, dir, _group,
2440
+ // @breaking-change 8.0.0 `_document` parameter to be made required.
2441
+ _document) {
2442
+ this.element = element;
2443
+ this._changeDetectorRef = _changeDetectorRef;
2444
+ this._group = _group;
2445
+ /**
2446
+ * Other draggable containers that this container is connected to and into which the
2447
+ * container's items can be transferred. Can either be references to other drop containers,
2448
+ * or their unique IDs.
2449
+ */
2450
+ this.connectedTo = [];
2451
+ /**
2452
+ * Direction in which the list is oriented.
2453
+ */
2454
+ this.orientation = 'vertical';
2455
+ /**
2456
+ * Unique ID for the drop zone. Can be used as a reference
2457
+ * in the `connectedTo` of another `CdkDropList`.
2458
+ */
2459
+ this.id = `cdk-drop-list-${_uniqueIdCounter$1++}`;
2460
+ this._disabled = false;
2461
+ /**
2462
+ * Function that is used to determine whether an item
2463
+ * is allowed to be moved into a drop container.
2464
+ */
2465
+ this.enterPredicate = () => true;
2466
+ /**
2467
+ * Emits when the user drops an item inside the container.
2468
+ */
2469
+ this.dropped = new EventEmitter();
2470
+ /**
2471
+ * Emits when the user has moved a new drag item into this container.
2472
+ */
2473
+ this.entered = new EventEmitter();
2474
+ /**
2475
+ * Emits when the user removes an item from the container
2476
+ * by dragging it into another container.
2477
+ */
2478
+ this.exited = new EventEmitter();
2479
+ /**
2480
+ * Emits as the user is swapping items while actively dragging.
2481
+ */
2482
+ this.sorted = new EventEmitter();
2483
+ // @breaking-change 8.0.0 Remove || once `_document` parameter is required.
2484
+ /** @type {?} */
2485
+ const ref = this._dropListRef = new DropListRef(element, dragDropRegistry, _document || document, dir);
2486
+ ref.data = this;
2487
+ ref.enterPredicate = (drag, drop) => {
2488
+ return this.enterPredicate(drag.data, drop.data);
2489
+ };
2490
+ this._syncInputs(ref);
2491
+ this._proxyEvents(ref);
2492
+ CdkDropList._dropLists.push(this);
2493
+ if (_group) {
2494
+ _group._items.add(this);
2495
+ }
1687
2496
  }
1688
2497
  /**
1689
- * Figures out whether an item should be moved into a sibling
1690
- * drop container, based on its current position.
1691
- * @param {?} item Drag item that is being moved.
1692
- * @param {?} x Position of the item along the X axis.
1693
- * @param {?} y Position of the item along the Y axis.
2498
+ * Whether starting a dragging sequence from this container is disabled.
1694
2499
  * @return {?}
1695
2500
  */
1696
- _getSiblingContainerFromPosition(item, x, y) {
1697
- /** @type {?} */
1698
- const result = this._positionCache.siblings
1699
- .find(sibling => isInsideClientRect(sibling.clientRect, x, y));
1700
- return result && result.drop.enterPredicate(item, result.drop) ? result.drop : null;
2501
+ get disabled() {
2502
+ return this._disabled || (!!this._group && this._group.disabled);
1701
2503
  }
1702
2504
  /**
1703
- * Checks whether an item that started in this container can be returned to it,
1704
- * after it was moved out into another container.
1705
- * @param {?} x Position of the item along the X axis.
1706
- * @param {?} y Position of the item along the Y axis.
2505
+ * @param {?} value
1707
2506
  * @return {?}
1708
2507
  */
1709
- _canReturnItem(x, y) {
1710
- return isInsideClientRect(this._positionCache.self, x, y);
2508
+ set disabled(value) {
2509
+ this._disabled = coerceBooleanProperty(value);
1711
2510
  }
1712
2511
  /**
1713
- * Refreshes the position cache of the items and sibling containers.
1714
- * @private
1715
2512
  * @return {?}
1716
2513
  */
1717
- _cachePositions() {
2514
+ ngOnDestroy() {
1718
2515
  /** @type {?} */
1719
- const isHorizontal = this.orientation === 'horizontal';
1720
- this._positionCache.self = this.element.nativeElement.getBoundingClientRect();
1721
- this._positionCache.items = this._activeDraggables
1722
- .map(drag => {
1723
- /** @type {?} */
1724
- const elementToMeasure = this._dragDropRegistry.isDragging(drag) ?
1725
- // If the element is being dragged, we have to measure the
1726
- // placeholder, because the element is hidden.
1727
- drag.getPlaceholderElement() :
1728
- drag.getRootElement();
1729
- /** @type {?} */
1730
- const clientRect = elementToMeasure.getBoundingClientRect();
1731
- return {
1732
- drag,
1733
- offset: 0,
1734
- // We need to clone the `clientRect` here, because all the values on it are readonly
1735
- // and we need to be able to update them. Also we can't use a spread here, because
1736
- // the values on a `ClientRect` aren't own properties. See:
1737
- // https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect#Notes
1738
- clientRect: {
1739
- top: clientRect.top,
1740
- right: clientRect.right,
1741
- bottom: clientRect.bottom,
1742
- left: clientRect.left,
1743
- width: clientRect.width,
1744
- height: clientRect.height
1745
- }
1746
- };
1747
- })
1748
- .sort((a, b) => {
1749
- return isHorizontal ? a.clientRect.left - b.clientRect.left :
1750
- a.clientRect.top - b.clientRect.top;
1751
- });
1752
- this._positionCache.siblings = this._getConnectedLists().map(drop => ({
1753
- drop,
1754
- clientRect: drop.element.nativeElement.getBoundingClientRect()
1755
- }));
2516
+ const index = CdkDropList._dropLists.indexOf(this);
2517
+ this._dropListRef.dispose();
2518
+ if (index > -1) {
2519
+ CdkDropList._dropLists.splice(index, 1);
2520
+ }
2521
+ if (this._group) {
2522
+ this._group._items.delete(this);
2523
+ }
1756
2524
  }
1757
2525
  /**
1758
- * Resets the container to its initial state.
1759
- * @private
2526
+ * Starts dragging an item.
1760
2527
  * @return {?}
1761
2528
  */
1762
- _reset() {
1763
- this._dragging = false;
1764
- // TODO(crisbeto): may have to wait for the animations to finish.
1765
- this._activeDraggables.forEach(item => item.getRootElement().style.transform = '');
1766
- this._activeDraggables = [];
1767
- this._positionCache.items = [];
1768
- this._positionCache.siblings = [];
1769
- this._previousSwap.drag = null;
1770
- this._previousSwap.delta = 0;
2529
+ start() {
2530
+ this._dropListRef.start();
1771
2531
  }
1772
2532
  /**
1773
- * Updates the top/left positions of a `ClientRect`, as well as their bottom/right counterparts.
1774
- * @private
1775
- * @param {?} clientRect `ClientRect` that should be updated.
1776
- * @param {?} top Amount to add to the `top` position.
1777
- * @param {?} left Amount to add to the `left` position.
2533
+ * Drops an item into this container.
2534
+ * @param {?} item Item being dropped into the container.
2535
+ * @param {?} currentIndex Index at which the item should be inserted.
2536
+ * @param {?} previousContainer Container from which the item got dragged in.
2537
+ * @param {?} isPointerOverContainer Whether the user's pointer was over the
2538
+ * container when the item was dropped.
1778
2539
  * @return {?}
1779
2540
  */
1780
- _adjustClientRect(clientRect, top, left) {
1781
- clientRect.top += top;
1782
- clientRect.bottom = clientRect.top + clientRect.height;
1783
- clientRect.left += left;
1784
- clientRect.right = clientRect.left + clientRect.width;
2541
+ drop(item, currentIndex, previousContainer, isPointerOverContainer) {
2542
+ this._dropListRef.drop(item._dragRef, currentIndex, ((/** @type {?} */ (previousContainer)))._dropListRef, isPointerOverContainer);
1785
2543
  }
1786
2544
  /**
1787
- * Gets the index of an item in the drop container, based on the position of the user's pointer.
1788
- * @private
1789
- * @param {?} item Item that is being sorted.
1790
- * @param {?} pointerX Position of the user's pointer along the X axis.
1791
- * @param {?} pointerY Position of the user's pointer along the Y axis.
1792
- * @param {?=} delta Direction in which the user is moving their pointer.
2545
+ * Emits an event to indicate that the user moved an item into the container.
2546
+ * @param {?} item Item that was moved into the container.
2547
+ * @param {?} pointerX Position of the item along the X axis.
2548
+ * @param {?} pointerY Position of the item along the Y axis.
1793
2549
  * @return {?}
1794
2550
  */
1795
- _getItemIndexFromPointerPosition(item, pointerX, pointerY, delta) {
1796
- /** @type {?} */
1797
- const isHorizontal = this.orientation === 'horizontal';
1798
- return findIndex(this._positionCache.items, ({ drag, clientRect }, _, array) => {
1799
- if (drag === item) {
1800
- // If there's only one item left in the container, it must be
1801
- // the dragged item itself so we use it as a reference.
1802
- return array.length < 2;
1803
- }
1804
- if (delta) {
1805
- /** @type {?} */
1806
- const direction = isHorizontal ? delta.x : delta.y;
1807
- // If the user is still hovering over the same item as last time, and they didn't change
1808
- // the direction in which they're dragging, we don't consider it a direction swap.
1809
- if (drag === this._previousSwap.drag && direction === this._previousSwap.delta) {
1810
- return false;
1811
- }
1812
- }
1813
- return isHorizontal ?
1814
- // Round these down since most browsers report client rects with
1815
- // sub-pixel precision, whereas the pointer coordinates are rounded to pixels.
1816
- pointerX >= Math.floor(clientRect.left) && pointerX <= Math.floor(clientRect.right) :
1817
- pointerY >= Math.floor(clientRect.top) && pointerY <= Math.floor(clientRect.bottom);
1818
- });
2551
+ enter(item, pointerX, pointerY) {
2552
+ this._dropListRef.enter(item._dragRef, pointerX, pointerY);
1819
2553
  }
1820
2554
  /**
1821
- * Checks whether the pointer coordinates are close to the drop container.
1822
- * @private
1823
- * @param {?} pointerX Coordinates along the X axis.
1824
- * @param {?} pointerY Coordinates along the Y axis.
2555
+ * Removes an item from the container after it was dragged into another container by the user.
2556
+ * @param {?} item Item that was dragged out.
1825
2557
  * @return {?}
1826
2558
  */
1827
- _isPointerNearDropContainer(pointerX, pointerY) {
1828
- const { top, right, bottom, left, width, height } = this._positionCache.self;
1829
- /** @type {?} */
1830
- const xThreshold = width * DROP_PROXIMITY_THRESHOLD;
1831
- /** @type {?} */
1832
- const yThreshold = height * DROP_PROXIMITY_THRESHOLD;
1833
- return pointerY > top - yThreshold && pointerY < bottom + yThreshold &&
1834
- pointerX > left - xThreshold && pointerX < right + xThreshold;
2559
+ exit(item) {
2560
+ this._dropListRef.exit(item._dragRef);
1835
2561
  }
1836
2562
  /**
1837
- * Gets the offset in pixels by which the item that is being dragged should be moved.
1838
- * @private
1839
- * @param {?} currentPosition Current position of the item.
1840
- * @param {?} newPosition Position of the item where the current item should be moved.
1841
- * @param {?} delta Direction in which the user is moving.
2563
+ * Figures out the index of an item in the container.
2564
+ * @param {?} item Item whose index should be determined.
1842
2565
  * @return {?}
1843
2566
  */
1844
- _getItemOffsetPx(currentPosition, newPosition, delta) {
1845
- /** @type {?} */
1846
- const isHorizontal = this.orientation === 'horizontal';
2567
+ getItemIndex(item) {
2568
+ return this._dropListRef.getItemIndex(item._dragRef);
2569
+ }
2570
+ /**
2571
+ * Sorts an item inside the container based on its position.
2572
+ * @param {?} item Item to be sorted.
2573
+ * @param {?} pointerX Position of the item along the X axis.
2574
+ * @param {?} pointerY Position of the item along the Y axis.
2575
+ * @param {?} pointerDelta Direction in which the pointer is moving along each axis.
2576
+ * @return {?}
2577
+ */
2578
+ _sortItem(item, pointerX, pointerY, pointerDelta) {
2579
+ return this._dropListRef._sortItem(item._dragRef, pointerX, pointerY, pointerDelta);
2580
+ }
2581
+ /**
2582
+ * Figures out whether an item should be moved into a sibling
2583
+ * drop container, based on its current position.
2584
+ * @param {?} item Drag item that is being moved.
2585
+ * @param {?} x Position of the item along the X axis.
2586
+ * @param {?} y Position of the item along the Y axis.
2587
+ * @return {?}
2588
+ */
2589
+ _getSiblingContainerFromPosition(item, x, y) {
1847
2590
  /** @type {?} */
1848
- let itemOffset = isHorizontal ? newPosition.left - currentPosition.left :
1849
- newPosition.top - currentPosition.top;
1850
- // Account for differences in the item width/height.
1851
- if (delta === -1) {
1852
- itemOffset += isHorizontal ? newPosition.width - currentPosition.width :
1853
- newPosition.height - currentPosition.height;
1854
- }
1855
- return itemOffset;
2591
+ const result = this._dropListRef._getSiblingContainerFromPosition(item._dragRef, x, y);
2592
+ return result ? result.data : null;
1856
2593
  }
1857
2594
  /**
1858
- * Gets the offset in pixels by which the items that aren't being dragged should be moved.
2595
+ * Checks whether the user's pointer is positioned over the container.
2596
+ * @param {?} x Pointer position along the X axis.
2597
+ * @param {?} y Pointer position along the Y axis.
2598
+ * @return {?}
2599
+ */
2600
+ _isOverContainer(x, y) {
2601
+ return this._dropListRef._isOverContainer(x, y);
2602
+ }
2603
+ /**
2604
+ * Syncs the inputs of the CdkDropList with the options of the underlying DropListRef.
1859
2605
  * @private
1860
- * @param {?} currentIndex Index of the item currently being dragged.
1861
- * @param {?} siblings All of the items in the list.
1862
- * @param {?} delta Direction in which the user is moving.
2606
+ * @param {?} ref
1863
2607
  * @return {?}
1864
2608
  */
1865
- _getSiblingOffsetPx(currentIndex, siblings, delta) {
1866
- /** @type {?} */
1867
- const isHorizontal = this.orientation === 'horizontal';
1868
- /** @type {?} */
1869
- const currentPosition = siblings[currentIndex].clientRect;
1870
- /** @type {?} */
1871
- const immediateSibling = siblings[currentIndex + delta * -1];
1872
- /** @type {?} */
1873
- let siblingOffset = currentPosition[isHorizontal ? 'width' : 'height'] * delta;
1874
- if (immediateSibling) {
2609
+ _syncInputs(ref) {
2610
+ ref.beforeStarted.subscribe(() => {
1875
2611
  /** @type {?} */
1876
- const start = isHorizontal ? 'left' : 'top';
1877
- /** @type {?} */
1878
- const end = isHorizontal ? 'right' : 'bottom';
1879
- // Get the spacing between the start of the current item and the end of the one immediately
1880
- // after it in the direction in which the user is dragging, or vice versa. We add it to the
1881
- // offset in order to push the element to where it will be when it's inline and is influenced
1882
- // by the `margin` of its siblings.
1883
- if (delta === -1) {
1884
- siblingOffset -= immediateSibling.clientRect[start] - currentPosition[end];
1885
- }
1886
- else {
1887
- siblingOffset += currentPosition[start] - immediateSibling.clientRect[end];
2612
+ const siblings = coerceArray(this.connectedTo).map(drop => {
2613
+ return typeof drop === 'string' ?
2614
+ (/** @type {?} */ (CdkDropList._dropLists.find(list => list.id === drop))) : drop;
2615
+ });
2616
+ if (this._group) {
2617
+ this._group._items.forEach(drop => {
2618
+ if (siblings.indexOf(drop) === -1) {
2619
+ siblings.push(drop);
2620
+ }
2621
+ });
1888
2622
  }
1889
- }
1890
- return siblingOffset;
2623
+ ref.lockAxis = this.lockAxis;
2624
+ ref
2625
+ .connectedTo(siblings.filter(drop => drop && drop !== this).map(list => list._dropListRef))
2626
+ .withOrientation(this.orientation)
2627
+ .withItems(this._draggables.map(drag => drag._dragRef));
2628
+ });
1891
2629
  }
1892
2630
  /**
1893
- * Gets an array of unique drop lists that the current list is connected to.
2631
+ * Proxies the events from a DropListRef to events that
2632
+ * match the interfaces of the CdkDropList outputs.
1894
2633
  * @private
2634
+ * @param {?} ref
1895
2635
  * @return {?}
1896
2636
  */
1897
- _getConnectedLists() {
1898
- /** @type {?} */
1899
- const siblings = coerceArray(this.connectedTo).map(drop => {
1900
- return typeof drop === 'string' ? (/** @type {?} */ (this._dragDropRegistry.getDropContainer(drop))) : drop;
2637
+ _proxyEvents(ref) {
2638
+ ref.beforeStarted.subscribe(() => {
2639
+ this._changeDetectorRef.markForCheck();
1901
2640
  });
1902
- if (this._group) {
1903
- this._group._items.forEach(drop => {
1904
- if (siblings.indexOf(drop) === -1) {
1905
- siblings.push(drop);
1906
- }
2641
+ ref.entered.subscribe(event => {
2642
+ this.entered.emit({
2643
+ container: this,
2644
+ item: event.item.data
1907
2645
  });
1908
- }
1909
- return siblings.filter(drop => drop && drop !== this);
2646
+ });
2647
+ ref.exited.subscribe(event => {
2648
+ this.exited.emit({
2649
+ container: this,
2650
+ item: event.item.data
2651
+ });
2652
+ });
2653
+ ref.sorted.subscribe(event => {
2654
+ this.sorted.emit({
2655
+ previousIndex: event.previousIndex,
2656
+ currentIndex: event.currentIndex,
2657
+ container: this,
2658
+ item: event.item.data
2659
+ });
2660
+ });
2661
+ ref.dropped.subscribe(event => {
2662
+ this.dropped.emit({
2663
+ previousIndex: event.previousIndex,
2664
+ currentIndex: event.currentIndex,
2665
+ previousContainer: event.previousContainer.data,
2666
+ container: event.container.data,
2667
+ item: event.item.data,
2668
+ isPointerOverContainer: event.isPointerOverContainer
2669
+ });
2670
+ });
1910
2671
  }
1911
2672
  }
2673
+ /**
2674
+ * Keeps track of the drop lists that are currently on the page.
2675
+ */
2676
+ CdkDropList._dropLists = [];
1912
2677
  CdkDropList.decorators = [
1913
2678
  { type: Directive, args: [{
1914
2679
  selector: '[cdkDropList], cdk-drop-list',
@@ -1921,7 +2686,8 @@ CdkDropList.decorators = [
1921
2686
  host: {
1922
2687
  'class': 'cdk-drop-list',
1923
2688
  '[id]': 'id',
1924
- '[class.cdk-drop-list-dragging]': '_dragging'
2689
+ '[class.cdk-drop-list-dragging]': '_dropListRef.isDragging()',
2690
+ '[class.cdk-drop-list-receiving]': '_dropListRef.isReceiving()',
1925
2691
  }
1926
2692
  },] },
1927
2693
  ];
@@ -1931,7 +2697,8 @@ CdkDropList.ctorParameters = () => [
1931
2697
  { type: DragDropRegistry },
1932
2698
  { type: ChangeDetectorRef },
1933
2699
  { type: Directionality, decorators: [{ type: Optional }] },
1934
- { type: CdkDropListGroup, decorators: [{ type: Optional }, { type: SkipSelf }] }
2700
+ { type: CdkDropListGroup, decorators: [{ type: Optional }, { type: SkipSelf }] },
2701
+ { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [DOCUMENT,] }] }
1935
2702
  ];
1936
2703
  CdkDropList.propDecorators = {
1937
2704
  _draggables: [{ type: ContentChildren, args: [forwardRef(() => CdkDrag),] }],
@@ -1947,38 +2714,6 @@ CdkDropList.propDecorators = {
1947
2714
  exited: [{ type: Output, args: ['cdkDropListExited',] }],
1948
2715
  sorted: [{ type: Output, args: ['cdkDropListSorted',] }]
1949
2716
  };
1950
- /**
1951
- * Finds the index of an item that matches a predicate function. Used as an equivalent
1952
- * of `Array.prototype.find` which isn't part of the standard Google typings.
1953
- * @template T
1954
- * @param {?} array Array in which to look for matches.
1955
- * @param {?} predicate Function used to determine whether an item is a match.
1956
- * @return {?}
1957
- */
1958
- function findIndex(array, predicate) {
1959
- for (let i = 0; i < array.length; i++) {
1960
- if (predicate(array[i], i, array)) {
1961
- return i;
1962
- }
1963
- }
1964
- return -1;
1965
- }
1966
- /**
1967
- * Checks whether some coordinates are within a `ClientRect`.
1968
- * @param {?} clientRect ClientRect that is being checked.
1969
- * @param {?} x Coordinates along the X axis.
1970
- * @param {?} y Coordinates along the Y axis.
1971
- * @return {?}
1972
- */
1973
- function isInsideClientRect(clientRect, x, y) {
1974
- const { top, bottom, left, right } = clientRect;
1975
- return y >= top && y <= bottom && x >= left && x <= right;
1976
- }
1977
-
1978
- /**
1979
- * @fileoverview added by tsickle
1980
- * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
1981
- */
1982
2717
 
1983
2718
  /**
1984
2719
  * @fileoverview added by tsickle
@@ -2017,5 +2752,5 @@ DragDropModule.decorators = [
2017
2752
  * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
2018
2753
  */
2019
2754
 
2020
- export { CdkDropList, CdkDropListGroup, CDK_DROP_LIST_CONTAINER, CDK_DRAG_CONFIG_FACTORY, CDK_DRAG_CONFIG, CdkDrag, CdkDragHandle, moveItemInArray, transferArrayItem, copyArrayItem, CdkDragPreview, CdkDragPlaceholder, DragDropModule, DragDropRegistry, CDK_DRAG_PARENT as ɵa };
2755
+ export { CDK_DROP_LIST, CDK_DROP_LIST_CONTAINER, moveItemInArray, transferArrayItem, copyArrayItem, DragDropModule, DragDropRegistry, CdkDropList, CdkDropListGroup, CDK_DRAG_CONFIG_FACTORY, CDK_DRAG_CONFIG, CdkDrag, CdkDragHandle, CdkDragPreview, CdkDragPlaceholder, CDK_DRAG_PARENT as ɵa };
2021
2756
  //# sourceMappingURL=drag-drop.js.map