@angular/cdk 7.0.3 → 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 (252) hide show
  1. package/a11y/typings/focus-monitor/focus-monitor.d.ts +20 -4
  2. package/a11y/typings/index.metadata.json +1 -1
  3. package/a11y/typings/key-manager/list-key-manager.d.ts +8 -0
  4. package/a11y/typings/live-announcer/live-announcer.d.ts +37 -4
  5. package/bidi/typings/dir.d.ts +4 -1
  6. package/bidi/typings/index.metadata.json +1 -1
  7. package/bundles/cdk-a11y.umd.js +503 -210
  8. package/bundles/cdk-a11y.umd.js.map +1 -1
  9. package/bundles/cdk-a11y.umd.min.js +1 -1
  10. package/bundles/cdk-a11y.umd.min.js.map +1 -1
  11. package/bundles/cdk-accordion.umd.js +16 -9
  12. package/bundles/cdk-accordion.umd.js.map +1 -1
  13. package/bundles/cdk-accordion.umd.min.js.map +1 -1
  14. package/bundles/cdk-bidi.umd.js +16 -7
  15. package/bundles/cdk-bidi.umd.js.map +1 -1
  16. package/bundles/cdk-bidi.umd.min.js +1 -1
  17. package/bundles/cdk-bidi.umd.min.js.map +1 -1
  18. package/bundles/cdk-coercion.umd.js +5 -5
  19. package/bundles/cdk-coercion.umd.js.map +1 -1
  20. package/bundles/cdk-collections.umd.js +28 -5
  21. package/bundles/cdk-collections.umd.js.map +1 -1
  22. package/bundles/cdk-collections.umd.min.js.map +1 -1
  23. package/bundles/cdk-drag-drop.umd.js +2251 -853
  24. package/bundles/cdk-drag-drop.umd.js.map +1 -1
  25. package/bundles/cdk-drag-drop.umd.min.js +2 -1
  26. package/bundles/cdk-drag-drop.umd.min.js.map +1 -1
  27. package/bundles/cdk-keycodes.umd.js +33 -1
  28. package/bundles/cdk-keycodes.umd.js.map +1 -1
  29. package/bundles/cdk-keycodes.umd.min.js +1 -1
  30. package/bundles/cdk-keycodes.umd.min.js.map +1 -1
  31. package/bundles/cdk-layout.umd.js +29 -22
  32. package/bundles/cdk-layout.umd.js.map +1 -1
  33. package/bundles/cdk-layout.umd.min.js +1 -1
  34. package/bundles/cdk-layout.umd.min.js.map +1 -1
  35. package/bundles/cdk-observers.umd.js +25 -6
  36. package/bundles/cdk-observers.umd.js.map +1 -1
  37. package/bundles/cdk-observers.umd.min.js.map +1 -1
  38. package/bundles/cdk-overlay.umd.js +600 -243
  39. package/bundles/cdk-overlay.umd.js.map +1 -1
  40. package/bundles/cdk-overlay.umd.min.js +2 -2
  41. package/bundles/cdk-overlay.umd.min.js.map +1 -1
  42. package/bundles/cdk-platform.umd.js +50 -28
  43. package/bundles/cdk-platform.umd.js.map +1 -1
  44. package/bundles/cdk-platform.umd.min.js.map +1 -1
  45. package/bundles/cdk-portal.umd.js +14 -7
  46. package/bundles/cdk-portal.umd.js.map +1 -1
  47. package/bundles/cdk-portal.umd.min.js.map +1 -1
  48. package/bundles/cdk-scrolling.umd.js +143 -48
  49. package/bundles/cdk-scrolling.umd.js.map +1 -1
  50. package/bundles/cdk-scrolling.umd.min.js +1 -1
  51. package/bundles/cdk-scrolling.umd.min.js.map +1 -1
  52. package/bundles/cdk-stepper.umd.js +103 -19
  53. package/bundles/cdk-stepper.umd.js.map +1 -1
  54. package/bundles/cdk-stepper.umd.min.js +1 -1
  55. package/bundles/cdk-stepper.umd.min.js.map +1 -1
  56. package/bundles/cdk-table.umd.js +182 -48
  57. package/bundles/cdk-table.umd.js.map +1 -1
  58. package/bundles/cdk-table.umd.min.js.map +1 -1
  59. package/bundles/cdk-text-field.umd.js +70 -32
  60. package/bundles/cdk-text-field.umd.js.map +1 -1
  61. package/bundles/cdk-text-field.umd.min.js +1 -1
  62. package/bundles/cdk-text-field.umd.min.js.map +1 -1
  63. package/bundles/cdk-tree.umd.js +71 -34
  64. package/bundles/cdk-tree.umd.js.map +1 -1
  65. package/bundles/cdk-tree.umd.min.js +1 -1
  66. package/bundles/cdk-tree.umd.min.js.map +1 -1
  67. package/bundles/cdk.umd.js +5 -4
  68. package/bundles/cdk.umd.js.map +1 -1
  69. package/bundles/cdk.umd.min.js +1 -1
  70. package/bundles/cdk.umd.min.js.map +1 -1
  71. package/drag-drop/typings/{drag-handle.d.ts → directives/drag-handle.d.ts} +3 -0
  72. package/drag-drop/typings/{drag-placeholder.d.ts → directives/drag-placeholder.d.ts} +0 -0
  73. package/drag-drop/typings/{drag-preview.d.ts → directives/drag-preview.d.ts} +0 -0
  74. package/drag-drop/typings/directives/drag.d.ts +108 -0
  75. package/drag-drop/typings/directives/drop-list-group.d.ts +22 -0
  76. package/drag-drop/typings/directives/drop-list.d.ts +135 -0
  77. package/drag-drop/typings/drag-drop-registry.d.ts +8 -5
  78. package/drag-drop/typings/drag-events.d.ts +24 -6
  79. package/{typings/esm5/drag-drop/drag.d.ts → drag-drop/typings/drag-ref.d.ts} +153 -77
  80. package/drag-drop/typings/drop-list-container.d.ts +21 -3
  81. package/drag-drop/typings/{drop-list.d.ts → drop-list-ref.d.ts} +133 -77
  82. package/drag-drop/typings/index.d.ts +1 -0
  83. package/drag-drop/typings/index.metadata.json +1 -1
  84. package/drag-drop/typings/public-api.d.ts +13 -5
  85. package/esm2015/a11y.js +353 -189
  86. package/esm2015/a11y.js.map +1 -1
  87. package/esm2015/accordion.js +16 -11
  88. package/esm2015/accordion.js.map +1 -1
  89. package/esm2015/bidi.js +18 -9
  90. package/esm2015/bidi.js.map +1 -1
  91. package/esm2015/cdk.js +7 -6
  92. package/esm2015/cdk.js.map +1 -1
  93. package/esm2015/coercion.js +7 -7
  94. package/esm2015/coercion.js.map +1 -1
  95. package/esm2015/collections.js +22 -7
  96. package/esm2015/collections.js.map +1 -1
  97. package/esm2015/drag-drop.js +1768 -751
  98. package/esm2015/drag-drop.js.map +1 -1
  99. package/esm2015/keycodes.js +31 -4
  100. package/esm2015/keycodes.js.map +1 -1
  101. package/esm2015/layout.js +29 -19
  102. package/esm2015/layout.js.map +1 -1
  103. package/esm2015/observers.js +13 -8
  104. package/esm2015/observers.js.map +1 -1
  105. package/esm2015/overlay.js +384 -219
  106. package/esm2015/overlay.js.map +1 -1
  107. package/esm2015/platform.js +53 -31
  108. package/esm2015/platform.js.map +1 -1
  109. package/esm2015/portal.js +13 -9
  110. package/esm2015/portal.js.map +1 -1
  111. package/esm2015/scrolling.js +106 -49
  112. package/esm2015/scrolling.js.map +1 -1
  113. package/esm2015/stepper.js +93 -24
  114. package/esm2015/stepper.js.map +1 -1
  115. package/esm2015/table.js +89 -45
  116. package/esm2015/table.js.map +1 -1
  117. package/esm2015/text-field.js +51 -34
  118. package/esm2015/text-field.js.map +1 -1
  119. package/esm2015/tree.js +55 -36
  120. package/esm2015/tree.js.map +1 -1
  121. package/esm5/a11y.es5.js +507 -214
  122. package/esm5/a11y.es5.js.map +1 -1
  123. package/esm5/accordion.es5.js +18 -11
  124. package/esm5/accordion.es5.js.map +1 -1
  125. package/esm5/bidi.es5.js +18 -9
  126. package/esm5/bidi.es5.js.map +1 -1
  127. package/esm5/cdk.es5.js +7 -6
  128. package/esm5/cdk.es5.js.map +1 -1
  129. package/esm5/coercion.es5.js +7 -7
  130. package/esm5/coercion.es5.js.map +1 -1
  131. package/esm5/collections.es5.js +35 -7
  132. package/esm5/collections.es5.js.map +1 -1
  133. package/esm5/drag-drop.es5.js +2125 -729
  134. package/esm5/drag-drop.es5.js.map +1 -1
  135. package/esm5/keycodes.es5.js +35 -4
  136. package/esm5/keycodes.es5.js.map +1 -1
  137. package/esm5/layout.es5.js +31 -24
  138. package/esm5/layout.es5.js.map +1 -1
  139. package/esm5/observers.es5.js +27 -8
  140. package/esm5/observers.es5.js.map +1 -1
  141. package/esm5/overlay.es5.js +602 -245
  142. package/esm5/overlay.es5.js.map +1 -1
  143. package/esm5/platform.es5.js +52 -30
  144. package/esm5/platform.es5.js.map +1 -1
  145. package/esm5/portal.es5.js +16 -9
  146. package/esm5/portal.es5.js.map +1 -1
  147. package/esm5/scrolling.es5.js +145 -50
  148. package/esm5/scrolling.es5.js.map +1 -1
  149. package/esm5/stepper.es5.js +106 -24
  150. package/esm5/stepper.es5.js.map +1 -1
  151. package/esm5/table.es5.js +184 -50
  152. package/esm5/table.es5.js.map +1 -1
  153. package/esm5/text-field.es5.js +72 -34
  154. package/esm5/text-field.es5.js.map +1 -1
  155. package/esm5/tree.es5.js +74 -37
  156. package/esm5/tree.es5.js.map +1 -1
  157. package/keycodes/typings/index.metadata.json +1 -1
  158. package/keycodes/typings/modifiers.d.ts +14 -0
  159. package/keycodes/typings/public-api.d.ts +1 -0
  160. package/overlay/typings/index.metadata.json +1 -1
  161. package/package.json +4 -4
  162. package/schematics/ng-generate/drag-drop/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.ts +2 -2
  163. package/schematics/ng-update/upgrade-data.js +2 -1
  164. package/schematics/ng-update/upgrade-data.js.map +1 -1
  165. package/schematics/ng-update/upgrade-rules/index.js +3 -2
  166. package/schematics/ng-update/upgrade-rules/index.js.map +1 -1
  167. package/schematics/utils/ast/ng-module-imports.d.ts +1 -1
  168. package/schematics/utils/ast/ng-module-imports.js +25 -13
  169. package/schematics/utils/ast/ng-module-imports.js.map +1 -1
  170. package/schematics/utils/get-project.js +2 -1
  171. package/schematics/utils/get-project.js.map +1 -1
  172. package/schematics/utils/parse5-element.js +3 -2
  173. package/schematics/utils/parse5-element.js.map +1 -1
  174. package/schematics/utils/project-targets.js +2 -1
  175. package/schematics/utils/project-targets.js.map +1 -1
  176. package/schematics/utils/version-agnostic-typescript.js +3 -2
  177. package/schematics/utils/version-agnostic-typescript.js.map +1 -1
  178. package/scrolling/typings/index.metadata.json +1 -1
  179. package/stepper/typings/index.metadata.json +1 -1
  180. package/stepper/typings/public-api.d.ts +1 -0
  181. package/stepper/typings/step-header.d.ts +15 -0
  182. package/stepper/typings/stepper.d.ts +11 -1
  183. package/text-field/typings/autosize.d.ts +6 -0
  184. package/text-field/typings/index.metadata.json +1 -1
  185. package/tree/typings/nested-node.d.ts +5 -5
  186. package/typings/a11y/focus-monitor/focus-monitor.d.ts +20 -4
  187. package/typings/a11y/index.metadata.json +1 -1
  188. package/typings/a11y/key-manager/list-key-manager.d.ts +8 -0
  189. package/typings/a11y/live-announcer/live-announcer.d.ts +37 -4
  190. package/typings/bidi/dir.d.ts +4 -1
  191. package/typings/bidi/index.metadata.json +1 -1
  192. package/typings/{esm5/drag-drop → drag-drop/directives}/drag-handle.d.ts +3 -0
  193. package/typings/drag-drop/{drag-placeholder.d.ts → directives/drag-placeholder.d.ts} +0 -0
  194. package/typings/drag-drop/{drag-preview.d.ts → directives/drag-preview.d.ts} +0 -0
  195. package/typings/drag-drop/directives/drag.d.ts +108 -0
  196. package/typings/drag-drop/directives/drop-list-group.d.ts +22 -0
  197. package/typings/drag-drop/directives/drop-list.d.ts +135 -0
  198. package/typings/drag-drop/drag-drop-registry.d.ts +8 -5
  199. package/typings/drag-drop/drag-events.d.ts +24 -6
  200. package/typings/drag-drop/{drag.d.ts → drag-ref.d.ts} +153 -77
  201. package/typings/drag-drop/drop-list-container.d.ts +21 -3
  202. package/typings/{esm5/drag-drop/drop-list.d.ts → drag-drop/drop-list-ref.d.ts} +133 -77
  203. package/typings/drag-drop/index.d.ts +1 -0
  204. package/typings/drag-drop/index.metadata.json +1 -1
  205. package/typings/drag-drop/public-api.d.ts +13 -5
  206. package/typings/esm5/a11y/focus-monitor/focus-monitor.d.ts +20 -4
  207. package/typings/esm5/a11y/index.metadata.json +1 -1
  208. package/typings/esm5/a11y/key-manager/list-key-manager.d.ts +8 -0
  209. package/typings/esm5/a11y/live-announcer/live-announcer.d.ts +37 -4
  210. package/typings/esm5/bidi/dir.d.ts +4 -1
  211. package/typings/esm5/bidi/index.metadata.json +1 -1
  212. package/typings/{drag-drop → esm5/drag-drop/directives}/drag-handle.d.ts +3 -0
  213. package/typings/esm5/drag-drop/{drag-placeholder.d.ts → directives/drag-placeholder.d.ts} +0 -0
  214. package/typings/esm5/drag-drop/{drag-preview.d.ts → directives/drag-preview.d.ts} +0 -0
  215. package/typings/esm5/drag-drop/directives/drag.d.ts +108 -0
  216. package/typings/esm5/drag-drop/directives/drop-list-group.d.ts +22 -0
  217. package/typings/esm5/drag-drop/directives/drop-list.d.ts +135 -0
  218. package/typings/esm5/drag-drop/drag-drop-registry.d.ts +8 -5
  219. package/typings/esm5/drag-drop/drag-events.d.ts +24 -6
  220. package/{drag-drop/typings/drag.d.ts → typings/esm5/drag-drop/drag-ref.d.ts} +153 -77
  221. package/typings/esm5/drag-drop/drop-list-container.d.ts +21 -3
  222. package/typings/{drag-drop/drop-list.d.ts → esm5/drag-drop/drop-list-ref.d.ts} +133 -77
  223. package/typings/esm5/drag-drop/index.d.ts +1 -0
  224. package/typings/esm5/drag-drop/index.metadata.json +1 -1
  225. package/typings/esm5/drag-drop/public-api.d.ts +13 -5
  226. package/typings/esm5/index.metadata.json +1 -1
  227. package/typings/esm5/keycodes/index.metadata.json +1 -1
  228. package/typings/esm5/keycodes/modifiers.d.ts +14 -0
  229. package/typings/esm5/keycodes/public-api.d.ts +1 -0
  230. package/typings/esm5/overlay/index.metadata.json +1 -1
  231. package/typings/esm5/scrolling/index.metadata.json +1 -1
  232. package/typings/esm5/stepper/index.metadata.json +1 -1
  233. package/typings/esm5/stepper/public-api.d.ts +1 -0
  234. package/typings/esm5/stepper/step-header.d.ts +15 -0
  235. package/typings/esm5/stepper/stepper.d.ts +11 -1
  236. package/typings/esm5/text-field/autosize.d.ts +6 -0
  237. package/typings/esm5/text-field/index.metadata.json +1 -1
  238. package/typings/esm5/tree/nested-node.d.ts +5 -5
  239. package/typings/index.metadata.json +1 -1
  240. package/typings/keycodes/index.metadata.json +1 -1
  241. package/typings/keycodes/modifiers.d.ts +14 -0
  242. package/typings/keycodes/public-api.d.ts +1 -0
  243. package/typings/overlay/index.metadata.json +1 -1
  244. package/typings/schematics/utils/ast/ng-module-imports.d.ts +1 -1
  245. package/typings/scrolling/index.metadata.json +1 -1
  246. package/typings/stepper/index.metadata.json +1 -1
  247. package/typings/stepper/public-api.d.ts +1 -0
  248. package/typings/stepper/step-header.d.ts +15 -0
  249. package/typings/stepper/stepper.d.ts +11 -1
  250. package/typings/text-field/autosize.d.ts +6 -0
  251. package/typings/text-field/index.metadata.json +1 -1
  252. package/typings/tree/nested-node.d.ts +5 -5
@@ -5,70 +5,136 @@
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, ContentChild, InjectionToken, SkipSelf, 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
+ import { coerceBooleanProperty, coerceArray } from '@angular/cdk/coercion';
12
13
  import { Directionality } from '@angular/cdk/bidi';
13
14
  import { ViewportRuler } from '@angular/cdk/scrolling';
14
- import { take } from 'rxjs/operators';
15
- import { coerceArray } from '@angular/cdk/coercion';
15
+ import { startWith, take, map } from 'rxjs/operators';
16
16
 
17
17
  /**
18
18
  * @fileoverview added by tsickle
19
- * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
19
+ * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
20
20
  */
21
21
  /**
22
- * Shallow-extends a stylesheet object with another stylesheet object.
23
- * \@docs-private
24
- * @param {?} dest
25
- * @param {?} source
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.
26
52
  * @return {?}
27
53
  */
28
- function extendStyles(dest, source) {
29
- for (let key in source) {
30
- if (source.hasOwnProperty(key)) {
31
- dest[/** @type {?} */ (key)] = source[/** @type {?} */ (key)];
32
- }
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;
33
61
  }
34
- return dest;
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;
35
70
  }
36
71
  /**
37
- * Toggles whether the native drag interactions should be enabled for an element.
38
- * \@docs-private
39
- * @param {?} element Element on which to toggle the drag interactions.
40
- * @param {?} enable Whether the drag interactions should be enabled.
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.
41
78
  * @return {?}
42
79
  */
43
- function toggleNativeDragInteractions(element, enable) {
80
+ function transferArrayItem(currentArray, targetArray, currentIndex, targetIndex) {
44
81
  /** @type {?} */
45
- const userSelect = enable ? '' : 'none';
46
- extendStyles(element.style, {
47
- touchAction: enable ? '' : 'none',
48
- webkitUserDrag: enable ? '' : 'none',
49
- webkitTapHighlightColor: enable ? '' : 'transparent',
50
- userSelect: userSelect,
51
- msUserSelect: userSelect,
52
- webkitUserSelect: userSelect,
53
- MozUserSelect: userSelect
54
- });
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));
55
115
  }
56
116
 
57
117
  /**
58
118
  * @fileoverview added by tsickle
59
- * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
119
+ * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
120
+ */
121
+ /**
122
+ * Event options that can be used to bind an active, capturing event.
123
+ * @type {?}
60
124
  */
61
- /** *
62
- * Event options that can be used to bind an active event.
63
- @type {?} */
64
- const activeEventOptions = normalizePassiveListenerOptions({ passive: false });
65
- // unsupported: template constraints.
125
+ const activeCapturingEventOptions = normalizePassiveListenerOptions({
126
+ passive: false,
127
+ capture: true
128
+ });
66
129
  /**
67
130
  * Service that keeps track of all the drag item and drop container
68
131
  * instances, and manages global event listeners on the `document`.
69
132
  * \@docs-private
70
133
  * @template I, C
71
134
  */
135
+ // Note: this class is generic, rather than referencing CdkDrag and CdkDropList directly, in order
136
+ // to avoid circular imports. If we were to reference them here, importing the registry into the
137
+ // classes that are registering themselves will introduce a circular import.
72
138
  class DragDropRegistry {
73
139
  /**
74
140
  * @param {?} _ngZone
@@ -103,11 +169,10 @@ class DragDropRegistry {
103
169
  */
104
170
  this.pointerUp = new Subject();
105
171
  /**
106
- * Listener used to prevent `touchmove` events while the element is being dragged.
107
- * This gets bound once, ahead of time, because WebKit won't preventDefault on a
108
- * dynamically-added `touchmove` listener. See https://bugs.webkit.org/show_bug.cgi?id=184250.
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.
109
174
  */
110
- this._preventScrollListener = (event) => {
175
+ this._preventDefaultWhileDragging = (event) => {
111
176
  if (this._activeDragInstances.size) {
112
177
  event.preventDefault();
113
178
  }
@@ -134,11 +199,14 @@ class DragDropRegistry {
134
199
  */
135
200
  registerDragItem(drag) {
136
201
  this._dragInstances.add(drag);
202
+ // The `touchmove` event gets bound once, ahead of time, because WebKit
203
+ // won't preventDefault on a dynamically-added `touchmove` listener.
204
+ // See https://bugs.webkit.org/show_bug.cgi?id=184250.
137
205
  if (this._dragInstances.size === 1) {
138
206
  this._ngZone.runOutsideAngular(() => {
139
- // The event handler has to be explicitly active, because
140
- // newer browsers make it passive by default.
141
- this._document.addEventListener('touchmove', this._preventScrollListener, activeEventOptions);
207
+ // The event handler has to be explicitly active,
208
+ // because newer browsers make it passive by default.
209
+ this._document.addEventListener('touchmove', this._preventDefaultWhileDragging, activeCapturingEventOptions);
142
210
  });
143
211
  }
144
212
  }
@@ -159,7 +227,7 @@ class DragDropRegistry {
159
227
  this._dragInstances.delete(drag);
160
228
  this.stopDragging(drag);
161
229
  if (this._dragInstances.size === 0) {
162
- this._document.removeEventListener('touchmove', this._preventScrollListener, /** @type {?} */ (activeEventOptions));
230
+ this._document.removeEventListener('touchmove', this._preventDefaultWhileDragging, activeCapturingEventOptions);
163
231
  }
164
232
  }
165
233
  /**
@@ -177,17 +245,36 @@ class DragDropRegistry {
177
245
  const moveEvent = isTouchEvent ? 'touchmove' : 'mousemove';
178
246
  /** @type {?} */
179
247
  const upEvent = isTouchEvent ? 'touchend' : 'mouseup';
180
- // We need to disable the native interactions on the entire body, because
181
- // the user can start marking text if they drag too far in Safari.
182
- toggleNativeDragInteractions(this._document.body, false);
183
248
  // We explicitly bind __active__ listeners here, because newer browsers will default to
184
249
  // passive ones for `mousemove` and `touchmove`. The events need to be active, because we
185
250
  // use `preventDefault` to prevent the page from scrolling while the user is dragging.
186
251
  this._globalListeners
187
- .set(moveEvent, { handler: e => this.pointerMove.next(e), options: activeEventOptions })
188
- .set(upEvent, { handler: e => this.pointerUp.next(e) })
189
- .forEach((config, name) => {
190
- this._ngZone.runOutsideAngular(() => {
252
+ .set(moveEvent, {
253
+ handler: (e) => this.pointerMove.next((/** @type {?} */ (e))),
254
+ options: activeCapturingEventOptions
255
+ })
256
+ .set(upEvent, {
257
+ handler: (e) => this.pointerUp.next((/** @type {?} */ (e))),
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
267
+ });
268
+ // TODO(crisbeto): prevent mouse wheel scrolling while
269
+ // dragging until we've set up proper scroll handling.
270
+ if (!isTouchEvent) {
271
+ this._globalListeners.set('wheel', {
272
+ handler: this._preventDefaultWhileDragging,
273
+ options: activeCapturingEventOptions
274
+ });
275
+ }
276
+ this._ngZone.runOutsideAngular(() => {
277
+ this._globalListeners.forEach((config, name) => {
191
278
  this._document.addEventListener(name, config.handler, config.options);
192
279
  });
193
280
  });
@@ -202,7 +289,6 @@ class DragDropRegistry {
202
289
  this._activeDragInstances.delete(drag);
203
290
  if (this._activeDragInstances.size === 0) {
204
291
  this._clearGlobalListeners();
205
- toggleNativeDragInteractions(this._document.body, true);
206
292
  }
207
293
  }
208
294
  /**
@@ -215,6 +301,8 @@ class DragDropRegistry {
215
301
  }
216
302
  /**
217
303
  * Gets a drop container by its id.
304
+ * @deprecated No longer being used. To be removed.
305
+ * \@breaking-change 8.0.0
218
306
  * @param {?} id
219
307
  * @return {?}
220
308
  */
@@ -233,6 +321,7 @@ class DragDropRegistry {
233
321
  }
234
322
  /**
235
323
  * Clears out the global event listeners from the `document`.
324
+ * @private
236
325
  * @return {?}
237
326
  */
238
327
  _clearGlobalListeners() {
@@ -254,19 +343,60 @@ DragDropRegistry.ctorParameters = () => [
254
343
 
255
344
  /**
256
345
  * @fileoverview added by tsickle
257
- * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
346
+ * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
258
347
  */
259
- /** *
348
+ /**
260
349
  * Injection token that can be used for a `CdkDrag` to provide itself as a parent to the
261
350
  * drag-specific child directive (`CdkDragHandle`, `CdkDragPreview` etc.). Used primarily
262
351
  * to avoid circular imports.
263
352
  * \@docs-private
264
- @type {?} */
353
+ * @type {?}
354
+ */
265
355
  const CDK_DRAG_PARENT = new InjectionToken('CDK_DRAG_PARENT');
266
356
 
267
357
  /**
268
358
  * @fileoverview added by tsickle
269
- * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
359
+ * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
360
+ */
361
+ /**
362
+ * Shallow-extends a stylesheet object with another stylesheet object.
363
+ * \@docs-private
364
+ * @param {?} dest
365
+ * @param {?} source
366
+ * @return {?}
367
+ */
368
+ function extendStyles(dest, source) {
369
+ for (let key in source) {
370
+ if (source.hasOwnProperty(key)) {
371
+ dest[(/** @type {?} */ (key))] = source[(/** @type {?} */ (key))];
372
+ }
373
+ }
374
+ return dest;
375
+ }
376
+ /**
377
+ * Toggles whether the native drag interactions should be enabled for an element.
378
+ * \@docs-private
379
+ * @param {?} element Element on which to toggle the drag interactions.
380
+ * @param {?} enable Whether the drag interactions should be enabled.
381
+ * @return {?}
382
+ */
383
+ function toggleNativeDragInteractions(element, enable) {
384
+ /** @type {?} */
385
+ const userSelect = enable ? '' : 'none';
386
+ extendStyles(element.style, {
387
+ touchAction: enable ? '' : 'none',
388
+ webkitUserDrag: enable ? '' : 'none',
389
+ webkitTapHighlightColor: enable ? '' : 'transparent',
390
+ userSelect: userSelect,
391
+ msUserSelect: userSelect,
392
+ webkitUserSelect: userSelect,
393
+ MozUserSelect: userSelect
394
+ });
395
+ }
396
+
397
+ /**
398
+ * @fileoverview added by tsickle
399
+ * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
270
400
  */
271
401
  /**
272
402
  * Handle that can be used to drag and CdkDrag instance.
@@ -278,9 +408,22 @@ class CdkDragHandle {
278
408
  */
279
409
  constructor(element, parentDrag) {
280
410
  this.element = element;
411
+ this._disabled = false;
281
412
  this._parentDrag = parentDrag;
282
413
  toggleNativeDragInteractions(element.nativeElement, false);
283
414
  }
415
+ /**
416
+ * Whether starting to drag through this handle is disabled.
417
+ * @return {?}
418
+ */
419
+ get disabled() { return this._disabled; }
420
+ /**
421
+ * @param {?} value
422
+ * @return {?}
423
+ */
424
+ set disabled(value) {
425
+ this._disabled = coerceBooleanProperty(value);
426
+ }
284
427
  }
285
428
  CdkDragHandle.decorators = [
286
429
  { type: Directive, args: [{
@@ -295,10 +438,13 @@ CdkDragHandle.ctorParameters = () => [
295
438
  { type: ElementRef },
296
439
  { type: undefined, decorators: [{ type: Inject, args: [CDK_DRAG_PARENT,] }, { type: Optional }] }
297
440
  ];
441
+ CdkDragHandle.propDecorators = {
442
+ disabled: [{ type: Input, args: ['cdkDragHandleDisabled',] }]
443
+ };
298
444
 
299
445
  /**
300
446
  * @fileoverview added by tsickle
301
- * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
447
+ * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
302
448
  */
303
449
  /**
304
450
  * Element that will be used as a template for the placeholder of a CdkDrag when
@@ -328,7 +474,7 @@ CdkDragPlaceholder.propDecorators = {
328
474
 
329
475
  /**
330
476
  * @fileoverview added by tsickle
331
- * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
477
+ * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
332
478
  */
333
479
  /**
334
480
  * Element that will be used as a template for the preview
@@ -358,17 +504,7 @@ CdkDragPreview.propDecorators = {
358
504
 
359
505
  /**
360
506
  * @fileoverview added by tsickle
361
- * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
362
- */
363
- /** *
364
- * Injection token that is used to provide a CdkDropList instance to CdkDrag.
365
- * Used for avoiding circular imports.
366
- @type {?} */
367
- const CDK_DROP_LIST_CONTAINER = new InjectionToken('CDK_DROP_LIST_CONTAINER');
368
-
369
- /**
370
- * @fileoverview added by tsickle
371
- * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
507
+ * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
372
508
  */
373
509
 
374
510
  /**
@@ -377,6 +513,7 @@ const CDK_DROP_LIST_CONTAINER = new InjectionToken('CDK_DROP_LIST_CONTAINER');
377
513
  * @return {?}
378
514
  */
379
515
  function parseCssTimeUnitsToMs(value) {
516
+ // Some browsers will return it in seconds, whereas others will return milliseconds.
380
517
  /** @type {?} */
381
518
  const multiplier = value.toLowerCase().indexOf('ms') > -1 ? 1 : 1000;
382
519
  return parseFloat(value) * multiplier;
@@ -397,6 +534,8 @@ function getTransformTransitionDurationInMs(element) {
397
534
  if (!property) {
398
535
  return 0;
399
536
  }
537
+ // Get the index of the property that we're interested in and match
538
+ // it up to the same index in `transition-delay` and `transition-duration`.
400
539
  /** @type {?} */
401
540
  const propertyIndex = transitionedProperties.indexOf(property);
402
541
  /** @type {?} */
@@ -420,51 +559,51 @@ function parseCssPropertyValue(computedStyle, name) {
420
559
 
421
560
  /**
422
561
  * @fileoverview added by tsickle
423
- * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
562
+ * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
424
563
  */
425
- /** *
426
- * Injection token that can be used to configure the behavior of `CdkDrag`.
427
- @type {?} */
428
- const CDK_DRAG_CONFIG = new InjectionToken('CDK_DRAG_CONFIG', {
429
- providedIn: 'root',
430
- factory: CDK_DRAG_CONFIG_FACTORY
431
- });
432
564
  /**
433
- * \@docs-private
434
- * @return {?}
435
- */
436
- function CDK_DRAG_CONFIG_FACTORY() {
437
- return { dragStartThreshold: 5, pointerDirectionChangeThreshold: 5 };
438
- }
439
- /** *
440
565
  * Options that can be used to bind a passive event listener.
441
- @type {?} */
566
+ * @type {?}
567
+ */
442
568
  const passiveEventListenerOptions = normalizePassiveListenerOptions({ passive: true });
443
569
  /**
444
- * Element that can be moved inside a CdkDropList container.
570
+ * Options that can be used to bind an active event listener.
571
+ * @type {?}
572
+ */
573
+ const activeEventListenerOptions = normalizePassiveListenerOptions({ passive: false });
574
+ /**
575
+ * Time in milliseconds for which to ignore mouse events, after
576
+ * receiving a touch event. Used to avoid doing double work for
577
+ * touch devices where the browser fires fake mouse events, in
578
+ * addition to touch events.
579
+ * @type {?}
580
+ */
581
+ const MOUSE_EVENT_IGNORE_TIME = 800;
582
+ /**
583
+ * Reference to a draggable item. Used to manipulate or dispose of the item.
584
+ * \@docs-private
445
585
  * @template T
446
586
  */
447
- class CdkDrag {
587
+ class DragRef {
448
588
  /**
449
589
  * @param {?} element
450
- * @param {?} dropContainer
451
- * @param {?} document
590
+ * @param {?} _document
452
591
  * @param {?} _ngZone
453
592
  * @param {?} _viewContainerRef
454
593
  * @param {?} _viewportRuler
455
594
  * @param {?} _dragDropRegistry
456
595
  * @param {?} _config
457
- * @param {?} _dir
596
+ * @param {?=} dropContainer
597
+ * @param {?=} _dir
458
598
  */
459
- constructor(element, /** Droppable container that the draggable is a part of. */
460
- dropContainer, document, _ngZone, _viewContainerRef, _viewportRuler, _dragDropRegistry, _config, _dir) {
461
- this.element = element;
462
- this.dropContainer = dropContainer;
599
+ constructor(element, _document, _ngZone, _viewContainerRef, _viewportRuler, _dragDropRegistry, _config, dropContainer, _dir) {
600
+ this._document = _document;
463
601
  this._ngZone = _ngZone;
464
602
  this._viewContainerRef = _viewContainerRef;
465
603
  this._viewportRuler = _viewportRuler;
466
604
  this._dragDropRegistry = _dragDropRegistry;
467
605
  this._config = _config;
606
+ this.dropContainer = dropContainer;
468
607
  this._dir = _dir;
469
608
  /**
470
609
  * CSS `transform` applied to the element when it isn't being dragged. We need a
@@ -494,26 +633,47 @@ class CdkDrag {
494
633
  * Subscription to the event that is dispatched when the user lifts their pointer.
495
634
  */
496
635
  this._pointerUpSubscription = Subscription.EMPTY;
636
+ /**
637
+ * Cached reference to the boundary element.
638
+ */
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;
648
+ this._disabled = false;
649
+ /**
650
+ * Emits as the drag sequence is being prepared.
651
+ */
652
+ this.beforeStarted = new Subject();
497
653
  /**
498
654
  * Emits when the user starts dragging the item.
499
655
  */
500
- 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();
501
661
  /**
502
662
  * Emits when the user stops dragging an item in the container.
503
663
  */
504
- this.ended = new EventEmitter();
664
+ this.ended = new Subject();
505
665
  /**
506
666
  * Emits when the user has moved the item into a new container.
507
667
  */
508
- this.entered = new EventEmitter();
668
+ this.entered = new Subject();
509
669
  /**
510
670
  * Emits when the user removes the item its container by dragging it into another container.
511
671
  */
512
- this.exited = new EventEmitter();
672
+ this.exited = new Subject();
513
673
  /**
514
674
  * Emits when the user drops the item inside a container.
515
675
  */
516
- this.dropped = new EventEmitter();
676
+ this.dropped = new Subject();
517
677
  /**
518
678
  * Emits as the user is dragging the item. Use with caution,
519
679
  * because this event will fire for every pixel that the user has dragged.
@@ -531,23 +691,22 @@ class CdkDrag {
531
691
  * Handler for the `mousedown`/`touchstart` events.
532
692
  */
533
693
  this._pointerDown = (event) => {
534
- /** @type {?} */
535
- const handles = this._handles.filter(handle => handle._parentDrag === this);
694
+ this.beforeStarted.next();
536
695
  // Delegate the event based on whether it started from a handle or the element itself.
537
- if (handles.length) {
696
+ if (this._handles.length) {
538
697
  /** @type {?} */
539
- const targetHandle = handles.find(handle => {
698
+ const targetHandle = this._handles.find(handle => {
540
699
  /** @type {?} */
541
700
  const element = handle.element.nativeElement;
542
701
  /** @type {?} */
543
702
  const target = event.target;
544
- return !!target && (target === element || element.contains(/** @type {?} */ (target)));
703
+ return !!target && (target === element || element.contains((/** @type {?} */ (target))));
545
704
  });
546
- if (targetHandle) {
705
+ if (targetHandle && !targetHandle.disabled && !this.disabled) {
547
706
  this._initializeDragSequence(targetHandle.element.nativeElement, event);
548
707
  }
549
708
  }
550
- else {
709
+ else if (!this.disabled) {
551
710
  this._initializeDragSequence(this._rootElement, event);
552
711
  }
553
712
  };
@@ -555,9 +714,9 @@ class CdkDrag {
555
714
  * Handler that is invoked when the user moves their pointer after they've initiated a drag.
556
715
  */
557
716
  this._pointerMove = (event) => {
558
- /** @type {?} */
559
- const pointerPosition = this._getConstrainedPointerPosition(event);
560
717
  if (!this._hasStartedDragging) {
718
+ /** @type {?} */
719
+ const pointerPosition = this._getPointerPositionOnPage(event);
561
720
  /** @type {?} */
562
721
  const distanceX = Math.abs(pointerPosition.x - this._pickupPositionOnPage.x);
563
722
  /** @type {?} */
@@ -568,28 +727,44 @@ class CdkDrag {
568
727
  // per pixel of movement (e.g. if the user moves their pointer quickly).
569
728
  if (distanceX + distanceY >= this._config.dragStartThreshold) {
570
729
  this._hasStartedDragging = true;
571
- this._ngZone.run(() => this._startDragSequence());
730
+ this._ngZone.run(() => this._startDragSequence(event));
572
731
  }
573
732
  return;
574
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);
575
744
  this._hasMoved = true;
576
745
  event.preventDefault();
577
- this._updatePointerDirectionDelta(pointerPosition);
746
+ this._updatePointerDirectionDelta(constrainedPointerPosition);
578
747
  if (this.dropContainer) {
579
- this._updateActiveDropContainer(pointerPosition);
748
+ this._updateActiveDropContainer(constrainedPointerPosition);
580
749
  }
581
750
  else {
582
751
  /** @type {?} */
583
752
  const activeTransform = this._activeTransform;
584
753
  activeTransform.x =
585
- pointerPosition.x - this._pickupPositionOnPage.x + this._passiveTransform.x;
754
+ constrainedPointerPosition.x - this._pickupPositionOnPage.x + this._passiveTransform.x;
586
755
  activeTransform.y =
587
- pointerPosition.y - this._pickupPositionOnPage.y + this._passiveTransform.y;
756
+ constrainedPointerPosition.y - this._pickupPositionOnPage.y + this._passiveTransform.y;
588
757
  /** @type {?} */
589
758
  const transform = getTransform(activeTransform.x, activeTransform.y);
590
759
  // Preserve the previous `transform` value, if there was one.
591
760
  this._rootElement.style.transform = this._initialTransform ?
592
761
  this._initialTransform + ' ' + transform : transform;
762
+ // Apply transform as attribute if dragging and svg element to work for IE
763
+ if (typeof SVGElement !== 'undefined' && this._rootElement instanceof SVGElement) {
764
+ /** @type {?} */
765
+ const appliedTransform = `translate(${activeTransform.x} ${activeTransform.y})`;
766
+ this._rootElement.setAttribute('transform', appliedTransform);
767
+ }
593
768
  }
594
769
  // Since this event gets fired for every pixel while dragging, we only
595
770
  // want to fire it if the consumer opted into it. Also we have to
@@ -598,7 +773,7 @@ class CdkDrag {
598
773
  this._ngZone.run(() => {
599
774
  this._moveEvents.next({
600
775
  source: this,
601
- pointerPosition,
776
+ pointerPosition: constrainedPointerPosition,
602
777
  event,
603
778
  delta: this._pointerDirectionDelta
604
779
  });
@@ -608,29 +783,55 @@ class CdkDrag {
608
783
  /**
609
784
  * Handler that is invoked when the user lifts their pointer up, after initiating a drag.
610
785
  */
611
- this._pointerUp = () => {
612
- 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)) {
613
792
  return;
614
793
  }
615
794
  this._removeSubscriptions();
616
795
  this._dragDropRegistry.stopDragging(this);
796
+ if (this._handles) {
797
+ this._rootElement.style.webkitTapHighlightColor = this._rootElementTapHighlight;
798
+ }
617
799
  if (!this._hasStartedDragging) {
618
800
  return;
619
801
  }
802
+ this.released.next({ source: this });
620
803
  if (!this.dropContainer) {
621
804
  // Convert the active transform into a passive one. This means that next time
622
805
  // the user starts dragging the item, its position will be calculated relatively
623
806
  // to the new passive transform.
624
807
  this._passiveTransform.x = this._activeTransform.x;
625
808
  this._passiveTransform.y = this._activeTransform.y;
626
- this._ngZone.run(() => this.ended.emit({ source: this }));
809
+ this._ngZone.run(() => this.ended.next({ source: this }));
810
+ this._dragDropRegistry.stopDragging(this);
627
811
  return;
628
812
  }
629
- this._animatePreviewToPlaceholder().then(() => this._cleanupDragArtifacts());
813
+ this._animatePreviewToPlaceholder().then(() => {
814
+ this._cleanupDragArtifacts(event);
815
+ this._dragDropRegistry.stopDragging(this);
816
+ });
630
817
  };
631
- this._document = document;
818
+ this.withRootElement(element);
632
819
  _dragDropRegistry.registerDragItem(this);
633
820
  }
821
+ /**
822
+ * Whether starting to drag this element is disabled.
823
+ * @return {?}
824
+ */
825
+ get disabled() {
826
+ return this._disabled || !!(this.dropContainer && this.dropContainer.disabled);
827
+ }
828
+ /**
829
+ * @param {?} value
830
+ * @return {?}
831
+ */
832
+ set disabled(value) {
833
+ this._disabled = coerceBooleanProperty(value);
834
+ }
634
835
  /**
635
836
  * Returns the element that is being used as a placeholder
636
837
  * while the current element is being dragged.
@@ -647,91 +848,171 @@ class CdkDrag {
647
848
  return this._rootElement;
648
849
  }
649
850
  /**
650
- * @return {?}
851
+ * Registers the handles that can be used to drag the element.
852
+ * @template THIS
853
+ * @this {THIS}
854
+ * @param {?} handles
855
+ * @return {THIS}
651
856
  */
652
- ngAfterViewInit() {
653
- // We need to wait for the zone to stabilize, in order for the reference
654
- // element to be in the proper place in the DOM. This is mostly relevant
655
- // for draggable elements inside portals since they get stamped out in
656
- // their original DOM position and then they get transferred to the portal.
657
- this._ngZone.onStable.asObservable().pipe(take(1)).subscribe(() => {
658
- /** @type {?} */
659
- const rootElement = this._rootElement = this._getRootElement();
660
- rootElement.addEventListener('mousedown', this._pointerDown, passiveEventListenerOptions);
661
- rootElement.addEventListener('touchstart', this._pointerDown, passiveEventListenerOptions);
662
- toggleNativeDragInteractions(rootElement, false);
663
- });
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));
664
921
  }
665
922
  /**
923
+ * Removes the dragging functionality from the DOM element.
666
924
  * @return {?}
667
925
  */
668
- ngOnDestroy() {
669
- this._rootElement.removeEventListener('mousedown', this._pointerDown, passiveEventListenerOptions);
670
- this._rootElement.removeEventListener('touchstart', this._pointerDown, passiveEventListenerOptions);
671
- this._destroyPreview();
672
- this._destroyPlaceholder();
926
+ dispose() {
927
+ this._removeRootElementListeners(this._rootElement);
673
928
  // Do this check before removing from the registry since it'll
674
929
  // stop being considered as dragged once it is removed.
675
- if (this._isDragging()) {
930
+ if (this.isDragging()) {
676
931
  // Since we move out the element to the end of the body while it's being
677
932
  // dragged, we have to make sure that it's removed if it gets destroyed.
678
- this._removeElement(this._rootElement);
933
+ removeElement(this._rootElement);
679
934
  }
680
- this._nextSibling = null;
935
+ this._destroyPreview();
936
+ this._destroyPlaceholder();
681
937
  this._dragDropRegistry.removeDragItem(this);
682
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();
683
946
  this._moveEvents.complete();
947
+ this._handles = [];
948
+ this._boundaryElement = this._rootElement = this._placeholderTemplate =
949
+ this._previewTemplate = this._nextSibling = (/** @type {?} */ (null));
684
950
  }
685
951
  /**
686
952
  * Checks whether the element is currently being dragged.
687
953
  * @return {?}
688
954
  */
689
- _isDragging() {
690
- return this._dragDropRegistry.isDragging(this);
955
+ isDragging() {
956
+ return this._hasStartedDragging && this._dragDropRegistry.isDragging(this);
691
957
  }
692
958
  /**
693
- * Sets up the different variables and subscriptions
694
- * that will be necessary for the dragging sequence.
695
- * @param {?} referenceElement Element that started the drag sequence.
696
- * @param {?} event Browser event object that started the sequence.
959
+ * Resets a standalone drag item to its initial position.
697
960
  * @return {?}
698
961
  */
699
- _initializeDragSequence(referenceElement, event) {
700
- // Always stop propagation for the event that initializes
701
- // the dragging sequence, in order to prevent it from potentially
702
- // starting another sequence for a draggable parent somewhere up the DOM tree.
703
- event.stopPropagation();
704
- // Abort if the user is already dragging or is using a mouse button other than the primary one.
705
- if (this._isDragging() || (!this._isTouchEvent(event) && event.button !== 0)) {
706
- return;
962
+ reset() {
963
+ this._rootElement.style.transform = '';
964
+ this._activeTransform = { x: 0, y: 0 };
965
+ this._passiveTransform = { x: 0, y: 0 };
966
+ }
967
+ /**
968
+ * Unsubscribes from the global subscriptions.
969
+ * @private
970
+ * @return {?}
971
+ */
972
+ _removeSubscriptions() {
973
+ this._pointerMoveSubscription.unsubscribe();
974
+ this._pointerUpSubscription.unsubscribe();
975
+ }
976
+ /**
977
+ * Destroys the preview element and its ViewRef.
978
+ * @private
979
+ * @return {?}
980
+ */
981
+ _destroyPreview() {
982
+ if (this._preview) {
983
+ removeElement(this._preview);
707
984
  }
708
- // Cache the previous transform amount only after the first drag sequence, because
709
- // we don't want our own transforms to stack on top of each other.
710
- if (this._initialTransform == null) {
711
- this._initialTransform = this._rootElement.style.transform || '';
985
+ if (this._previewRef) {
986
+ this._previewRef.destroy();
712
987
  }
713
- this._hasStartedDragging = this._hasMoved = false;
714
- this._initialContainer = this.dropContainer;
715
- this._pointerMoveSubscription = this._dragDropRegistry.pointerMove.subscribe(this._pointerMove);
716
- this._pointerUpSubscription = this._dragDropRegistry.pointerUp.subscribe(this._pointerUp);
717
- this._scrollPosition = this._viewportRuler.getViewportScrollPosition();
718
- // If we have a custom preview template, the element won't be visible anyway so we avoid the
719
- // extra `getBoundingClientRect` calls and just move the preview next to the cursor.
720
- this._pickupPositionInElement = this._previewTemplate ? { x: 0, y: 0 } :
721
- this._getPointerPositionInElement(referenceElement, event);
722
- /** @type {?} */
723
- const pointerPosition = this._pickupPositionOnPage = this._getPointerPositionOnPage(event);
724
- this._pointerDirectionDelta = { x: 0, y: 0 };
725
- this._pointerPositionAtLastDirectionChange = { x: pointerPosition.x, y: pointerPosition.y };
726
- this._dragDropRegistry.startDragging(this, event);
988
+ this._preview = this._previewRef = (/** @type {?} */ (null));
989
+ }
990
+ /**
991
+ * Destroys the placeholder element and its ViewRef.
992
+ * @private
993
+ * @return {?}
994
+ */
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));
727
1003
  }
728
1004
  /**
729
1005
  * Starts the dragging sequence.
1006
+ * @private
1007
+ * @param {?} event
730
1008
  * @return {?}
731
1009
  */
732
- _startDragSequence() {
1010
+ _startDragSequence(event) {
733
1011
  // Emit the event on the item before the one on the container.
734
- this.started.emit({ source: this });
1012
+ this.started.next({ source: this });
1013
+ if (isTouchEvent(event)) {
1014
+ this._lastTouchEventTime = Date.now();
1015
+ }
735
1016
  if (this.dropContainer) {
736
1017
  /** @type {?} */
737
1018
  const element = this._rootElement;
@@ -746,80 +1027,160 @@ class CdkDrag {
746
1027
  // place will throw off the consumer's `:last-child` selectors. We can't remove the element
747
1028
  // from the DOM completely, because iOS will stop firing all subsequent events in the chain.
748
1029
  element.style.display = 'none';
749
- this._document.body.appendChild(/** @type {?} */ ((element.parentNode)).replaceChild(placeholder, element));
1030
+ this._document.body.appendChild((/** @type {?} */ (element.parentNode)).replaceChild(placeholder, element));
750
1031
  this._document.body.appendChild(preview);
751
1032
  this.dropContainer.start();
752
1033
  }
753
1034
  }
1035
+ /**
1036
+ * Sets up the different variables and subscriptions
1037
+ * that will be necessary for the dragging sequence.
1038
+ * @private
1039
+ * @param {?} referenceElement Element that started the drag sequence.
1040
+ * @param {?} event Browser event object that started the sequence.
1041
+ * @return {?}
1042
+ */
1043
+ _initializeDragSequence(referenceElement, event) {
1044
+ // Always stop propagation for the event that initializes
1045
+ // the dragging sequence, in order to prevent it from potentially
1046
+ // starting another sequence for a draggable parent somewhere up the DOM tree.
1047
+ event.stopPropagation();
1048
+ /** @type {?} */
1049
+ const isDragging = this.isDragging();
1050
+ /** @type {?} */
1051
+ const isTouchSequence = isTouchEvent(event);
1052
+ /** @type {?} */
1053
+ const isAuxiliaryMouseButton = !isTouchSequence && ((/** @type {?} */ (event))).button !== 0;
1054
+ /** @type {?} */
1055
+ const rootElement = this._rootElement;
1056
+ /** @type {?} */
1057
+ const isSyntheticEvent = !isTouchSequence && this._lastTouchEventTime &&
1058
+ this._lastTouchEventTime + MOUSE_EVENT_IGNORE_TIME > Date.now();
1059
+ // If the event started from an element with the native HTML drag&drop, it'll interfere
1060
+ // with our own dragging (e.g. `img` tags do it by default). Prevent the default action
1061
+ // to stop it from happening. Note that preventing on `dragstart` also seems to work, but
1062
+ // it's flaky and it fails if the user drags it away quickly. Also note that we only want
1063
+ // to do this for `mousedown` since doing the same for `touchstart` will stop any `click`
1064
+ // events from firing on touch devices.
1065
+ if (event.target && ((/** @type {?} */ (event.target))).draggable && event.type === 'mousedown') {
1066
+ event.preventDefault();
1067
+ }
1068
+ // Abort if the user is already dragging or is using a mouse button other than the primary one.
1069
+ if (isDragging || isAuxiliaryMouseButton || isSyntheticEvent) {
1070
+ return;
1071
+ }
1072
+ // Cache the previous transform amount only after the first drag sequence, because
1073
+ // we don't want our own transforms to stack on top of each other.
1074
+ if (this._initialTransform == null) {
1075
+ this._initialTransform = this._rootElement.style.transform || '';
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();
1085
+ this._hasStartedDragging = this._hasMoved = false;
1086
+ this._initialContainer = (/** @type {?} */ (this.dropContainer));
1087
+ this._pointerMoveSubscription = this._dragDropRegistry.pointerMove.subscribe(this._pointerMove);
1088
+ this._pointerUpSubscription = this._dragDropRegistry.pointerUp.subscribe(this._pointerUp);
1089
+ this._scrollPosition = this._viewportRuler.getViewportScrollPosition();
1090
+ if (this._boundaryElement) {
1091
+ this._boundaryRect = this._boundaryElement.getBoundingClientRect();
1092
+ }
1093
+ // If we have a custom preview template, the element won't be visible anyway so we avoid the
1094
+ // extra `getBoundingClientRect` calls and just move the preview next to the cursor.
1095
+ this._pickupPositionInElement = this._previewTemplate ? { x: 0, y: 0 } :
1096
+ this._getPointerPositionInElement(referenceElement, event);
1097
+ /** @type {?} */
1098
+ const pointerPosition = this._pickupPositionOnPage = this._getPointerPositionOnPage(event);
1099
+ this._pointerDirectionDelta = { x: 0, y: 0 };
1100
+ this._pointerPositionAtLastDirectionChange = { x: pointerPosition.x, y: pointerPosition.y };
1101
+ this._dragDropRegistry.startDragging(this, event);
1102
+ }
754
1103
  /**
755
1104
  * Cleans up the DOM artifacts that were added to facilitate the element being dragged.
1105
+ * @private
1106
+ * @param {?} event
756
1107
  * @return {?}
757
1108
  */
758
- _cleanupDragArtifacts() {
1109
+ _cleanupDragArtifacts(event) {
759
1110
  // Restore the element's visibility and insert it at its old position in the DOM.
760
1111
  // It's important that we maintain the position, because moving the element around in the DOM
761
1112
  // can throw off `NgFor` which does smart diffing and re-creates elements only when necessary,
762
1113
  // while moving the existing elements in all other cases.
763
1114
  this._rootElement.style.display = '';
764
1115
  if (this._nextSibling) {
765
- /** @type {?} */ ((this._nextSibling.parentNode)).insertBefore(this._rootElement, this._nextSibling);
1116
+ (/** @type {?} */ (this._nextSibling.parentNode)).insertBefore(this._rootElement, this._nextSibling);
766
1117
  }
767
1118
  else {
768
1119
  this._initialContainer.element.nativeElement.appendChild(this._rootElement);
769
1120
  }
770
1121
  this._destroyPreview();
771
1122
  this._destroyPlaceholder();
1123
+ this._boundaryRect = this._previewRect = undefined;
772
1124
  // Re-enter the NgZone since we bound `document` events on the outside.
773
1125
  this._ngZone.run(() => {
774
1126
  /** @type {?} */
775
- const currentIndex = this.dropContainer.getItemIndex(this);
776
- this.ended.emit({ source: this });
777
- 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({
778
1135
  item: this,
779
1136
  currentIndex,
780
1137
  previousIndex: this._initialContainer.getItemIndex(this),
781
- container: this.dropContainer,
782
- previousContainer: this._initialContainer
1138
+ container: container,
1139
+ previousContainer: this._initialContainer,
1140
+ isPointerOverContainer
783
1141
  });
784
- this.dropContainer.drop(this, currentIndex, this._initialContainer);
1142
+ container.drop(this, currentIndex, this._initialContainer, isPointerOverContainer);
785
1143
  this.dropContainer = this._initialContainer;
786
1144
  });
787
1145
  }
788
1146
  /**
789
1147
  * Updates the item's position in its drop container, or moves it
790
1148
  * into a new one, depending on its current drag position.
1149
+ * @private
791
1150
  * @param {?} __0
792
1151
  * @return {?}
793
1152
  */
794
1153
  _updateActiveDropContainer({ x, y }) {
1154
+ // Drop container that draggable has been moved into.
795
1155
  /** @type {?} */
796
- let newContainer = this.dropContainer._getSiblingContainerFromPosition(this, x, y);
1156
+ let newContainer = (/** @type {?} */ (this.dropContainer))._getSiblingContainerFromPosition(this, x, y);
797
1157
  // If we couldn't find a new container to move the item into, and the item has left it's
798
- // initial container, check whether the it's allowed to return into its original container.
799
- // This handles the case where two containers are connected one way and the user tries to
800
- // 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.
801
1161
  if (!newContainer && this.dropContainer !== this._initialContainer &&
802
- this._initialContainer._canReturnItem(this, x, y)) {
1162
+ this._initialContainer._isOverContainer(x, y)) {
803
1163
  newContainer = this._initialContainer;
804
1164
  }
805
1165
  if (newContainer) {
806
1166
  this._ngZone.run(() => {
807
1167
  // Notify the old container that the item has left.
808
- this.exited.emit({ item: this, container: this.dropContainer });
809
- this.dropContainer.exit(this);
1168
+ this.exited.next({ item: this, container: (/** @type {?} */ (this.dropContainer)) });
1169
+ (/** @type {?} */ (this.dropContainer)).exit(this);
810
1170
  // Notify the new container that the item has entered.
811
- this.entered.emit({ item: this, container: /** @type {?} */ ((newContainer)) });
812
- this.dropContainer = /** @type {?} */ ((newContainer));
1171
+ this.entered.next({ item: this, container: (/** @type {?} */ (newContainer)) });
1172
+ this.dropContainer = (/** @type {?} */ (newContainer));
813
1173
  this.dropContainer.enter(this, x, y);
814
1174
  });
815
1175
  }
816
- this.dropContainer._sortItem(this, x, y, this._pointerDirectionDelta);
1176
+ (/** @type {?} */ (this.dropContainer))._sortItem(this, x, y, this._pointerDirectionDelta);
817
1177
  this._preview.style.transform =
818
1178
  getTransform(x - this._pickupPositionInElement.x, y - this._pickupPositionInElement.y);
819
1179
  }
820
1180
  /**
821
1181
  * Creates the element that will be rendered next to the user's pointer
822
1182
  * and will be used as a preview of the element that is being dragged.
1183
+ * @private
823
1184
  * @return {?}
824
1185
  */
825
1186
  _createPreviewElement() {
@@ -838,23 +1199,72 @@ class CdkDrag {
838
1199
  const element = this._rootElement;
839
1200
  /** @type {?} */
840
1201
  const elementRect = element.getBoundingClientRect();
841
- preview = /** @type {?} */ (element.cloneNode(true));
1202
+ preview = deepCloneNode(element);
842
1203
  preview.style.width = `${elementRect.width}px`;
843
1204
  preview.style.height = `${elementRect.height}px`;
844
1205
  preview.style.transform = getTransform(elementRect.left, elementRect.top);
845
1206
  }
846
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',
847
1211
  position: 'fixed',
848
1212
  top: '0',
849
1213
  left: '0',
850
1214
  zIndex: '1000'
851
1215
  });
1216
+ toggleNativeDragInteractions(preview, false);
852
1217
  preview.classList.add('cdk-drag-preview');
853
1218
  preview.setAttribute('dir', this._dir ? this._dir.value : 'ltr');
854
1219
  return preview;
855
1220
  }
1221
+ /**
1222
+ * Animates the preview element from its current position to the location of the drop placeholder.
1223
+ * @private
1224
+ * @return {?} Promise that resolves when the animation completes.
1225
+ */
1226
+ _animatePreviewToPlaceholder() {
1227
+ // If the user hasn't moved yet, the transitionend event won't fire.
1228
+ if (!this._hasMoved) {
1229
+ return Promise.resolve();
1230
+ }
1231
+ /** @type {?} */
1232
+ const placeholderRect = this._placeholder.getBoundingClientRect();
1233
+ // Apply the class that adds a transition to the preview.
1234
+ this._preview.classList.add('cdk-drag-animating');
1235
+ // Move the preview to the placeholder position.
1236
+ this._preview.style.transform = getTransform(placeholderRect.left, placeholderRect.top);
1237
+ // If the element doesn't have a `transition`, the `transitionend` event won't fire. Since
1238
+ // we need to trigger a style recalculation in order for the `cdk-drag-animating` class to
1239
+ // apply its style, we take advantage of the available info to figure out whether we need to
1240
+ // bind the event in the first place.
1241
+ /** @type {?} */
1242
+ const duration = getTransformTransitionDurationInMs(this._preview);
1243
+ if (duration === 0) {
1244
+ return Promise.resolve();
1245
+ }
1246
+ return this._ngZone.runOutsideAngular(() => {
1247
+ return new Promise(resolve => {
1248
+ /** @type {?} */
1249
+ const handler = (/** @type {?} */ (((event) => {
1250
+ if (!event || (event.target === this._preview && event.propertyName === 'transform')) {
1251
+ this._preview.removeEventListener('transitionend', handler);
1252
+ resolve();
1253
+ clearTimeout(timeout);
1254
+ }
1255
+ })));
1256
+ // If a transition is short enough, the browser might not fire the `transitionend` event.
1257
+ // Since we know how long it's supposed to take, add a timeout with a 50% buffer that'll
1258
+ // fire if the transition hasn't completed when it was supposed to.
1259
+ /** @type {?} */
1260
+ const timeout = setTimeout((/** @type {?} */ (handler)), duration * 1.5);
1261
+ this._preview.addEventListener('transitionend', handler);
1262
+ });
1263
+ });
1264
+ }
856
1265
  /**
857
1266
  * Creates an element that will be shown instead of the current element while dragging.
1267
+ * @private
858
1268
  * @return {?}
859
1269
  */
860
1270
  _createPlaceholderElement() {
@@ -865,13 +1275,14 @@ class CdkDrag {
865
1275
  placeholder = this._placeholderRef.rootNodes[0];
866
1276
  }
867
1277
  else {
868
- placeholder = /** @type {?} */ (this._rootElement.cloneNode(true));
1278
+ placeholder = deepCloneNode(this._rootElement);
869
1279
  }
870
1280
  placeholder.classList.add('cdk-drag-placeholder');
871
1281
  return placeholder;
872
1282
  }
873
1283
  /**
874
1284
  * Figures out the coordinates at which an element was picked up.
1285
+ * @private
875
1286
  * @param {?} referenceElement Element that initiated the dragging.
876
1287
  * @param {?} event Event that initiated the dragging.
877
1288
  * @return {?}
@@ -884,7 +1295,7 @@ class CdkDrag {
884
1295
  /** @type {?} */
885
1296
  const referenceRect = handleElement ? handleElement.getBoundingClientRect() : elementRect;
886
1297
  /** @type {?} */
887
- const point = this._isTouchEvent(event) ? event.targetTouches[0] : event;
1298
+ const point = isTouchEvent(event) ? event.targetTouches[0] : event;
888
1299
  /** @type {?} */
889
1300
  const x = point.pageX - referenceRect.left - this._scrollPosition.left;
890
1301
  /** @type {?} */
@@ -894,60 +1305,16 @@ class CdkDrag {
894
1305
  y: referenceRect.top - elementRect.top + y
895
1306
  };
896
1307
  }
897
- /**
898
- * Animates the preview element from its current position to the location of the drop placeholder.
899
- * @return {?} Promise that resolves when the animation completes.
900
- */
901
- _animatePreviewToPlaceholder() {
902
- // If the user hasn't moved yet, the transitionend event won't fire.
903
- if (!this._hasMoved) {
904
- return Promise.resolve();
905
- }
906
- /** @type {?} */
907
- const placeholderRect = this._placeholder.getBoundingClientRect();
908
- // Apply the class that adds a transition to the preview.
909
- this._preview.classList.add('cdk-drag-animating');
910
- // Move the preview to the placeholder position.
911
- this._preview.style.transform = getTransform(placeholderRect.left, placeholderRect.top);
912
- /** @type {?} */
913
- const duration = getTransformTransitionDurationInMs(this._preview);
914
- if (duration === 0) {
915
- return Promise.resolve();
916
- }
917
- return this._ngZone.runOutsideAngular(() => {
918
- return new Promise(resolve => {
919
- /** @type {?} */
920
- const handler = /** @type {?} */ (((event) => {
921
- if (!event || (event.target === this._preview && event.propertyName === 'transform')) {
922
- this._preview.removeEventListener('transitionend', handler);
923
- resolve();
924
- clearTimeout(timeout);
925
- }
926
- }));
927
- /** @type {?} */
928
- const timeout = setTimeout(/** @type {?} */ (handler), duration * 1.5);
929
- this._preview.addEventListener('transitionend', handler);
930
- });
931
- });
932
- }
933
- /**
934
- * Helper to remove an element from the DOM and to do all the necessary null checks.
935
- * @param {?} element Element to be removed.
936
- * @return {?}
937
- */
938
- _removeElement(element) {
939
- if (element && element.parentNode) {
940
- element.parentNode.removeChild(element);
941
- }
942
- }
943
1308
  /**
944
1309
  * Determines the point of the page that was touched by the user.
1310
+ * @private
945
1311
  * @param {?} event
946
1312
  * @return {?}
947
1313
  */
948
1314
  _getPointerPositionOnPage(event) {
1315
+ // `touches` will be empty for start/end events so we have to fall back to `changedTouches`.
949
1316
  /** @type {?} */
950
- const point = this._isTouchEvent(event) ? event.touches[0] : event;
1317
+ const point = isTouchEvent(event) ? (event.touches[0] || event.changedTouches[0]) : event;
951
1318
  return {
952
1319
  x: point.pageX - this._scrollPosition.left,
953
1320
  y: point.pageY - this._scrollPosition.top
@@ -955,6 +1322,7 @@ class CdkDrag {
955
1322
  }
956
1323
  /**
957
1324
  * Gets the pointer position on the page, accounting for any position constraints.
1325
+ * @private
958
1326
  * @param {?} event
959
1327
  * @return {?}
960
1328
  */
@@ -969,44 +1337,28 @@ class CdkDrag {
969
1337
  else if (this.lockAxis === 'y' || dropContainerLock === 'y') {
970
1338
  point.x = this._pickupPositionOnPage.x;
971
1339
  }
972
- return point;
973
- }
974
- /**
975
- * Determines whether an event is a touch event.
976
- * @param {?} event
977
- * @return {?}
978
- */
979
- _isTouchEvent(event) {
980
- return event.type.startsWith('touch');
981
- }
982
- /**
983
- * Destroys the preview element and its ViewRef.
984
- * @return {?}
985
- */
986
- _destroyPreview() {
987
- if (this._preview) {
988
- this._removeElement(this._preview);
989
- }
990
- if (this._previewRef) {
991
- this._previewRef.destroy();
992
- }
993
- this._preview = this._previewRef = /** @type {?} */ ((null));
994
- }
995
- /**
996
- * Destroys the placeholder element and its ViewRef.
997
- * @return {?}
998
- */
999
- _destroyPlaceholder() {
1000
- if (this._placeholder) {
1001
- this._removeElement(this._placeholder);
1002
- }
1003
- if (this._placeholderRef) {
1004
- 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);
1005
1356
  }
1006
- this._placeholder = this._placeholderRef = /** @type {?} */ ((null));
1357
+ return point;
1007
1358
  }
1008
1359
  /**
1009
1360
  * Updates the current drag delta, based on the user's current pointer position on the page.
1361
+ * @private
1010
1362
  * @param {?} pointerPositionOnPage
1011
1363
  * @return {?}
1012
1364
  */
@@ -1016,6 +1368,7 @@ class CdkDrag {
1016
1368
  const delta = this._pointerDirectionDelta;
1017
1369
  /** @type {?} */
1018
1370
  const positionSinceLastChange = this._pointerPositionAtLastDirectionChange;
1371
+ // Amount of pixels the user has dragged since the last time the direction changed.
1019
1372
  /** @type {?} */
1020
1373
  const changeX = Math.abs(x - positionSinceLastChange.x);
1021
1374
  /** @type {?} */
@@ -1035,75 +1388,31 @@ class CdkDrag {
1035
1388
  return delta;
1036
1389
  }
1037
1390
  /**
1038
- * Gets the root draggable element, based on the `rootElementSelector`.
1391
+ * Toggles the native drag interactions, based on how many handles are registered.
1392
+ * @private
1039
1393
  * @return {?}
1040
1394
  */
1041
- _getRootElement() {
1042
- if (this.rootElementSelector) {
1043
- /** @type {?} */
1044
- const selector = this.rootElementSelector;
1045
- /** @type {?} */
1046
- let currentElement = /** @type {?} */ (this.element.nativeElement.parentElement);
1047
- while (currentElement) {
1048
- // IE doesn't support `matches` so we have to fall back to `msMatchesSelector`.
1049
- if (currentElement.matches ? currentElement.matches(selector) :
1050
- (/** @type {?} */ (currentElement)).msMatchesSelector(selector)) {
1051
- return currentElement;
1052
- }
1053
- currentElement = currentElement.parentElement;
1054
- }
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);
1055
1403
  }
1056
- return this.element.nativeElement;
1057
1404
  }
1058
1405
  /**
1059
- * Unsubscribes from the global subscriptions.
1406
+ * Removes the manually-added event listeners from the root element.
1407
+ * @private
1408
+ * @param {?} element
1060
1409
  * @return {?}
1061
1410
  */
1062
- _removeSubscriptions() {
1063
- this._pointerMoveSubscription.unsubscribe();
1064
- this._pointerUpSubscription.unsubscribe();
1411
+ _removeRootElementListeners(element) {
1412
+ element.removeEventListener('mousedown', this._pointerDown, activeEventListenerOptions);
1413
+ element.removeEventListener('touchstart', this._pointerDown, passiveEventListenerOptions);
1065
1414
  }
1066
1415
  }
1067
- CdkDrag.decorators = [
1068
- { type: Directive, args: [{
1069
- selector: '[cdkDrag]',
1070
- exportAs: 'cdkDrag',
1071
- host: {
1072
- 'class': 'cdk-drag',
1073
- '[class.cdk-drag-dragging]': '_hasStartedDragging && _isDragging()',
1074
- },
1075
- providers: [{
1076
- provide: CDK_DRAG_PARENT,
1077
- useExisting: CdkDrag
1078
- }]
1079
- },] },
1080
- ];
1081
- /** @nocollapse */
1082
- CdkDrag.ctorParameters = () => [
1083
- { type: ElementRef },
1084
- { type: undefined, decorators: [{ type: Inject, args: [CDK_DROP_LIST_CONTAINER,] }, { type: Optional }, { type: SkipSelf }] },
1085
- { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] }] },
1086
- { type: NgZone },
1087
- { type: ViewContainerRef },
1088
- { type: ViewportRuler },
1089
- { type: DragDropRegistry },
1090
- { type: undefined, decorators: [{ type: Inject, args: [CDK_DRAG_CONFIG,] }] },
1091
- { type: Directionality, decorators: [{ type: Optional }] }
1092
- ];
1093
- CdkDrag.propDecorators = {
1094
- _handles: [{ type: ContentChildren, args: [CdkDragHandle, { descendants: true },] }],
1095
- _previewTemplate: [{ type: ContentChild, args: [CdkDragPreview,] }],
1096
- _placeholderTemplate: [{ type: ContentChild, args: [CdkDragPlaceholder,] }],
1097
- data: [{ type: Input, args: ['cdkDragData',] }],
1098
- lockAxis: [{ type: Input, args: ['cdkDragLockAxis',] }],
1099
- rootElementSelector: [{ type: Input, args: ['cdkDragRootElement',] }],
1100
- started: [{ type: Output, args: ['cdkDragStarted',] }],
1101
- ended: [{ type: Output, args: ['cdkDragEnded',] }],
1102
- entered: [{ type: Output, args: ['cdkDragEntered',] }],
1103
- exited: [{ type: Output, args: ['cdkDragExited',] }],
1104
- dropped: [{ type: Output, args: ['cdkDragDropped',] }],
1105
- moved: [{ type: Output, args: ['cdkDragMoved',] }]
1106
- };
1107
1416
  /**
1108
1417
  * Gets a 3d `transform` that can be applied to an element.
1109
1418
  * @param {?} x Desired position of the element along the X axis.
@@ -1111,310 +1420,704 @@ CdkDrag.propDecorators = {
1111
1420
  * @return {?}
1112
1421
  */
1113
1422
  function getTransform(x, y) {
1114
- return `translate3d(${x}px, ${y}px, 0)`;
1423
+ // Round the transforms since some browsers will
1424
+ // blur the elements for sub-pixel transforms.
1425
+ return `translate3d(${Math.round(x)}px, ${Math.round(y)}px, 0)`;
1115
1426
  }
1116
-
1117
1427
  /**
1118
- * @fileoverview added by tsickle
1119
- * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
1120
- */
1121
-
1122
- /**
1123
- * Moves an item one index in an array to another.
1124
- * @template T
1125
- * @param {?} array Array in which to move the item.
1126
- * @param {?} fromIndex Starting index of the item.
1127
- * @param {?} toIndex Index to which the item should be moved.
1428
+ * Creates a deep clone of an element.
1429
+ * @param {?} node
1128
1430
  * @return {?}
1129
1431
  */
1130
- function moveItemInArray(array, fromIndex, toIndex) {
1131
- /** @type {?} */
1132
- const from = clamp(fromIndex, array.length - 1);
1133
- /** @type {?} */
1134
- const to = clamp(toIndex, array.length - 1);
1135
- if (from === to) {
1136
- return;
1137
- }
1432
+ function deepCloneNode(node) {
1138
1433
  /** @type {?} */
1139
- const target = array[from];
1140
- /** @type {?} */
1141
- const delta = to < from ? -1 : 1;
1142
- for (let i = from; i !== to; i += delta) {
1143
- array[i] = array[i + delta];
1144
- }
1145
- array[to] = target;
1434
+ const clone = (/** @type {?} */ (node.cloneNode(true)));
1435
+ // Remove the `id` to avoid having multiple elements with the same id on the page.
1436
+ clone.removeAttribute('id');
1437
+ return clone;
1146
1438
  }
1147
1439
  /**
1148
- * Moves an item from one array to another.
1149
- * @template T
1150
- * @param {?} currentArray Array from which to transfer the item.
1151
- * @param {?} targetArray Array into which to put the item.
1152
- * @param {?} currentIndex Index of the item in its current array.
1153
- * @param {?} targetIndex Index at which to insert the item.
1440
+ * Clamps a value between a minimum and a maximum.
1441
+ * @param {?} value
1442
+ * @param {?} min
1443
+ * @param {?} max
1154
1444
  * @return {?}
1155
1445
  */
1156
- function transferArrayItem(currentArray, targetArray, currentIndex, targetIndex) {
1157
- /** @type {?} */
1158
- const from = clamp(currentIndex, currentArray.length - 1);
1159
- /** @type {?} */
1160
- const to = clamp(targetIndex, targetArray.length);
1161
- if (currentArray.length) {
1162
- targetArray.splice(to, 0, currentArray.splice(from, 1)[0]);
1163
- }
1446
+ function clamp$1(value, min, max) {
1447
+ return Math.max(min, Math.min(max, value));
1164
1448
  }
1165
1449
  /**
1166
- * Copies an item from one array to another, leaving it in its
1167
- * original position in current array.
1168
- * @template T
1169
- * @param {?} currentArray Array from which to copy the item.
1170
- * @param {?} targetArray Array into which is copy the item.
1171
- * @param {?} currentIndex Index of the item in its current array.
1172
- * @param {?} targetIndex Index at which to insert the item.
1173
- *
1450
+ * Helper to remove an element from the DOM and to do all the necessary null checks.
1451
+ * @param {?} element Element to be removed.
1174
1452
  * @return {?}
1175
1453
  */
1176
- function copyArrayItem(currentArray, targetArray, currentIndex, targetIndex) {
1177
- /** @type {?} */
1178
- const to = clamp(targetIndex, targetArray.length);
1179
- if (currentArray.length) {
1180
- targetArray.splice(to, 0, currentArray[currentIndex]);
1454
+ function removeElement(element) {
1455
+ if (element && element.parentNode) {
1456
+ element.parentNode.removeChild(element);
1181
1457
  }
1182
1458
  }
1183
1459
  /**
1184
- * Clamps a number between zero and a maximum.
1185
- * @param {?} value
1186
- * @param {?} max
1460
+ * Determines whether an event is a touch event.
1461
+ * @param {?} event
1187
1462
  * @return {?}
1188
1463
  */
1189
- function clamp(value, max) {
1190
- return Math.max(0, Math.min(max, value));
1464
+ function isTouchEvent(event) {
1465
+ return event.type.startsWith('touch');
1191
1466
  }
1192
1467
 
1193
1468
  /**
1194
1469
  * @fileoverview added by tsickle
1195
- * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
1470
+ * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
1196
1471
  */
1197
- /** *
1198
- * Counter used to generate unique ids for drop zones.
1199
- @type {?} */
1200
- let _uniqueIdCounter = 0;
1201
- /** *
1202
- * Proximity, as a ratio to width/height, at which a
1203
- * dragged item will affect the drop container.
1204
- @type {?} */
1205
- const DROP_PROXIMITY_THRESHOLD = 0.05;
1206
1472
  /**
1207
- * Container that wraps a set of draggable items.
1473
+ * Injection token that can be used to configure the behavior of `CdkDrag`.
1474
+ * @type {?}
1475
+ */
1476
+ const CDK_DRAG_CONFIG = new InjectionToken('CDK_DRAG_CONFIG', {
1477
+ providedIn: 'root',
1478
+ factory: CDK_DRAG_CONFIG_FACTORY
1479
+ });
1480
+ /**
1481
+ * \@docs-private
1482
+ * @return {?}
1483
+ */
1484
+ function CDK_DRAG_CONFIG_FACTORY() {
1485
+ return { dragStartThreshold: 5, pointerDirectionChangeThreshold: 5 };
1486
+ }
1487
+ /**
1488
+ * Element that can be moved inside a CdkDropList container.
1208
1489
  * @template T
1209
1490
  */
1210
- class CdkDropList {
1491
+ class CdkDrag {
1211
1492
  /**
1212
1493
  * @param {?} element
1494
+ * @param {?} dropContainer
1495
+ * @param {?} _document
1496
+ * @param {?} _ngZone
1497
+ * @param {?} _viewContainerRef
1498
+ * @param {?} _viewportRuler
1213
1499
  * @param {?} _dragDropRegistry
1214
- * @param {?} _changeDetectorRef
1215
- * @param {?=} _dir
1500
+ * @param {?} _config
1501
+ * @param {?} _dir
1216
1502
  */
1217
- constructor(element, _dragDropRegistry, _changeDetectorRef, _dir) {
1503
+ constructor(element, dropContainer, _document, _ngZone, _viewContainerRef, _viewportRuler, _dragDropRegistry, _config, _dir) {
1218
1504
  this.element = element;
1505
+ this.dropContainer = dropContainer;
1506
+ this._document = _document;
1507
+ this._ngZone = _ngZone;
1508
+ this._viewContainerRef = _viewContainerRef;
1509
+ this._viewportRuler = _viewportRuler;
1219
1510
  this._dragDropRegistry = _dragDropRegistry;
1220
- this._changeDetectorRef = _changeDetectorRef;
1511
+ this._config = _config;
1221
1512
  this._dir = _dir;
1222
1513
  /**
1223
- * Other draggable containers that this container is connected to and into which the
1224
- * container's items can be transferred. Can either be references to other drop containers,
1225
- * or their unique IDs.
1226
- */
1227
- this.connectedTo = [];
1228
- /**
1229
- * Direction in which the list is oriented.
1514
+ * Subscription to the stream that initializes the root element.
1230
1515
  */
1231
- this.orientation = 'vertical';
1516
+ this._rootElementInitSubscription = Subscription.EMPTY;
1517
+ this._disabled = false;
1232
1518
  /**
1233
- * Unique ID for the drop zone. Can be used as a reference
1234
- * in the `connectedTo` of another `CdkDropList`.
1519
+ * Emits when the user starts dragging the item.
1235
1520
  */
1236
- this.id = `cdk-drop-list-${_uniqueIdCounter++}`;
1521
+ this.started = new EventEmitter();
1237
1522
  /**
1238
- * Function that is used to determine whether an item
1239
- * is allowed to be moved into a drop container.
1523
+ * Emits when the user has released a drag item, before any animations have started.
1240
1524
  */
1241
- this.enterPredicate = () => true;
1525
+ this.released = new EventEmitter();
1242
1526
  /**
1243
- * Emits when the user drops an item inside the container.
1527
+ * Emits when the user stops dragging an item in the container.
1244
1528
  */
1245
- this.dropped = new EventEmitter();
1529
+ this.ended = new EventEmitter();
1246
1530
  /**
1247
- * 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.
1248
1532
  */
1249
1533
  this.entered = new EventEmitter();
1250
1534
  /**
1251
- * Emits when the user removes an item from the container
1252
- * by dragging it into another container.
1535
+ * Emits when the user removes the item its container by dragging it into another container.
1253
1536
  */
1254
1537
  this.exited = new EventEmitter();
1255
1538
  /**
1256
- * Whether an item in the container is being dragged.
1257
- */
1258
- this._dragging = false;
1259
- /**
1260
- * Cache of the dimensions of all the items and the sibling containers.
1539
+ * Emits when the user drops the item inside a container.
1261
1540
  */
1262
- this._positionCache = { items: [], siblings: [], self: /** @type {?} */ ({}) };
1541
+ this.dropped = new EventEmitter();
1263
1542
  /**
1264
- * Keeps track of the item that was last swapped with the dragged item, as
1265
- * 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.
1266
1545
  */
1267
- 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);
1268
1572
  }
1269
1573
  /**
1574
+ * Whether starting to drag this element is disabled.
1270
1575
  * @return {?}
1271
1576
  */
1272
- ngOnInit() {
1273
- this._dragDropRegistry.registerDropContainer(this);
1577
+ get disabled() {
1578
+ return this._disabled || (this.dropContainer && this.dropContainer.disabled);
1274
1579
  }
1275
1580
  /**
1581
+ * @param {?} value
1276
1582
  * @return {?}
1277
1583
  */
1278
- ngOnDestroy() {
1279
- this._dragDropRegistry.removeDropContainer(this);
1584
+ set disabled(value) {
1585
+ this._disabled = coerceBooleanProperty(value);
1280
1586
  }
1281
1587
  /**
1282
- * Starts dragging an item.
1588
+ * Returns the element that is being used as a placeholder
1589
+ * while the current element is being dragged.
1283
1590
  * @return {?}
1284
1591
  */
1285
- start() {
1286
- this._dragging = true;
1287
- this._activeDraggables = this._draggables.toArray();
1288
- this._cachePositions();
1289
- this._changeDetectorRef.markForCheck();
1592
+ getPlaceholderElement() {
1593
+ return this._dragRef.getPlaceholderElement();
1290
1594
  }
1291
1595
  /**
1292
- * Drops an item into this container.
1293
- * @param {?} item Item being dropped into the container.
1294
- * @param {?} currentIndex Index at which the item should be inserted.
1295
- * @param {?} previousContainer Container from which the item got dragged in.
1596
+ * Returns the root draggable element.
1296
1597
  * @return {?}
1297
1598
  */
1298
- drop(item, currentIndex, previousContainer) {
1299
- this._reset();
1300
- this.dropped.emit({
1301
- item,
1302
- currentIndex,
1303
- previousIndex: previousContainer.getItemIndex(item),
1304
- container: this,
1305
- // TODO(crisbeto): reconsider whether to make this null if the containers are the same.
1306
- previousContainer
1307
- });
1599
+ getRootElement() {
1600
+ return this._dragRef.getRootElement();
1308
1601
  }
1309
1602
  /**
1310
- * Emits an event to indicate that the user moved an item into the container.
1311
- * @param {?} item Item that was moved into the container.
1312
- * @param {?} pointerX Position of the item along the X axis.
1313
- * @param {?} pointerY Position of the item along the Y axis.
1603
+ * Resets a standalone drag item to its initial position.
1314
1604
  * @return {?}
1315
1605
  */
1316
- enter(item, pointerX, pointerY) {
1317
- this.entered.emit({ item, container: this });
1318
- this.start();
1319
- /** @type {?} */
1320
- const newIndex = this._getItemIndexFromPointerPosition(item, pointerX, pointerY);
1321
- /** @type {?} */
1322
- const currentIndex = this._activeDraggables.indexOf(item);
1323
- /** @type {?} */
1324
- const newPositionReference = this._activeDraggables[newIndex];
1325
- /** @type {?} */
1326
- const placeholder = item.getPlaceholderElement();
1327
- // Since the item may be in the `activeDraggables` already (e.g. if the user dragged it
1328
- // into another container and back again), we have to ensure that it isn't duplicated.
1329
- if (currentIndex > -1) {
1330
- this._activeDraggables.splice(currentIndex, 1);
1331
- }
1332
- // Don't use items that are being dragged as a reference, because
1333
- // their element has been moved down to the bottom of the body.
1334
- if (newPositionReference && !this._dragDropRegistry.isDragging(newPositionReference)) {
1335
- /** @type {?} */
1336
- const element = newPositionReference.getRootElement(); /** @type {?} */
1337
- ((element.parentElement)).insertBefore(placeholder, element);
1338
- this._activeDraggables.splice(newIndex, 0, item);
1339
- }
1340
- else {
1341
- this.element.nativeElement.appendChild(placeholder);
1342
- this._activeDraggables.push(item);
1343
- }
1344
- // The transform needs to be cleared so it doesn't throw off the measurements.
1345
- placeholder.style.transform = '';
1346
- // Note that the positions were already cached when we called `start` above,
1347
- // but we need to refresh them since the amount of items has changed.
1348
- this._cachePositions();
1606
+ reset() {
1607
+ this._dragRef.reset();
1349
1608
  }
1350
1609
  /**
1351
- * Removes an item from the container after it was dragged into another container by the user.
1352
- * @param {?} item Item that was dragged out.
1353
1610
  * @return {?}
1354
1611
  */
1355
- exit(item) {
1356
- this._reset();
1357
- this.exited.emit({ item, container: this });
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
+ });
1632
+ });
1358
1633
  }
1359
1634
  /**
1360
- * Figures out the index of an item in the container.
1361
- * @param {?} item Item whose index should be determined.
1362
1635
  * @return {?}
1363
1636
  */
1364
- getItemIndex(item) {
1365
- if (!this._dragging) {
1366
- return this._draggables.toArray().indexOf(item);
1367
- }
1368
- /** @type {?} */
1369
- const items = this.orientation === 'horizontal' && this._dir && this._dir.value === 'rtl' ?
1370
- this._positionCache.items.slice().reverse() : this._positionCache.items;
1371
- return findIndex(items, currentItem => currentItem.drag === item);
1637
+ ngOnDestroy() {
1638
+ this._rootElementInitSubscription.unsubscribe();
1639
+ this._dragRef.dispose();
1372
1640
  }
1373
1641
  /**
1374
- * Sorts an item inside the container based on its position.
1375
- * @param {?} item Item to be sorted.
1376
- * @param {?} pointerX Position of the item along the X axis.
1377
- * @param {?} pointerY Position of the item along the Y axis.
1378
- * @param {?} pointerDelta
1642
+ * Gets the root draggable element, based on the `rootElementSelector`.
1643
+ * @private
1379
1644
  * @return {?}
1380
1645
  */
1381
- _sortItem(item, pointerX, pointerY, pointerDelta) {
1382
- // Don't sort the item if it's out of range.
1383
- if (!this._isPointerNearDropContainer(pointerX, pointerY)) {
1384
- return;
1385
- }
1386
- /** @type {?} */
1387
- const siblings = this._positionCache.items;
1388
- /** @type {?} */
1389
- const newIndex = this._getItemIndexFromPointerPosition(item, pointerX, pointerY, pointerDelta);
1390
- if (newIndex === -1 && siblings.length > 0) {
1391
- return;
1392
- }
1393
- /** @type {?} */
1394
- const isHorizontal = this.orientation === 'horizontal';
1395
- /** @type {?} */
1396
- const currentIndex = findIndex(siblings, currentItem => currentItem.drag === item);
1397
- /** @type {?} */
1398
- const siblingAtNewPosition = siblings[newIndex];
1399
- /** @type {?} */
1400
- const currentPosition = siblings[currentIndex].clientRect;
1401
- /** @type {?} */
1402
- const newPosition = siblingAtNewPosition.clientRect;
1403
- /** @type {?} */
1404
- const delta = currentIndex > newIndex ? 1 : -1;
1405
- this._previousSwap.drag = siblingAtNewPosition.drag;
1406
- this._previousSwap.delta = isHorizontal ? pointerDelta.x : pointerDelta.y;
1646
+ _getRootElement() {
1407
1647
  /** @type {?} */
1408
- const itemOffset = this._getItemOffsetPx(currentPosition, newPosition, delta);
1648
+ const element = this.element.nativeElement;
1409
1649
  /** @type {?} */
1410
- const siblingOffset = this._getSiblingOffsetPx(currentIndex, siblings, delta);
1650
+ const rootElement = this.rootElementSelector ?
1651
+ getClosestMatchingAncestor(element, this.rootElementSelector) : null;
1652
+ return rootElement || element;
1653
+ }
1654
+ /**
1655
+ * Gets the boundary element, based on the `boundaryElementSelector`.
1656
+ * @private
1657
+ * @return {?}
1658
+ */
1659
+ _getBoundaryElement() {
1411
1660
  /** @type {?} */
1412
- const oldOrder = siblings.slice();
1413
- // Shuffle the array in place.
1414
- moveItemInArray(siblings, currentIndex, newIndex);
1415
- siblings.forEach((sibling, index) => {
1416
- // Don't do anything if the position hasn't changed.
1417
- if (oldOrder[index] === sibling) {
1661
+ const selector = this.boundaryElementSelector;
1662
+ return selector ? getClosestMatchingAncestor(this.element.nativeElement, selector) : null;
1663
+ }
1664
+ /**
1665
+ * Proxies the events from a DragRef to events that
1666
+ * match the interfaces of the CdkDrag outputs.
1667
+ * @private
1668
+ * @param {?} ref
1669
+ * @return {?}
1670
+ */
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];
2092
+ /** @type {?} */
2093
+ const currentPosition = siblings[currentIndex].clientRect;
2094
+ /** @type {?} */
2095
+ const newPosition = siblingAtNewPosition.clientRect;
2096
+ /** @type {?} */
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) {
1418
2121
  return;
1419
2122
  }
1420
2123
  /** @type {?} */
@@ -1431,225 +2134,560 @@ class CdkDropList {
1431
2134
  // Note that we shouldn't use `getBoundingClientRect` here to update the cache, because the
1432
2135
  // elements may be mid-animation which will give us a wrong result.
1433
2136
  if (isHorizontal) {
1434
- elementToOffset.style.transform = `translate3d(${sibling.offset}px, 0, 0)`;
1435
- this._adjustClientRect(sibling.clientRect, 0, offset);
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';
2229
+ /** @type {?} */
2230
+ const currentPosition = siblings[currentIndex].clientRect;
2231
+ /** @type {?} */
2232
+ const immediateSibling = siblings[currentIndex + delta * -1];
2233
+ /** @type {?} */
2234
+ let siblingOffset = currentPosition[isHorizontal ? 'width' : 'height'] * delta;
2235
+ if (immediateSibling) {
2236
+ /** @type {?} */
2237
+ const start = isHorizontal ? 'left' : 'top';
2238
+ /** @type {?} */
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];
1436
2246
  }
1437
2247
  else {
1438
- elementToOffset.style.transform = `translate3d(0, ${sibling.offset}px, 0)`;
1439
- 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
+ }
1440
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);
1441
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
+ }
1442
2496
  }
1443
2497
  /**
1444
- * Figures out whether an item should be moved into a sibling
1445
- * drop container, based on its current position.
1446
- * @param {?} item Drag item that is being moved.
1447
- * @param {?} x Position of the item along the X axis.
1448
- * @param {?} y Position of the item along the Y axis.
2498
+ * Whether starting a dragging sequence from this container is disabled.
1449
2499
  * @return {?}
1450
2500
  */
1451
- _getSiblingContainerFromPosition(item, x, y) {
1452
- /** @type {?} */
1453
- const result = this._positionCache.siblings
1454
- .find(sibling => isInsideClientRect(sibling.clientRect, x, y));
1455
- return result && result.drop.enterPredicate(item, result.drop) ? result.drop : null;
2501
+ get disabled() {
2502
+ return this._disabled || (!!this._group && this._group.disabled);
1456
2503
  }
1457
2504
  /**
1458
- * Checks whether an item that started in this container can be returned to it,
1459
- * after it was moved out into another container.
1460
- * @param {?} item Item that is being checked.
1461
- * @param {?} x Position of the item along the X axis.
1462
- * @param {?} y Position of the item along the Y axis.
2505
+ * @param {?} value
1463
2506
  * @return {?}
1464
2507
  */
1465
- _canReturnItem(item, x, y) {
1466
- return isInsideClientRect(this._positionCache.self, x, y) && this.enterPredicate(item, this);
2508
+ set disabled(value) {
2509
+ this._disabled = coerceBooleanProperty(value);
1467
2510
  }
1468
2511
  /**
1469
- * Refreshes the position cache of the items and sibling containers.
1470
2512
  * @return {?}
1471
2513
  */
1472
- _cachePositions() {
2514
+ ngOnDestroy() {
1473
2515
  /** @type {?} */
1474
- const isHorizontal = this.orientation === 'horizontal';
1475
- this._positionCache.items = this._activeDraggables
1476
- .map(drag => {
1477
- /** @type {?} */
1478
- const elementToMeasure = this._dragDropRegistry.isDragging(drag) ?
1479
- // If the element is being dragged, we have to measure the
1480
- // placeholder, because the element is hidden.
1481
- drag.getPlaceholderElement() :
1482
- drag.getRootElement();
1483
- /** @type {?} */
1484
- const clientRect = elementToMeasure.getBoundingClientRect();
1485
- return {
1486
- drag,
1487
- offset: 0,
1488
- // We need to clone the `clientRect` here, because all the values on it are readonly
1489
- // and we need to be able to update them. Also we can't use a spread here, because
1490
- // the values on a `ClientRect` aren't own properties. See:
1491
- // https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect#Notes
1492
- clientRect: {
1493
- top: clientRect.top,
1494
- right: clientRect.right,
1495
- bottom: clientRect.bottom,
1496
- left: clientRect.left,
1497
- width: clientRect.width,
1498
- height: clientRect.height
1499
- }
1500
- };
1501
- })
1502
- .sort((a, b) => {
1503
- return isHorizontal ? a.clientRect.left - b.clientRect.left :
1504
- a.clientRect.top - b.clientRect.top;
1505
- });
1506
- this._positionCache.siblings = coerceArray(this.connectedTo)
1507
- .map(drop => typeof drop === 'string' ? /** @type {?} */ ((this._dragDropRegistry.getDropContainer(drop))) : drop)
1508
- .filter(drop => drop && drop !== this)
1509
- .map(drop => ({ drop, clientRect: drop.element.nativeElement.getBoundingClientRect() }));
1510
- this._positionCache.self = this.element.nativeElement.getBoundingClientRect();
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
+ }
1511
2524
  }
1512
2525
  /**
1513
- * Resets the container to its initial state.
2526
+ * Starts dragging an item.
1514
2527
  * @return {?}
1515
2528
  */
1516
- _reset() {
1517
- this._dragging = false;
1518
- // TODO(crisbeto): may have to wait for the animations to finish.
1519
- this._activeDraggables.forEach(item => item.getRootElement().style.transform = '');
1520
- this._activeDraggables = [];
1521
- this._positionCache.items = [];
1522
- this._positionCache.siblings = [];
1523
- this._previousSwap.drag = null;
1524
- this._previousSwap.delta = 0;
2529
+ start() {
2530
+ this._dropListRef.start();
1525
2531
  }
1526
2532
  /**
1527
- * Updates the top/left positions of a `ClientRect`, as well as their bottom/right counterparts.
1528
- * @param {?} clientRect `ClientRect` that should be updated.
1529
- * @param {?} top Amount to add to the `top` position.
1530
- * @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.
1531
2539
  * @return {?}
1532
2540
  */
1533
- _adjustClientRect(clientRect, top, left) {
1534
- clientRect.top += top;
1535
- clientRect.bottom = clientRect.top + clientRect.height;
1536
- clientRect.left += left;
1537
- clientRect.right = clientRect.left + clientRect.width;
2541
+ drop(item, currentIndex, previousContainer, isPointerOverContainer) {
2542
+ this._dropListRef.drop(item._dragRef, currentIndex, ((/** @type {?} */ (previousContainer)))._dropListRef, isPointerOverContainer);
1538
2543
  }
1539
2544
  /**
1540
- * Gets the index of an item in the drop container, based on the position of the user's pointer.
1541
- * @param {?} item Item that is being sorted.
1542
- * @param {?} pointerX Position of the user's pointer along the X axis.
1543
- * @param {?} pointerY Position of the user's pointer along the Y axis.
1544
- * @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.
1545
2549
  * @return {?}
1546
2550
  */
1547
- _getItemIndexFromPointerPosition(item, pointerX, pointerY, delta) {
1548
- /** @type {?} */
1549
- const isHorizontal = this.orientation === 'horizontal';
1550
- return findIndex(this._positionCache.items, ({ drag, clientRect }, _, array) => {
1551
- if (drag === item) {
1552
- // If there's only one item left in the container, it must be
1553
- // the dragged item itself so we use it as a reference.
1554
- return array.length < 2;
1555
- }
1556
- if (delta) {
1557
- /** @type {?} */
1558
- const direction = isHorizontal ? delta.x : delta.y;
1559
- // If the user is still hovering over the same item as last time, and they didn't change
1560
- // the direction in which they're dragging, we don't consider it a direction swap.
1561
- if (drag === this._previousSwap.drag && direction === this._previousSwap.delta) {
1562
- return false;
1563
- }
1564
- }
1565
- return isHorizontal ?
1566
- // Round these down since most browsers report client rects with
1567
- // sub-pixel precision, whereas the pointer coordinates are rounded to pixels.
1568
- pointerX >= Math.floor(clientRect.left) && pointerX <= Math.floor(clientRect.right) :
1569
- pointerY >= Math.floor(clientRect.top) && pointerY <= Math.floor(clientRect.bottom);
1570
- });
2551
+ enter(item, pointerX, pointerY) {
2552
+ this._dropListRef.enter(item._dragRef, pointerX, pointerY);
1571
2553
  }
1572
2554
  /**
1573
- * Checks whether the pointer coordinates are close to the drop container.
1574
- * @param {?} pointerX Coordinates along the X axis.
1575
- * @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.
1576
2557
  * @return {?}
1577
2558
  */
1578
- _isPointerNearDropContainer(pointerX, pointerY) {
1579
- const { top, right, bottom, left, width, height } = this._positionCache.self;
1580
- /** @type {?} */
1581
- const xThreshold = width * DROP_PROXIMITY_THRESHOLD;
1582
- /** @type {?} */
1583
- const yThreshold = height * DROP_PROXIMITY_THRESHOLD;
1584
- return pointerY > top - yThreshold && pointerY < bottom + yThreshold &&
1585
- pointerX > left - xThreshold && pointerX < right + xThreshold;
2559
+ exit(item) {
2560
+ this._dropListRef.exit(item._dragRef);
1586
2561
  }
1587
2562
  /**
1588
- * Gets the offset in pixels by which the item that is being dragged should be moved.
1589
- * @param {?} currentPosition Current position of the item.
1590
- * @param {?} newPosition Position of the item where the current item should be moved.
1591
- * @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.
1592
2565
  * @return {?}
1593
2566
  */
1594
- _getItemOffsetPx(currentPosition, newPosition, delta) {
1595
- /** @type {?} */
1596
- const isHorizontal = this.orientation === 'horizontal';
1597
- /** @type {?} */
1598
- let itemOffset = isHorizontal ? newPosition.left - currentPosition.left :
1599
- newPosition.top - currentPosition.top;
1600
- // Account for differences in the item width/height.
1601
- if (delta === -1) {
1602
- itemOffset += isHorizontal ? newPosition.width - currentPosition.width :
1603
- newPosition.height - currentPosition.height;
1604
- }
1605
- return itemOffset;
2567
+ getItemIndex(item) {
2568
+ return this._dropListRef.getItemIndex(item._dragRef);
1606
2569
  }
1607
2570
  /**
1608
- * Gets the offset in pixels by which the items that aren't being dragged should be moved.
1609
- * @param {?} currentIndex Index of the item currently being dragged.
1610
- * @param {?} siblings All of the items in the list.
1611
- * @param {?} delta Direction in which the user is moving.
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.
1612
2576
  * @return {?}
1613
2577
  */
1614
- _getSiblingOffsetPx(currentIndex, siblings, delta) {
1615
- /** @type {?} */
1616
- const isHorizontal = this.orientation === 'horizontal';
1617
- /** @type {?} */
1618
- const currentPosition = siblings[currentIndex].clientRect;
1619
- /** @type {?} */
1620
- const immediateSibling = siblings[currentIndex + delta * -1];
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) {
1621
2590
  /** @type {?} */
1622
- let siblingOffset = currentPosition[isHorizontal ? 'width' : 'height'] * delta;
1623
- if (immediateSibling) {
1624
- /** @type {?} */
1625
- const start = isHorizontal ? 'left' : 'top';
2591
+ const result = this._dropListRef._getSiblingContainerFromPosition(item._dragRef, x, y);
2592
+ return result ? result.data : null;
2593
+ }
2594
+ /**
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.
2605
+ * @private
2606
+ * @param {?} ref
2607
+ * @return {?}
2608
+ */
2609
+ _syncInputs(ref) {
2610
+ ref.beforeStarted.subscribe(() => {
1626
2611
  /** @type {?} */
1627
- const end = isHorizontal ? 'right' : 'bottom';
1628
- // Get the spacing between the start of the current item and the end of the one immediately
1629
- // after it in the direction in which the user is dragging, or vice versa. We add it to the
1630
- // offset in order to push the element to where it will be when it's inline and is influenced
1631
- // by the `margin` of its siblings.
1632
- if (delta === -1) {
1633
- siblingOffset -= immediateSibling.clientRect[start] - currentPosition[end];
1634
- }
1635
- else {
1636
- 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
+ });
1637
2622
  }
1638
- }
1639
- 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
+ });
2629
+ }
2630
+ /**
2631
+ * Proxies the events from a DropListRef to events that
2632
+ * match the interfaces of the CdkDropList outputs.
2633
+ * @private
2634
+ * @param {?} ref
2635
+ * @return {?}
2636
+ */
2637
+ _proxyEvents(ref) {
2638
+ ref.beforeStarted.subscribe(() => {
2639
+ this._changeDetectorRef.markForCheck();
2640
+ });
2641
+ ref.entered.subscribe(event => {
2642
+ this.entered.emit({
2643
+ container: this,
2644
+ item: event.item.data
2645
+ });
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
+ });
1640
2671
  }
1641
2672
  }
2673
+ /**
2674
+ * Keeps track of the drop lists that are currently on the page.
2675
+ */
2676
+ CdkDropList._dropLists = [];
1642
2677
  CdkDropList.decorators = [
1643
2678
  { type: Directive, args: [{
1644
2679
  selector: '[cdkDropList], cdk-drop-list',
1645
2680
  exportAs: 'cdkDropList',
1646
2681
  providers: [
2682
+ // Prevent child drop lists from picking up the same group as their parent.
2683
+ { provide: CdkDropListGroup, useValue: ɵ0 },
1647
2684
  { provide: CDK_DROP_LIST_CONTAINER, useExisting: CdkDropList },
1648
2685
  ],
1649
2686
  host: {
1650
2687
  'class': 'cdk-drop-list',
1651
2688
  '[id]': 'id',
1652
- '[class.cdk-drop-list-dragging]': '_dragging'
2689
+ '[class.cdk-drop-list-dragging]': '_dropListRef.isDragging()',
2690
+ '[class.cdk-drop-list-receiving]': '_dropListRef.isReceiving()',
1653
2691
  }
1654
2692
  },] },
1655
2693
  ];
@@ -1658,7 +2696,9 @@ CdkDropList.ctorParameters = () => [
1658
2696
  { type: ElementRef },
1659
2697
  { type: DragDropRegistry },
1660
2698
  { type: ChangeDetectorRef },
1661
- { type: Directionality, decorators: [{ type: Optional }] }
2699
+ { type: Directionality, decorators: [{ type: Optional }] },
2700
+ { type: CdkDropListGroup, decorators: [{ type: Optional }, { type: SkipSelf }] },
2701
+ { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [DOCUMENT,] }] }
1662
2702
  ];
1663
2703
  CdkDropList.propDecorators = {
1664
2704
  _draggables: [{ type: ContentChildren, args: [forwardRef(() => CdkDrag),] }],
@@ -1667,42 +2707,17 @@ CdkDropList.propDecorators = {
1667
2707
  orientation: [{ type: Input, args: ['cdkDropListOrientation',] }],
1668
2708
  id: [{ type: Input }],
1669
2709
  lockAxis: [{ type: Input, args: ['cdkDropListLockAxis',] }],
2710
+ disabled: [{ type: Input, args: ['cdkDropListDisabled',] }],
1670
2711
  enterPredicate: [{ type: Input, args: ['cdkDropListEnterPredicate',] }],
1671
2712
  dropped: [{ type: Output, args: ['cdkDropListDropped',] }],
1672
2713
  entered: [{ type: Output, args: ['cdkDropListEntered',] }],
1673
- exited: [{ type: Output, args: ['cdkDropListExited',] }]
2714
+ exited: [{ type: Output, args: ['cdkDropListExited',] }],
2715
+ sorted: [{ type: Output, args: ['cdkDropListSorted',] }]
1674
2716
  };
1675
- /**
1676
- * Finds the index of an item that matches a predicate function. Used as an equivalent
1677
- * of `Array.prototype.find` which isn't part of the standard Google typings.
1678
- * @template T
1679
- * @param {?} array Array in which to look for matches.
1680
- * @param {?} predicate Function used to determine whether an item is a match.
1681
- * @return {?}
1682
- */
1683
- function findIndex(array, predicate) {
1684
- for (let i = 0; i < array.length; i++) {
1685
- if (predicate(array[i], i, array)) {
1686
- return i;
1687
- }
1688
- }
1689
- return -1;
1690
- }
1691
- /**
1692
- * Checks whether some coordinates are within a `ClientRect`.
1693
- * @param {?} clientRect ClientRect that is being checked.
1694
- * @param {?} x Coordinates along the X axis.
1695
- * @param {?} y Coordinates along the Y axis.
1696
- * @return {?}
1697
- */
1698
- function isInsideClientRect(clientRect, x, y) {
1699
- const { top, bottom, left, right } = clientRect;
1700
- return y >= top && y <= bottom && x >= left && x <= right;
1701
- }
1702
2717
 
1703
2718
  /**
1704
2719
  * @fileoverview added by tsickle
1705
- * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
2720
+ * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
1706
2721
  */
1707
2722
  class DragDropModule {
1708
2723
  }
@@ -1710,6 +2725,7 @@ DragDropModule.decorators = [
1710
2725
  { type: NgModule, args: [{
1711
2726
  declarations: [
1712
2727
  CdkDropList,
2728
+ CdkDropListGroup,
1713
2729
  CdkDrag,
1714
2730
  CdkDragHandle,
1715
2731
  CdkDragPreview,
@@ -1717,6 +2733,7 @@ DragDropModule.decorators = [
1717
2733
  ],
1718
2734
  exports: [
1719
2735
  CdkDropList,
2736
+ CdkDropListGroup,
1720
2737
  CdkDrag,
1721
2738
  CdkDragHandle,
1722
2739
  CdkDragPreview,
@@ -1727,13 +2744,13 @@ DragDropModule.decorators = [
1727
2744
 
1728
2745
  /**
1729
2746
  * @fileoverview added by tsickle
1730
- * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
2747
+ * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
1731
2748
  */
1732
2749
 
1733
2750
  /**
1734
2751
  * @fileoverview added by tsickle
1735
- * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
2752
+ * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
1736
2753
  */
1737
2754
 
1738
- export { CdkDropList, 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 };
1739
2756
  //# sourceMappingURL=drag-drop.js.map