@kato-lee/cdk 14.2.7

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 (374) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +8 -0
  3. package/_index.scss +8 -0
  4. package/a11y/_index.import.scss +2 -0
  5. package/a11y/_index.scss +102 -0
  6. package/a11y/index.d.ts +1212 -0
  7. package/a11y-prebuilt.css +1 -0
  8. package/accordion/index.d.ts +140 -0
  9. package/bidi/index.d.ts +80 -0
  10. package/clipboard/index.d.ts +115 -0
  11. package/coercion/index.d.ts +67 -0
  12. package/collections/index.d.ts +374 -0
  13. package/dialog/index.d.ts +469 -0
  14. package/drag-drop/index.d.ts +1614 -0
  15. package/esm2020/a11y/a11y-module.mjs +32 -0
  16. package/esm2020/a11y/a11y_public_index.mjs +5 -0
  17. package/esm2020/a11y/aria-describer/aria-describer.mjs +232 -0
  18. package/esm2020/a11y/aria-describer/aria-reference.mjs +44 -0
  19. package/esm2020/a11y/fake-event-detection.mjs +31 -0
  20. package/esm2020/a11y/focus-monitor/focus-monitor.mjs +451 -0
  21. package/esm2020/a11y/focus-trap/configurable-focus-trap-config.mjs +9 -0
  22. package/esm2020/a11y/focus-trap/configurable-focus-trap-factory.mjs +53 -0
  23. package/esm2020/a11y/focus-trap/configurable-focus-trap.mjs +51 -0
  24. package/esm2020/a11y/focus-trap/event-listener-inert-strategy.mjs +61 -0
  25. package/esm2020/a11y/focus-trap/focus-trap-inert-strategy.mjs +11 -0
  26. package/esm2020/a11y/focus-trap/focus-trap-manager.mjs +53 -0
  27. package/esm2020/a11y/focus-trap/focus-trap.mjs +402 -0
  28. package/esm2020/a11y/high-contrast-mode/high-contrast-mode-detector.mjs +109 -0
  29. package/esm2020/a11y/index.mjs +9 -0
  30. package/esm2020/a11y/input-modality/input-modality-detector.mjs +176 -0
  31. package/esm2020/a11y/interactivity-checker/interactivity-checker.mjs +238 -0
  32. package/esm2020/a11y/key-manager/activedescendant-key-manager.mjs +20 -0
  33. package/esm2020/a11y/key-manager/focus-key-manager.mjs +29 -0
  34. package/esm2020/a11y/key-manager/list-key-manager.mjs +321 -0
  35. package/esm2020/a11y/live-announcer/live-announcer-tokens.mjs +19 -0
  36. package/esm2020/a11y/live-announcer/live-announcer.mjs +178 -0
  37. package/esm2020/a11y/public-api.mjs +26 -0
  38. package/esm2020/accordion/accordion-item.mjs +167 -0
  39. package/esm2020/accordion/accordion-module.mjs +24 -0
  40. package/esm2020/accordion/accordion.mjs +70 -0
  41. package/esm2020/accordion/accordion_public_index.mjs +5 -0
  42. package/esm2020/accordion/index.mjs +9 -0
  43. package/esm2020/accordion/public-api.mjs +11 -0
  44. package/esm2020/bidi/bidi-module.mjs +23 -0
  45. package/esm2020/bidi/bidi_public_index.mjs +5 -0
  46. package/esm2020/bidi/dir-document-token.mjs +33 -0
  47. package/esm2020/bidi/dir.mjs +69 -0
  48. package/esm2020/bidi/directionality.mjs +52 -0
  49. package/esm2020/bidi/index.mjs +9 -0
  50. package/esm2020/bidi/public-api.mjs +12 -0
  51. package/esm2020/clipboard/clipboard-module.mjs +23 -0
  52. package/esm2020/clipboard/clipboard.mjs +53 -0
  53. package/esm2020/clipboard/clipboard_public_index.mjs +5 -0
  54. package/esm2020/clipboard/copy-to-clipboard.mjs +99 -0
  55. package/esm2020/clipboard/index.mjs +9 -0
  56. package/esm2020/clipboard/pending-copy.mjs +69 -0
  57. package/esm2020/clipboard/public-api.mjs +12 -0
  58. package/esm2020/coercion/array.mjs +11 -0
  59. package/esm2020/coercion/boolean-property.mjs +12 -0
  60. package/esm2020/coercion/css-pixel-value.mjs +15 -0
  61. package/esm2020/coercion/element.mjs +16 -0
  62. package/esm2020/coercion/index.mjs +9 -0
  63. package/esm2020/coercion/number-property.mjs +21 -0
  64. package/esm2020/coercion/public-api.mjs +14 -0
  65. package/esm2020/coercion/string-array.mjs +38 -0
  66. package/esm2020/collections/array-data-source.mjs +21 -0
  67. package/esm2020/collections/collection-viewer.mjs +9 -0
  68. package/esm2020/collections/collections_public_index.mjs +5 -0
  69. package/esm2020/collections/data-source.mjs +19 -0
  70. package/esm2020/collections/dispose-view-repeater-strategy.mjs +47 -0
  71. package/esm2020/collections/index.mjs +9 -0
  72. package/esm2020/collections/public-api.mjs +17 -0
  73. package/esm2020/collections/recycle-view-repeater-strategy.mjs +128 -0
  74. package/esm2020/collections/selection-model.mjs +216 -0
  75. package/esm2020/collections/tree-adapter.mjs +9 -0
  76. package/esm2020/collections/unique-selection-dispatcher.mjs +55 -0
  77. package/esm2020/collections/view-repeater.mjs +14 -0
  78. package/esm2020/dialog/dialog-config.mjs +63 -0
  79. package/esm2020/dialog/dialog-container.mjs +278 -0
  80. package/esm2020/dialog/dialog-injectors.mjs +26 -0
  81. package/esm2020/dialog/dialog-module.mjs +42 -0
  82. package/esm2020/dialog/dialog-ref.mjs +76 -0
  83. package/esm2020/dialog/dialog.mjs +301 -0
  84. package/esm2020/dialog/dialog_public_index.mjs +5 -0
  85. package/esm2020/dialog/index.mjs +9 -0
  86. package/esm2020/dialog/public-api.mjs +14 -0
  87. package/esm2020/drag-drop/directives/assertions.mjs +18 -0
  88. package/esm2020/drag-drop/directives/config.mjs +14 -0
  89. package/esm2020/drag-drop/directives/drag-handle.mjs +66 -0
  90. package/esm2020/drag-drop/directives/drag-placeholder.mjs +36 -0
  91. package/esm2020/drag-drop/directives/drag-preview.mjs +47 -0
  92. package/esm2020/drag-drop/directives/drag.mjs +487 -0
  93. package/esm2020/drag-drop/directives/drop-list-group.mjs +53 -0
  94. package/esm2020/drag-drop/directives/drop-list.mjs +345 -0
  95. package/esm2020/drag-drop/dom/client-rect.mjs +64 -0
  96. package/esm2020/drag-drop/dom/clone-node.mjs +65 -0
  97. package/esm2020/drag-drop/dom/parent-position-tracker.mjs +76 -0
  98. package/esm2020/drag-drop/dom/styling.mjs +69 -0
  99. package/esm2020/drag-drop/dom/transition-duration.mjs +36 -0
  100. package/esm2020/drag-drop/drag-drop-module.mjs +57 -0
  101. package/esm2020/drag-drop/drag-drop-registry.mjs +231 -0
  102. package/esm2020/drag-drop/drag-drop.mjs +57 -0
  103. package/esm2020/drag-drop/drag-drop_public_index.mjs +5 -0
  104. package/esm2020/drag-drop/drag-events.mjs +9 -0
  105. package/esm2020/drag-drop/drag-parent.mjs +16 -0
  106. package/esm2020/drag-drop/drag-ref.mjs +1146 -0
  107. package/esm2020/drag-drop/drag-utils.mjs +60 -0
  108. package/esm2020/drag-drop/drop-list-ref.mjs +577 -0
  109. package/esm2020/drag-drop/index.mjs +9 -0
  110. package/esm2020/drag-drop/public-api.mjs +23 -0
  111. package/esm2020/drag-drop/sorting/drop-list-sort-strategy.mjs +9 -0
  112. package/esm2020/drag-drop/sorting/single-axis-sort-strategy.mjs +341 -0
  113. package/esm2020/index.mjs +9 -0
  114. package/esm2020/keycodes/index.mjs +9 -0
  115. package/esm2020/keycodes/keycodes.mjs +127 -0
  116. package/esm2020/keycodes/keycodes_public_index.mjs +5 -0
  117. package/esm2020/keycodes/modifiers.mjs +18 -0
  118. package/esm2020/keycodes/public-api.mjs +10 -0
  119. package/esm2020/layout/breakpoints-observer.mjs +105 -0
  120. package/esm2020/layout/breakpoints.mjs +29 -0
  121. package/esm2020/layout/index.mjs +9 -0
  122. package/esm2020/layout/layout-module.mjs +19 -0
  123. package/esm2020/layout/layout_public_index.mjs +5 -0
  124. package/esm2020/layout/media-matcher.mjs +85 -0
  125. package/esm2020/layout/public-api.mjs +12 -0
  126. package/esm2020/listbox/index.mjs +9 -0
  127. package/esm2020/listbox/listbox-module.mjs +24 -0
  128. package/esm2020/listbox/listbox.mjs +872 -0
  129. package/esm2020/listbox/listbox_public_index.mjs +5 -0
  130. package/esm2020/listbox/public-api.mjs +10 -0
  131. package/esm2020/menu/context-menu-trigger.mjs +212 -0
  132. package/esm2020/menu/index.mjs +9 -0
  133. package/esm2020/menu/menu-aim.mjs +203 -0
  134. package/esm2020/menu/menu-bar.mjs +133 -0
  135. package/esm2020/menu/menu-base.mjs +187 -0
  136. package/esm2020/menu/menu-errors.mjs +22 -0
  137. package/esm2020/menu/menu-group.mjs +30 -0
  138. package/esm2020/menu/menu-interface.mjs +11 -0
  139. package/esm2020/menu/menu-item-checkbox.mjs +49 -0
  140. package/esm2020/menu/menu-item-radio.mjs +71 -0
  141. package/esm2020/menu/menu-item-selectable.mjs +42 -0
  142. package/esm2020/menu/menu-item.mjs +267 -0
  143. package/esm2020/menu/menu-module.mjs +62 -0
  144. package/esm2020/menu/menu-stack.mjs +156 -0
  145. package/esm2020/menu/menu-trigger-base.mjs +107 -0
  146. package/esm2020/menu/menu-trigger.mjs +291 -0
  147. package/esm2020/menu/menu.mjs +134 -0
  148. package/esm2020/menu/menu_public_index.mjs +5 -0
  149. package/esm2020/menu/pointer-focus-tracker.mjs +51 -0
  150. package/esm2020/menu/public-api.mjs +24 -0
  151. package/esm2020/observers/index.mjs +9 -0
  152. package/esm2020/observers/observe-content.mjs +187 -0
  153. package/esm2020/observers/observers_public_index.mjs +5 -0
  154. package/esm2020/observers/public-api.mjs +9 -0
  155. package/esm2020/overlay/dispatchers/base-overlay-dispatcher.mjs +52 -0
  156. package/esm2020/overlay/dispatchers/index.mjs +10 -0
  157. package/esm2020/overlay/dispatchers/overlay-keyboard-dispatcher.mjs +81 -0
  158. package/esm2020/overlay/dispatchers/overlay-outside-click-dispatcher.mjs +138 -0
  159. package/esm2020/overlay/fullscreen-overlay-container.mjs +94 -0
  160. package/esm2020/overlay/index.mjs +9 -0
  161. package/esm2020/overlay/overlay-config.mjs +45 -0
  162. package/esm2020/overlay/overlay-container.mjs +81 -0
  163. package/esm2020/overlay/overlay-directives.mjs +427 -0
  164. package/esm2020/overlay/overlay-module.mjs +29 -0
  165. package/esm2020/overlay/overlay-ref.mjs +427 -0
  166. package/esm2020/overlay/overlay-reference.mjs +9 -0
  167. package/esm2020/overlay/overlay.mjs +125 -0
  168. package/esm2020/overlay/overlay_public_index.mjs +5 -0
  169. package/esm2020/overlay/position/connected-position.mjs +88 -0
  170. package/esm2020/overlay/position/flexible-connected-position-strategy.mjs +985 -0
  171. package/esm2020/overlay/position/global-position-strategy.mjs +237 -0
  172. package/esm2020/overlay/position/overlay-position-builder.mjs +50 -0
  173. package/esm2020/overlay/position/position-strategy.mjs +9 -0
  174. package/esm2020/overlay/position/scroll-clip.mjs +40 -0
  175. package/esm2020/overlay/public-api.mjs +22 -0
  176. package/esm2020/overlay/scroll/block-scroll-strategy.mjs +80 -0
  177. package/esm2020/overlay/scroll/close-scroll-strategy.mjs +61 -0
  178. package/esm2020/overlay/scroll/index.mjs +14 -0
  179. package/esm2020/overlay/scroll/noop-scroll-strategy.mjs +17 -0
  180. package/esm2020/overlay/scroll/reposition-scroll-strategy.mjs +61 -0
  181. package/esm2020/overlay/scroll/scroll-strategy-options.mjs +55 -0
  182. package/esm2020/overlay/scroll/scroll-strategy.mjs +14 -0
  183. package/esm2020/platform/features/input-types.mjs +59 -0
  184. package/esm2020/platform/features/passive-listeners.mjs +36 -0
  185. package/esm2020/platform/features/scrolling.mjs +85 -0
  186. package/esm2020/platform/features/shadow-dom.mjs +54 -0
  187. package/esm2020/platform/features/test-environment.mjs +24 -0
  188. package/esm2020/platform/index.mjs +9 -0
  189. package/esm2020/platform/platform-module.mjs +19 -0
  190. package/esm2020/platform/platform.mjs +85 -0
  191. package/esm2020/platform/platform_public_index.mjs +5 -0
  192. package/esm2020/platform/public-api.mjs +15 -0
  193. package/esm2020/portal/dom-portal-outlet.mjs +158 -0
  194. package/esm2020/portal/index.mjs +9 -0
  195. package/esm2020/portal/portal-directives.mjs +246 -0
  196. package/esm2020/portal/portal-errors.mjs +51 -0
  197. package/esm2020/portal/portal-injector.mjs +28 -0
  198. package/esm2020/portal/portal.mjs +188 -0
  199. package/esm2020/portal/portal_public_index.mjs +5 -0
  200. package/esm2020/portal/public-api.mjs +12 -0
  201. package/esm2020/public-api.mjs +9 -0
  202. package/esm2020/scrolling/fixed-size-virtual-scroll.mjs +217 -0
  203. package/esm2020/scrolling/index.mjs +9 -0
  204. package/esm2020/scrolling/public-api.mjs +20 -0
  205. package/esm2020/scrolling/scroll-dispatcher.mjs +163 -0
  206. package/esm2020/scrolling/scrollable.mjs +176 -0
  207. package/esm2020/scrolling/scrolling-module.mjs +67 -0
  208. package/esm2020/scrolling/scrolling_public_index.mjs +5 -0
  209. package/esm2020/scrolling/viewport-ruler.mjs +146 -0
  210. package/esm2020/scrolling/virtual-for-of.mjs +298 -0
  211. package/esm2020/scrolling/virtual-scroll-repeater.mjs +9 -0
  212. package/esm2020/scrolling/virtual-scroll-strategy.mjs +11 -0
  213. package/esm2020/scrolling/virtual-scroll-viewport.mjs +437 -0
  214. package/esm2020/scrolling/virtual-scrollable-element.mjs +41 -0
  215. package/esm2020/scrolling/virtual-scrollable-window.mjs +40 -0
  216. package/esm2020/scrolling/virtual-scrollable.mjs +40 -0
  217. package/esm2020/stepper/index.mjs +9 -0
  218. package/esm2020/stepper/public-api.mjs +13 -0
  219. package/esm2020/stepper/step-header.mjs +30 -0
  220. package/esm2020/stepper/step-label.mjs +23 -0
  221. package/esm2020/stepper/stepper-button.mjs +56 -0
  222. package/esm2020/stepper/stepper-module.mjs +40 -0
  223. package/esm2020/stepper/stepper.mjs +458 -0
  224. package/esm2020/stepper/stepper_public_index.mjs +5 -0
  225. package/esm2020/table/can-stick.mjs +44 -0
  226. package/esm2020/table/cell.mjs +217 -0
  227. package/esm2020/table/coalesced-style-scheduler.mjs +91 -0
  228. package/esm2020/table/index.mjs +9 -0
  229. package/esm2020/table/public-api.mjs +20 -0
  230. package/esm2020/table/row.mjs +262 -0
  231. package/esm2020/table/sticky-position-listener.mjs +11 -0
  232. package/esm2020/table/sticky-styler.mjs +345 -0
  233. package/esm2020/table/table-errors.mjs +67 -0
  234. package/esm2020/table/table-module.mjs +94 -0
  235. package/esm2020/table/table.mjs +1065 -0
  236. package/esm2020/table/table_public_index.mjs +5 -0
  237. package/esm2020/table/text-column.mjs +153 -0
  238. package/esm2020/table/tokens.mjs +16 -0
  239. package/esm2020/text-field/autofill.mjs +113 -0
  240. package/esm2020/text-field/autosize.mjs +309 -0
  241. package/esm2020/text-field/index.mjs +9 -0
  242. package/esm2020/text-field/public-api.mjs +11 -0
  243. package/esm2020/text-field/text-field-module.mjs +24 -0
  244. package/esm2020/text-field/text-field_public_index.mjs +5 -0
  245. package/esm2020/tree/control/base-tree-control.mjs +57 -0
  246. package/esm2020/tree/control/flat-tree-control.mjs +51 -0
  247. package/esm2020/tree/control/nested-tree-control.mjs +58 -0
  248. package/esm2020/tree/control/tree-control.mjs +2 -0
  249. package/esm2020/tree/index.mjs +9 -0
  250. package/esm2020/tree/nested-node.mjs +112 -0
  251. package/esm2020/tree/node.mjs +35 -0
  252. package/esm2020/tree/outlet.mjs +39 -0
  253. package/esm2020/tree/padding.mjs +131 -0
  254. package/esm2020/tree/public-api.mjs +20 -0
  255. package/esm2020/tree/toggle.mjs +50 -0
  256. package/esm2020/tree/tree-errors.mjs +43 -0
  257. package/esm2020/tree/tree-module.mjs +49 -0
  258. package/esm2020/tree/tree.mjs +347 -0
  259. package/esm2020/tree/tree_public_index.mjs +5 -0
  260. package/esm2020/version.mjs +11 -0
  261. package/fesm2015/a11y.mjs +2473 -0
  262. package/fesm2015/a11y.mjs.map +1 -0
  263. package/fesm2015/accordion.mjs +414 -0
  264. package/fesm2015/accordion.mjs.map +1 -0
  265. package/fesm2015/bidi.mjs +194 -0
  266. package/fesm2015/bidi.mjs.map +1 -0
  267. package/fesm2015/cdk.mjs +30 -0
  268. package/fesm2015/cdk.mjs.map +1 -0
  269. package/fesm2015/clipboard.mjs +263 -0
  270. package/fesm2015/clipboard.mjs.map +1 -0
  271. package/fesm2015/coercion.mjs +132 -0
  272. package/fesm2015/coercion.mjs.map +1 -0
  273. package/fesm2015/collections.mjs +519 -0
  274. package/fesm2015/collections.mjs.map +1 -0
  275. package/fesm2015/dialog.mjs +1050 -0
  276. package/fesm2015/dialog.mjs.map +1 -0
  277. package/fesm2015/drag-drop.mjs +3812 -0
  278. package/fesm2015/drag-drop.mjs.map +1 -0
  279. package/fesm2015/keycodes.mjs +167 -0
  280. package/fesm2015/keycodes.mjs.map +1 -0
  281. package/fesm2015/layout.mjs +337 -0
  282. package/fesm2015/layout.mjs.map +1 -0
  283. package/fesm2015/listbox.mjs +1200 -0
  284. package/fesm2015/listbox.mjs.map +1 -0
  285. package/fesm2015/menu.mjs +2719 -0
  286. package/fesm2015/menu.mjs.map +1 -0
  287. package/fesm2015/observers.mjs +326 -0
  288. package/fesm2015/observers.mjs.map +1 -0
  289. package/fesm2015/overlay.mjs +3137 -0
  290. package/fesm2015/overlay.mjs.map +1 -0
  291. package/fesm2015/platform.mjs +385 -0
  292. package/fesm2015/platform.mjs.map +1 -0
  293. package/fesm2015/portal.mjs +691 -0
  294. package/fesm2015/portal.mjs.map +1 -0
  295. package/fesm2015/scrolling.mjs +1558 -0
  296. package/fesm2015/scrolling.mjs.map +1 -0
  297. package/fesm2015/stepper.mjs +989 -0
  298. package/fesm2015/stepper.mjs.map +1 -0
  299. package/fesm2015/table.mjs +2356 -0
  300. package/fesm2015/table.mjs.map +1 -0
  301. package/fesm2015/testing.mjs +833 -0
  302. package/fesm2015/testing.mjs.map +1 -0
  303. package/fesm2015/text-field.mjs +461 -0
  304. package/fesm2015/text-field.mjs.map +1 -0
  305. package/fesm2015/tree.mjs +1303 -0
  306. package/fesm2015/tree.mjs.map +1 -0
  307. package/fesm2020/a11y.mjs +2476 -0
  308. package/fesm2020/a11y.mjs.map +1 -0
  309. package/fesm2020/accordion.mjs +414 -0
  310. package/fesm2020/accordion.mjs.map +1 -0
  311. package/fesm2020/bidi.mjs +192 -0
  312. package/fesm2020/bidi.mjs.map +1 -0
  313. package/fesm2020/cdk.mjs +30 -0
  314. package/fesm2020/cdk.mjs.map +1 -0
  315. package/fesm2020/clipboard.mjs +259 -0
  316. package/fesm2020/clipboard.mjs.map +1 -0
  317. package/fesm2020/coercion.mjs +132 -0
  318. package/fesm2020/coercion.mjs.map +1 -0
  319. package/fesm2020/collections.mjs +535 -0
  320. package/fesm2020/collections.mjs.map +1 -0
  321. package/fesm2020/dialog.mjs +787 -0
  322. package/fesm2020/dialog.mjs.map +1 -0
  323. package/fesm2020/drag-drop.mjs +3808 -0
  324. package/fesm2020/drag-drop.mjs.map +1 -0
  325. package/fesm2020/keycodes.mjs +167 -0
  326. package/fesm2020/keycodes.mjs.map +1 -0
  327. package/fesm2020/layout.mjs +337 -0
  328. package/fesm2020/layout.mjs.map +1 -0
  329. package/fesm2020/listbox.mjs +1164 -0
  330. package/fesm2020/listbox.mjs.map +1 -0
  331. package/fesm2020/menu.mjs +2615 -0
  332. package/fesm2020/menu.mjs.map +1 -0
  333. package/fesm2020/observers.mjs +325 -0
  334. package/fesm2020/observers.mjs.map +1 -0
  335. package/fesm2020/overlay.mjs +3145 -0
  336. package/fesm2020/overlay.mjs.map +1 -0
  337. package/fesm2020/platform.mjs +383 -0
  338. package/fesm2020/platform.mjs.map +1 -0
  339. package/fesm2020/portal.mjs +689 -0
  340. package/fesm2020/portal.mjs.map +1 -0
  341. package/fesm2020/scrolling.mjs +1591 -0
  342. package/fesm2020/scrolling.mjs.map +1 -0
  343. package/fesm2020/stepper.mjs +985 -0
  344. package/fesm2020/stepper.mjs.map +1 -0
  345. package/fesm2020/table.mjs +2348 -0
  346. package/fesm2020/table.mjs.map +1 -0
  347. package/fesm2020/testing.mjs +797 -0
  348. package/fesm2020/testing.mjs.map +1 -0
  349. package/fesm2020/text-field.mjs +459 -0
  350. package/fesm2020/text-field.mjs.map +1 -0
  351. package/fesm2020/tree.mjs +1305 -0
  352. package/fesm2020/tree.mjs.map +1 -0
  353. package/index.d.ts +6 -0
  354. package/keycodes/index.d.ts +249 -0
  355. package/layout/index.d.ts +90 -0
  356. package/listbox/index.d.ts +419 -0
  357. package/menu/index.d.ts +1013 -0
  358. package/observers/index.d.ts +109 -0
  359. package/overlay/_index-deprecated.scss +13 -0
  360. package/overlay/_index.import.scss +13 -0
  361. package/overlay/_index.scss +152 -0
  362. package/overlay/index.d.ts +1343 -0
  363. package/overlay-prebuilt.css +1 -0
  364. package/package.json +232 -0
  365. package/platform/index.d.ts +106 -0
  366. package/portal/index.d.ts +328 -0
  367. package/scrolling/index.d.ts +849 -0
  368. package/stepper/index.d.ts +419 -0
  369. package/table/index.d.ts +1483 -0
  370. package/text-field/_index.import.scss +2 -0
  371. package/text-field/_index.scss +89 -0
  372. package/text-field/index.d.ts +203 -0
  373. package/text-field-prebuilt.css +1 -0
  374. package/tree/index.d.ts +593 -0
@@ -0,0 +1,3812 @@
1
+ import * as i0 from '@angular/core';
2
+ import { Injectable, Inject, InjectionToken, Directive, Input, EventEmitter, Optional, SkipSelf, Output, Self, ContentChildren, ContentChild, NgModule } from '@angular/core';
3
+ import { DOCUMENT } from '@angular/common';
4
+ import { _getEventTarget, normalizePassiveListenerOptions, _getShadowRoot } from '@kato-lee/cdk/platform';
5
+ import { coerceBooleanProperty, coerceElement, coerceArray, coerceNumberProperty } from '@kato-lee/cdk/coercion';
6
+ import { isFakeTouchstartFromScreenReader, isFakeMousedownFromScreenReader } from '@kato-lee/cdk/a11y';
7
+ import { Subject, Subscription, interval, animationFrameScheduler, Observable, merge } from 'rxjs';
8
+ import { takeUntil, startWith, map, take, tap, switchMap } from 'rxjs/operators';
9
+ import * as i1 from '@kato-lee/cdk/scrolling';
10
+ import { CdkScrollableModule } from '@kato-lee/cdk/scrolling';
11
+ import * as i3 from '@kato-lee/cdk/bidi';
12
+
13
+ /**
14
+ * @license
15
+ * Copyright Google LLC All Rights Reserved.
16
+ *
17
+ * Use of this source code is governed by an MIT-style license that can be
18
+ * found in the LICENSE file at https://angular.io/license
19
+ */
20
+ /**
21
+ * Shallow-extends a stylesheet object with another stylesheet-like object.
22
+ * Note that the keys in `source` have to be dash-cased.
23
+ * @docs-private
24
+ */
25
+ function extendStyles(dest, source, importantProperties) {
26
+ for (let key in source) {
27
+ if (source.hasOwnProperty(key)) {
28
+ const value = source[key];
29
+ if (value) {
30
+ dest.setProperty(key, value, (importantProperties === null || importantProperties === void 0 ? void 0 : importantProperties.has(key)) ? 'important' : '');
31
+ }
32
+ else {
33
+ dest.removeProperty(key);
34
+ }
35
+ }
36
+ }
37
+ return dest;
38
+ }
39
+ /**
40
+ * Toggles whether the native drag interactions should be enabled for an element.
41
+ * @param element Element on which to toggle the drag interactions.
42
+ * @param enable Whether the drag interactions should be enabled.
43
+ * @docs-private
44
+ */
45
+ function toggleNativeDragInteractions(element, enable) {
46
+ const userSelect = enable ? '' : 'none';
47
+ extendStyles(element.style, {
48
+ 'touch-action': enable ? '' : 'none',
49
+ '-webkit-user-drag': enable ? '' : 'none',
50
+ '-webkit-tap-highlight-color': enable ? '' : 'transparent',
51
+ 'user-select': userSelect,
52
+ '-ms-user-select': userSelect,
53
+ '-webkit-user-select': userSelect,
54
+ '-moz-user-select': userSelect,
55
+ });
56
+ }
57
+ /**
58
+ * Toggles whether an element is visible while preserving its dimensions.
59
+ * @param element Element whose visibility to toggle
60
+ * @param enable Whether the element should be visible.
61
+ * @param importantProperties Properties to be set as `!important`.
62
+ * @docs-private
63
+ */
64
+ function toggleVisibility(element, enable, importantProperties) {
65
+ extendStyles(element.style, {
66
+ position: enable ? '' : 'fixed',
67
+ top: enable ? '' : '0',
68
+ opacity: enable ? '' : '0',
69
+ left: enable ? '' : '-999em',
70
+ }, importantProperties);
71
+ }
72
+ /**
73
+ * Combines a transform string with an optional other transform
74
+ * that exited before the base transform was applied.
75
+ */
76
+ function combineTransforms(transform, initialTransform) {
77
+ return initialTransform && initialTransform != 'none'
78
+ ? transform + ' ' + initialTransform
79
+ : transform;
80
+ }
81
+
82
+ /**
83
+ * @license
84
+ * Copyright Google LLC All Rights Reserved.
85
+ *
86
+ * Use of this source code is governed by an MIT-style license that can be
87
+ * found in the LICENSE file at https://angular.io/license
88
+ */
89
+ /** Parses a CSS time value to milliseconds. */
90
+ function parseCssTimeUnitsToMs(value) {
91
+ // Some browsers will return it in seconds, whereas others will return milliseconds.
92
+ const multiplier = value.toLowerCase().indexOf('ms') > -1 ? 1 : 1000;
93
+ return parseFloat(value) * multiplier;
94
+ }
95
+ /** Gets the transform transition duration, including the delay, of an element in milliseconds. */
96
+ function getTransformTransitionDurationInMs(element) {
97
+ const computedStyle = getComputedStyle(element);
98
+ const transitionedProperties = parseCssPropertyValue(computedStyle, 'transition-property');
99
+ const property = transitionedProperties.find(prop => prop === 'transform' || prop === 'all');
100
+ // If there's no transition for `all` or `transform`, we shouldn't do anything.
101
+ if (!property) {
102
+ return 0;
103
+ }
104
+ // Get the index of the property that we're interested in and match
105
+ // it up to the same index in `transition-delay` and `transition-duration`.
106
+ const propertyIndex = transitionedProperties.indexOf(property);
107
+ const rawDurations = parseCssPropertyValue(computedStyle, 'transition-duration');
108
+ const rawDelays = parseCssPropertyValue(computedStyle, 'transition-delay');
109
+ return (parseCssTimeUnitsToMs(rawDurations[propertyIndex]) +
110
+ parseCssTimeUnitsToMs(rawDelays[propertyIndex]));
111
+ }
112
+ /** Parses out multiple values from a computed style into an array. */
113
+ function parseCssPropertyValue(computedStyle, name) {
114
+ const value = computedStyle.getPropertyValue(name);
115
+ return value.split(',').map(part => part.trim());
116
+ }
117
+
118
+ /**
119
+ * @license
120
+ * Copyright Google LLC All Rights Reserved.
121
+ *
122
+ * Use of this source code is governed by an MIT-style license that can be
123
+ * found in the LICENSE file at https://angular.io/license
124
+ */
125
+ /** Gets a mutable version of an element's bounding `ClientRect`. */
126
+ function getMutableClientRect(element) {
127
+ const clientRect = element.getBoundingClientRect();
128
+ // We need to clone the `clientRect` here, because all the values on it are readonly
129
+ // and we need to be able to update them. Also we can't use a spread here, because
130
+ // the values on a `ClientRect` aren't own properties. See:
131
+ // https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect#Notes
132
+ return {
133
+ top: clientRect.top,
134
+ right: clientRect.right,
135
+ bottom: clientRect.bottom,
136
+ left: clientRect.left,
137
+ width: clientRect.width,
138
+ height: clientRect.height,
139
+ x: clientRect.x,
140
+ y: clientRect.y,
141
+ };
142
+ }
143
+ /**
144
+ * Checks whether some coordinates are within a `ClientRect`.
145
+ * @param clientRect ClientRect that is being checked.
146
+ * @param x Coordinates along the X axis.
147
+ * @param y Coordinates along the Y axis.
148
+ */
149
+ function isInsideClientRect(clientRect, x, y) {
150
+ const { top, bottom, left, right } = clientRect;
151
+ return y >= top && y <= bottom && x >= left && x <= right;
152
+ }
153
+ /**
154
+ * Updates the top/left positions of a `ClientRect`, as well as their bottom/right counterparts.
155
+ * @param clientRect `ClientRect` that should be updated.
156
+ * @param top Amount to add to the `top` position.
157
+ * @param left Amount to add to the `left` position.
158
+ */
159
+ function adjustClientRect(clientRect, top, left) {
160
+ clientRect.top += top;
161
+ clientRect.bottom = clientRect.top + clientRect.height;
162
+ clientRect.left += left;
163
+ clientRect.right = clientRect.left + clientRect.width;
164
+ }
165
+ /**
166
+ * Checks whether the pointer coordinates are close to a ClientRect.
167
+ * @param rect ClientRect to check against.
168
+ * @param threshold Threshold around the ClientRect.
169
+ * @param pointerX Coordinates along the X axis.
170
+ * @param pointerY Coordinates along the Y axis.
171
+ */
172
+ function isPointerNearClientRect(rect, threshold, pointerX, pointerY) {
173
+ const { top, right, bottom, left, width, height } = rect;
174
+ const xThreshold = width * threshold;
175
+ const yThreshold = height * threshold;
176
+ return (pointerY > top - yThreshold &&
177
+ pointerY < bottom + yThreshold &&
178
+ pointerX > left - xThreshold &&
179
+ pointerX < right + xThreshold);
180
+ }
181
+
182
+ /**
183
+ * @license
184
+ * Copyright Google LLC All Rights Reserved.
185
+ *
186
+ * Use of this source code is governed by an MIT-style license that can be
187
+ * found in the LICENSE file at https://angular.io/license
188
+ */
189
+ /** Keeps track of the scroll position and dimensions of the parents of an element. */
190
+ class ParentPositionTracker {
191
+ constructor(_document) {
192
+ this._document = _document;
193
+ /** Cached positions of the scrollable parent elements. */
194
+ this.positions = new Map();
195
+ }
196
+ /** Clears the cached positions. */
197
+ clear() {
198
+ this.positions.clear();
199
+ }
200
+ /** Caches the positions. Should be called at the beginning of a drag sequence. */
201
+ cache(elements) {
202
+ this.clear();
203
+ this.positions.set(this._document, {
204
+ scrollPosition: this.getViewportScrollPosition(),
205
+ });
206
+ elements.forEach(element => {
207
+ this.positions.set(element, {
208
+ scrollPosition: { top: element.scrollTop, left: element.scrollLeft },
209
+ clientRect: getMutableClientRect(element),
210
+ });
211
+ });
212
+ }
213
+ /** Handles scrolling while a drag is taking place. */
214
+ handleScroll(event) {
215
+ const target = _getEventTarget(event);
216
+ const cachedPosition = this.positions.get(target);
217
+ if (!cachedPosition) {
218
+ return null;
219
+ }
220
+ const scrollPosition = cachedPosition.scrollPosition;
221
+ let newTop;
222
+ let newLeft;
223
+ if (target === this._document) {
224
+ const viewportScrollPosition = this.getViewportScrollPosition();
225
+ newTop = viewportScrollPosition.top;
226
+ newLeft = viewportScrollPosition.left;
227
+ }
228
+ else {
229
+ newTop = target.scrollTop;
230
+ newLeft = target.scrollLeft;
231
+ }
232
+ const topDifference = scrollPosition.top - newTop;
233
+ const leftDifference = scrollPosition.left - newLeft;
234
+ // Go through and update the cached positions of the scroll
235
+ // parents that are inside the element that was scrolled.
236
+ this.positions.forEach((position, node) => {
237
+ if (position.clientRect && target !== node && target.contains(node)) {
238
+ adjustClientRect(position.clientRect, topDifference, leftDifference);
239
+ }
240
+ });
241
+ scrollPosition.top = newTop;
242
+ scrollPosition.left = newLeft;
243
+ return { top: topDifference, left: leftDifference };
244
+ }
245
+ /**
246
+ * Gets the scroll position of the viewport. Note that we use the scrollX and scrollY directly,
247
+ * instead of going through the `ViewportRuler`, because the first value the ruler looks at is
248
+ * the top/left offset of the `document.documentElement` which works for most cases, but breaks
249
+ * if the element is offset by something like the `BlockScrollStrategy`.
250
+ */
251
+ getViewportScrollPosition() {
252
+ return { top: window.scrollY, left: window.scrollX };
253
+ }
254
+ }
255
+
256
+ /**
257
+ * @license
258
+ * Copyright Google LLC All Rights Reserved.
259
+ *
260
+ * Use of this source code is governed by an MIT-style license that can be
261
+ * found in the LICENSE file at https://angular.io/license
262
+ */
263
+ /** Creates a deep clone of an element. */
264
+ function deepCloneNode(node) {
265
+ const clone = node.cloneNode(true);
266
+ const descendantsWithId = clone.querySelectorAll('[id]');
267
+ const nodeName = node.nodeName.toLowerCase();
268
+ // Remove the `id` to avoid having multiple elements with the same id on the page.
269
+ clone.removeAttribute('id');
270
+ for (let i = 0; i < descendantsWithId.length; i++) {
271
+ descendantsWithId[i].removeAttribute('id');
272
+ }
273
+ if (nodeName === 'canvas') {
274
+ transferCanvasData(node, clone);
275
+ }
276
+ else if (nodeName === 'input' || nodeName === 'select' || nodeName === 'textarea') {
277
+ transferInputData(node, clone);
278
+ }
279
+ transferData('canvas', node, clone, transferCanvasData);
280
+ transferData('input, textarea, select', node, clone, transferInputData);
281
+ return clone;
282
+ }
283
+ /** Matches elements between an element and its clone and allows for their data to be cloned. */
284
+ function transferData(selector, node, clone, callback) {
285
+ const descendantElements = node.querySelectorAll(selector);
286
+ if (descendantElements.length) {
287
+ const cloneElements = clone.querySelectorAll(selector);
288
+ for (let i = 0; i < descendantElements.length; i++) {
289
+ callback(descendantElements[i], cloneElements[i]);
290
+ }
291
+ }
292
+ }
293
+ // Counter for unique cloned radio button names.
294
+ let cloneUniqueId = 0;
295
+ /** Transfers the data of one input element to another. */
296
+ function transferInputData(source, clone) {
297
+ // Browsers throw an error when assigning the value of a file input programmatically.
298
+ if (clone.type !== 'file') {
299
+ clone.value = source.value;
300
+ }
301
+ // Radio button `name` attributes must be unique for radio button groups
302
+ // otherwise original radio buttons can lose their checked state
303
+ // once the clone is inserted in the DOM.
304
+ if (clone.type === 'radio' && clone.name) {
305
+ clone.name = `mat-clone-${clone.name}-${cloneUniqueId++}`;
306
+ }
307
+ }
308
+ /** Transfers the data of one canvas element to another. */
309
+ function transferCanvasData(source, clone) {
310
+ const context = clone.getContext('2d');
311
+ if (context) {
312
+ // In some cases `drawImage` can throw (e.g. if the canvas size is 0x0).
313
+ // We can't do much about it so just ignore the error.
314
+ try {
315
+ context.drawImage(source, 0, 0);
316
+ }
317
+ catch (_a) { }
318
+ }
319
+ }
320
+
321
+ /**
322
+ * @license
323
+ * Copyright Google LLC All Rights Reserved.
324
+ *
325
+ * Use of this source code is governed by an MIT-style license that can be
326
+ * found in the LICENSE file at https://angular.io/license
327
+ */
328
+ /** Options that can be used to bind a passive event listener. */
329
+ const passiveEventListenerOptions = normalizePassiveListenerOptions({ passive: true });
330
+ /** Options that can be used to bind an active event listener. */
331
+ const activeEventListenerOptions = normalizePassiveListenerOptions({ passive: false });
332
+ /**
333
+ * Time in milliseconds for which to ignore mouse events, after
334
+ * receiving a touch event. Used to avoid doing double work for
335
+ * touch devices where the browser fires fake mouse events, in
336
+ * addition to touch events.
337
+ */
338
+ const MOUSE_EVENT_IGNORE_TIME = 800;
339
+ /** Inline styles to be set as `!important` while dragging. */
340
+ const dragImportantProperties = new Set([
341
+ // Needs to be important, because some `mat-table` sets `position: sticky !important`. See #22781.
342
+ 'position',
343
+ ]);
344
+ /**
345
+ * Reference to a draggable item. Used to manipulate or dispose of the item.
346
+ */
347
+ class DragRef {
348
+ constructor(element, _config, _document, _ngZone, _viewportRuler, _dragDropRegistry) {
349
+ this._config = _config;
350
+ this._document = _document;
351
+ this._ngZone = _ngZone;
352
+ this._viewportRuler = _viewportRuler;
353
+ this._dragDropRegistry = _dragDropRegistry;
354
+ /**
355
+ * CSS `transform` applied to the element when it isn't being dragged. We need a
356
+ * passive transform in order for the dragged element to retain its new position
357
+ * after the user has stopped dragging and because we need to know the relative
358
+ * position in case they start dragging again. This corresponds to `element.style.transform`.
359
+ */
360
+ this._passiveTransform = { x: 0, y: 0 };
361
+ /** CSS `transform` that is applied to the element while it's being dragged. */
362
+ this._activeTransform = { x: 0, y: 0 };
363
+ /**
364
+ * Whether the dragging sequence has been started. Doesn't
365
+ * necessarily mean that the element has been moved.
366
+ */
367
+ this._hasStartedDragging = false;
368
+ /** Emits when the item is being moved. */
369
+ this._moveEvents = new Subject();
370
+ /** Subscription to pointer movement events. */
371
+ this._pointerMoveSubscription = Subscription.EMPTY;
372
+ /** Subscription to the event that is dispatched when the user lifts their pointer. */
373
+ this._pointerUpSubscription = Subscription.EMPTY;
374
+ /** Subscription to the viewport being scrolled. */
375
+ this._scrollSubscription = Subscription.EMPTY;
376
+ /** Subscription to the viewport being resized. */
377
+ this._resizeSubscription = Subscription.EMPTY;
378
+ /** Cached reference to the boundary element. */
379
+ this._boundaryElement = null;
380
+ /** Whether the native dragging interactions have been enabled on the root element. */
381
+ this._nativeInteractionsEnabled = true;
382
+ /** Elements that can be used to drag the draggable item. */
383
+ this._handles = [];
384
+ /** Registered handles that are currently disabled. */
385
+ this._disabledHandles = new Set();
386
+ /** Layout direction of the item. */
387
+ this._direction = 'ltr';
388
+ /**
389
+ * Amount of milliseconds to wait after the user has put their
390
+ * pointer down before starting to drag the element.
391
+ */
392
+ this.dragStartDelay = 0;
393
+ this._disabled = false;
394
+ /** Emits as the drag sequence is being prepared. */
395
+ this.beforeStarted = new Subject();
396
+ /** Emits when the user starts dragging the item. */
397
+ this.started = new Subject();
398
+ /** Emits when the user has released a drag item, before any animations have started. */
399
+ this.released = new Subject();
400
+ /** Emits when the user stops dragging an item in the container. */
401
+ this.ended = new Subject();
402
+ /** Emits when the user has moved the item into a new container. */
403
+ this.entered = new Subject();
404
+ /** Emits when the user removes the item its container by dragging it into another container. */
405
+ this.exited = new Subject();
406
+ /** Emits when the user drops the item inside a container. */
407
+ this.dropped = new Subject();
408
+ /**
409
+ * Emits as the user is dragging the item. Use with caution,
410
+ * because this event will fire for every pixel that the user has dragged.
411
+ */
412
+ this.moved = this._moveEvents;
413
+ /** Handler for the `mousedown`/`touchstart` events. */
414
+ this._pointerDown = (event) => {
415
+ this.beforeStarted.next();
416
+ // Delegate the event based on whether it started from a handle or the element itself.
417
+ if (this._handles.length) {
418
+ const targetHandle = this._getTargetHandle(event);
419
+ if (targetHandle && !this._disabledHandles.has(targetHandle) && !this.disabled) {
420
+ this._initializeDragSequence(targetHandle, event);
421
+ }
422
+ }
423
+ else if (!this.disabled) {
424
+ this._initializeDragSequence(this._rootElement, event);
425
+ }
426
+ };
427
+ /** Handler that is invoked when the user moves their pointer after they've initiated a drag. */
428
+ this._pointerMove = (event) => {
429
+ const pointerPosition = this._getPointerPositionOnPage(event);
430
+ if (!this._hasStartedDragging) {
431
+ const distanceX = Math.abs(pointerPosition.x - this._pickupPositionOnPage.x);
432
+ const distanceY = Math.abs(pointerPosition.y - this._pickupPositionOnPage.y);
433
+ const isOverThreshold = distanceX + distanceY >= this._config.dragStartThreshold;
434
+ // Only start dragging after the user has moved more than the minimum distance in either
435
+ // direction. Note that this is preferable over doing something like `skip(minimumDistance)`
436
+ // in the `pointerMove` subscription, because we're not guaranteed to have one move event
437
+ // per pixel of movement (e.g. if the user moves their pointer quickly).
438
+ if (isOverThreshold) {
439
+ const isDelayElapsed = Date.now() >= this._dragStartTime + this._getDragStartDelay(event);
440
+ const container = this._dropContainer;
441
+ if (!isDelayElapsed) {
442
+ this._endDragSequence(event);
443
+ return;
444
+ }
445
+ // Prevent other drag sequences from starting while something in the container is still
446
+ // being dragged. This can happen while we're waiting for the drop animation to finish
447
+ // and can cause errors, because some elements might still be moving around.
448
+ if (!container || (!container.isDragging() && !container.isReceiving())) {
449
+ // Prevent the default action as soon as the dragging sequence is considered as
450
+ // "started" since waiting for the next event can allow the device to begin scrolling.
451
+ event.preventDefault();
452
+ this._hasStartedDragging = true;
453
+ this._ngZone.run(() => this._startDragSequence(event));
454
+ }
455
+ }
456
+ return;
457
+ }
458
+ // We prevent the default action down here so that we know that dragging has started. This is
459
+ // important for touch devices where doing this too early can unnecessarily block scrolling,
460
+ // if there's a dragging delay.
461
+ event.preventDefault();
462
+ const constrainedPointerPosition = this._getConstrainedPointerPosition(pointerPosition);
463
+ this._hasMoved = true;
464
+ this._lastKnownPointerPosition = pointerPosition;
465
+ this._updatePointerDirectionDelta(constrainedPointerPosition);
466
+ if (this._dropContainer) {
467
+ this._updateActiveDropContainer(constrainedPointerPosition, pointerPosition);
468
+ }
469
+ else {
470
+ // If there's a position constraint function, we want the element's top/left to be at the
471
+ // specific position on the page. Use the initial position as a reference if that's the case.
472
+ const offset = this.constrainPosition ? this._initialClientRect : this._pickupPositionOnPage;
473
+ const activeTransform = this._activeTransform;
474
+ activeTransform.x = constrainedPointerPosition.x - offset.x + this._passiveTransform.x;
475
+ activeTransform.y = constrainedPointerPosition.y - offset.y + this._passiveTransform.y;
476
+ this._applyRootElementTransform(activeTransform.x, activeTransform.y);
477
+ }
478
+ // Since this event gets fired for every pixel while dragging, we only
479
+ // want to fire it if the consumer opted into it. Also we have to
480
+ // re-enter the zone because we run all of the events on the outside.
481
+ if (this._moveEvents.observers.length) {
482
+ this._ngZone.run(() => {
483
+ this._moveEvents.next({
484
+ source: this,
485
+ pointerPosition: constrainedPointerPosition,
486
+ event,
487
+ distance: this._getDragDistance(constrainedPointerPosition),
488
+ delta: this._pointerDirectionDelta,
489
+ });
490
+ });
491
+ }
492
+ };
493
+ /** Handler that is invoked when the user lifts their pointer up, after initiating a drag. */
494
+ this._pointerUp = (event) => {
495
+ this._endDragSequence(event);
496
+ };
497
+ /** Handles a native `dragstart` event. */
498
+ this._nativeDragStart = (event) => {
499
+ if (this._handles.length) {
500
+ const targetHandle = this._getTargetHandle(event);
501
+ if (targetHandle && !this._disabledHandles.has(targetHandle) && !this.disabled) {
502
+ event.preventDefault();
503
+ }
504
+ }
505
+ else if (!this.disabled) {
506
+ // Usually this isn't necessary since the we prevent the default action in `pointerDown`,
507
+ // but some cases like dragging of links can slip through (see #24403).
508
+ event.preventDefault();
509
+ }
510
+ };
511
+ this.withRootElement(element).withParent(_config.parentDragRef || null);
512
+ this._parentPositions = new ParentPositionTracker(_document);
513
+ _dragDropRegistry.registerDragItem(this);
514
+ }
515
+ /** Whether starting to drag this element is disabled. */
516
+ get disabled() {
517
+ return this._disabled || !!(this._dropContainer && this._dropContainer.disabled);
518
+ }
519
+ set disabled(value) {
520
+ const newValue = coerceBooleanProperty(value);
521
+ if (newValue !== this._disabled) {
522
+ this._disabled = newValue;
523
+ this._toggleNativeDragInteractions();
524
+ this._handles.forEach(handle => toggleNativeDragInteractions(handle, newValue));
525
+ }
526
+ }
527
+ /**
528
+ * Returns the element that is being used as a placeholder
529
+ * while the current element is being dragged.
530
+ */
531
+ getPlaceholderElement() {
532
+ return this._placeholder;
533
+ }
534
+ /** Returns the root draggable element. */
535
+ getRootElement() {
536
+ return this._rootElement;
537
+ }
538
+ /**
539
+ * Gets the currently-visible element that represents the drag item.
540
+ * While dragging this is the placeholder, otherwise it's the root element.
541
+ */
542
+ getVisibleElement() {
543
+ return this.isDragging() ? this.getPlaceholderElement() : this.getRootElement();
544
+ }
545
+ /** Registers the handles that can be used to drag the element. */
546
+ withHandles(handles) {
547
+ this._handles = handles.map(handle => coerceElement(handle));
548
+ this._handles.forEach(handle => toggleNativeDragInteractions(handle, this.disabled));
549
+ this._toggleNativeDragInteractions();
550
+ // Delete any lingering disabled handles that may have been destroyed. Note that we re-create
551
+ // the set, rather than iterate over it and filter out the destroyed handles, because while
552
+ // the ES spec allows for sets to be modified while they're being iterated over, some polyfills
553
+ // use an array internally which may throw an error.
554
+ const disabledHandles = new Set();
555
+ this._disabledHandles.forEach(handle => {
556
+ if (this._handles.indexOf(handle) > -1) {
557
+ disabledHandles.add(handle);
558
+ }
559
+ });
560
+ this._disabledHandles = disabledHandles;
561
+ return this;
562
+ }
563
+ /**
564
+ * Registers the template that should be used for the drag preview.
565
+ * @param template Template that from which to stamp out the preview.
566
+ */
567
+ withPreviewTemplate(template) {
568
+ this._previewTemplate = template;
569
+ return this;
570
+ }
571
+ /**
572
+ * Registers the template that should be used for the drag placeholder.
573
+ * @param template Template that from which to stamp out the placeholder.
574
+ */
575
+ withPlaceholderTemplate(template) {
576
+ this._placeholderTemplate = template;
577
+ return this;
578
+ }
579
+ /**
580
+ * Sets an alternate drag root element. The root element is the element that will be moved as
581
+ * the user is dragging. Passing an alternate root element is useful when trying to enable
582
+ * dragging on an element that you might not have access to.
583
+ */
584
+ withRootElement(rootElement) {
585
+ const element = coerceElement(rootElement);
586
+ if (element !== this._rootElement) {
587
+ if (this._rootElement) {
588
+ this._removeRootElementListeners(this._rootElement);
589
+ }
590
+ this._ngZone.runOutsideAngular(() => {
591
+ element.addEventListener('mousedown', this._pointerDown, activeEventListenerOptions);
592
+ element.addEventListener('touchstart', this._pointerDown, passiveEventListenerOptions);
593
+ element.addEventListener('dragstart', this._nativeDragStart, activeEventListenerOptions);
594
+ });
595
+ this._initialTransform = undefined;
596
+ this._rootElement = element;
597
+ }
598
+ if (typeof SVGElement !== 'undefined' && this._rootElement instanceof SVGElement) {
599
+ this._ownerSVGElement = this._rootElement.ownerSVGElement;
600
+ }
601
+ return this;
602
+ }
603
+ /**
604
+ * Element to which the draggable's position will be constrained.
605
+ */
606
+ withBoundaryElement(boundaryElement) {
607
+ this._boundaryElement = boundaryElement ? coerceElement(boundaryElement) : null;
608
+ this._resizeSubscription.unsubscribe();
609
+ if (boundaryElement) {
610
+ this._resizeSubscription = this._viewportRuler
611
+ .change(10)
612
+ .subscribe(() => this._containInsideBoundaryOnResize());
613
+ }
614
+ return this;
615
+ }
616
+ /** Sets the parent ref that the ref is nested in. */
617
+ withParent(parent) {
618
+ this._parentDragRef = parent;
619
+ return this;
620
+ }
621
+ /** Removes the dragging functionality from the DOM element. */
622
+ dispose() {
623
+ var _a, _b;
624
+ this._removeRootElementListeners(this._rootElement);
625
+ // Do this check before removing from the registry since it'll
626
+ // stop being considered as dragged once it is removed.
627
+ if (this.isDragging()) {
628
+ // Since we move out the element to the end of the body while it's being
629
+ // dragged, we have to make sure that it's removed if it gets destroyed.
630
+ (_a = this._rootElement) === null || _a === void 0 ? void 0 : _a.remove();
631
+ }
632
+ (_b = this._anchor) === null || _b === void 0 ? void 0 : _b.remove();
633
+ this._destroyPreview();
634
+ this._destroyPlaceholder();
635
+ this._dragDropRegistry.removeDragItem(this);
636
+ this._removeSubscriptions();
637
+ this.beforeStarted.complete();
638
+ this.started.complete();
639
+ this.released.complete();
640
+ this.ended.complete();
641
+ this.entered.complete();
642
+ this.exited.complete();
643
+ this.dropped.complete();
644
+ this._moveEvents.complete();
645
+ this._handles = [];
646
+ this._disabledHandles.clear();
647
+ this._dropContainer = undefined;
648
+ this._resizeSubscription.unsubscribe();
649
+ this._parentPositions.clear();
650
+ this._boundaryElement =
651
+ this._rootElement =
652
+ this._ownerSVGElement =
653
+ this._placeholderTemplate =
654
+ this._previewTemplate =
655
+ this._anchor =
656
+ this._parentDragRef =
657
+ null;
658
+ }
659
+ /** Checks whether the element is currently being dragged. */
660
+ isDragging() {
661
+ return this._hasStartedDragging && this._dragDropRegistry.isDragging(this);
662
+ }
663
+ /** Resets a standalone drag item to its initial position. */
664
+ reset() {
665
+ this._rootElement.style.transform = this._initialTransform || '';
666
+ this._activeTransform = { x: 0, y: 0 };
667
+ this._passiveTransform = { x: 0, y: 0 };
668
+ }
669
+ /**
670
+ * Sets a handle as disabled. While a handle is disabled, it'll capture and interrupt dragging.
671
+ * @param handle Handle element that should be disabled.
672
+ */
673
+ disableHandle(handle) {
674
+ if (!this._disabledHandles.has(handle) && this._handles.indexOf(handle) > -1) {
675
+ this._disabledHandles.add(handle);
676
+ toggleNativeDragInteractions(handle, true);
677
+ }
678
+ }
679
+ /**
680
+ * Enables a handle, if it has been disabled.
681
+ * @param handle Handle element to be enabled.
682
+ */
683
+ enableHandle(handle) {
684
+ if (this._disabledHandles.has(handle)) {
685
+ this._disabledHandles.delete(handle);
686
+ toggleNativeDragInteractions(handle, this.disabled);
687
+ }
688
+ }
689
+ /** Sets the layout direction of the draggable item. */
690
+ withDirection(direction) {
691
+ this._direction = direction;
692
+ return this;
693
+ }
694
+ /** Sets the container that the item is part of. */
695
+ _withDropContainer(container) {
696
+ this._dropContainer = container;
697
+ }
698
+ /**
699
+ * Gets the current position in pixels the draggable outside of a drop container.
700
+ */
701
+ getFreeDragPosition() {
702
+ const position = this.isDragging() ? this._activeTransform : this._passiveTransform;
703
+ return { x: position.x, y: position.y };
704
+ }
705
+ /**
706
+ * Sets the current position in pixels the draggable outside of a drop container.
707
+ * @param value New position to be set.
708
+ */
709
+ setFreeDragPosition(value) {
710
+ this._activeTransform = { x: 0, y: 0 };
711
+ this._passiveTransform.x = value.x;
712
+ this._passiveTransform.y = value.y;
713
+ if (!this._dropContainer) {
714
+ this._applyRootElementTransform(value.x, value.y);
715
+ }
716
+ return this;
717
+ }
718
+ /**
719
+ * Sets the container into which to insert the preview element.
720
+ * @param value Container into which to insert the preview.
721
+ */
722
+ withPreviewContainer(value) {
723
+ this._previewContainer = value;
724
+ return this;
725
+ }
726
+ /** Updates the item's sort order based on the last-known pointer position. */
727
+ _sortFromLastPointerPosition() {
728
+ const position = this._lastKnownPointerPosition;
729
+ if (position && this._dropContainer) {
730
+ this._updateActiveDropContainer(this._getConstrainedPointerPosition(position), position);
731
+ }
732
+ }
733
+ /** Unsubscribes from the global subscriptions. */
734
+ _removeSubscriptions() {
735
+ this._pointerMoveSubscription.unsubscribe();
736
+ this._pointerUpSubscription.unsubscribe();
737
+ this._scrollSubscription.unsubscribe();
738
+ }
739
+ /** Destroys the preview element and its ViewRef. */
740
+ _destroyPreview() {
741
+ var _a, _b;
742
+ (_a = this._preview) === null || _a === void 0 ? void 0 : _a.remove();
743
+ (_b = this._previewRef) === null || _b === void 0 ? void 0 : _b.destroy();
744
+ this._preview = this._previewRef = null;
745
+ }
746
+ /** Destroys the placeholder element and its ViewRef. */
747
+ _destroyPlaceholder() {
748
+ var _a, _b;
749
+ (_a = this._placeholder) === null || _a === void 0 ? void 0 : _a.remove();
750
+ (_b = this._placeholderRef) === null || _b === void 0 ? void 0 : _b.destroy();
751
+ this._placeholder = this._placeholderRef = null;
752
+ }
753
+ /**
754
+ * Clears subscriptions and stops the dragging sequence.
755
+ * @param event Browser event object that ended the sequence.
756
+ */
757
+ _endDragSequence(event) {
758
+ // Note that here we use `isDragging` from the service, rather than from `this`.
759
+ // The difference is that the one from the service reflects whether a dragging sequence
760
+ // has been initiated, whereas the one on `this` includes whether the user has passed
761
+ // the minimum dragging threshold.
762
+ if (!this._dragDropRegistry.isDragging(this)) {
763
+ return;
764
+ }
765
+ this._removeSubscriptions();
766
+ this._dragDropRegistry.stopDragging(this);
767
+ this._toggleNativeDragInteractions();
768
+ if (this._handles) {
769
+ this._rootElement.style.webkitTapHighlightColor =
770
+ this._rootElementTapHighlight;
771
+ }
772
+ if (!this._hasStartedDragging) {
773
+ return;
774
+ }
775
+ this.released.next({ source: this, event });
776
+ if (this._dropContainer) {
777
+ // Stop scrolling immediately, instead of waiting for the animation to finish.
778
+ this._dropContainer._stopScrolling();
779
+ this._animatePreviewToPlaceholder().then(() => {
780
+ this._cleanupDragArtifacts(event);
781
+ this._cleanupCachedDimensions();
782
+ this._dragDropRegistry.stopDragging(this);
783
+ });
784
+ }
785
+ else {
786
+ // Convert the active transform into a passive one. This means that next time
787
+ // the user starts dragging the item, its position will be calculated relatively
788
+ // to the new passive transform.
789
+ this._passiveTransform.x = this._activeTransform.x;
790
+ const pointerPosition = this._getPointerPositionOnPage(event);
791
+ this._passiveTransform.y = this._activeTransform.y;
792
+ this._ngZone.run(() => {
793
+ this.ended.next({
794
+ source: this,
795
+ distance: this._getDragDistance(pointerPosition),
796
+ dropPoint: pointerPosition,
797
+ event,
798
+ });
799
+ });
800
+ this._cleanupCachedDimensions();
801
+ this._dragDropRegistry.stopDragging(this);
802
+ }
803
+ }
804
+ /** Starts the dragging sequence. */
805
+ _startDragSequence(event) {
806
+ if (isTouchEvent(event)) {
807
+ this._lastTouchEventTime = Date.now();
808
+ }
809
+ this._toggleNativeDragInteractions();
810
+ const dropContainer = this._dropContainer;
811
+ if (dropContainer) {
812
+ const element = this._rootElement;
813
+ const parent = element.parentNode;
814
+ const placeholder = (this._placeholder = this._createPlaceholderElement());
815
+ const anchor = (this._anchor = this._anchor || this._document.createComment(''));
816
+ // Needs to happen before the root element is moved.
817
+ const shadowRoot = this._getShadowRoot();
818
+ // Insert an anchor node so that we can restore the element's position in the DOM.
819
+ parent.insertBefore(anchor, element);
820
+ // There's no risk of transforms stacking when inside a drop container so
821
+ // we can keep the initial transform up to date any time dragging starts.
822
+ this._initialTransform = element.style.transform || '';
823
+ // Create the preview after the initial transform has
824
+ // been cached, because it can be affected by the transform.
825
+ this._preview = this._createPreviewElement();
826
+ // We move the element out at the end of the body and we make it hidden, because keeping it in
827
+ // place will throw off the consumer's `:last-child` selectors. We can't remove the element
828
+ // from the DOM completely, because iOS will stop firing all subsequent events in the chain.
829
+ toggleVisibility(element, false, dragImportantProperties);
830
+ this._document.body.appendChild(parent.replaceChild(placeholder, element));
831
+ this._getPreviewInsertionPoint(parent, shadowRoot).appendChild(this._preview);
832
+ this.started.next({ source: this, event }); // Emit before notifying the container.
833
+ dropContainer.start();
834
+ this._initialContainer = dropContainer;
835
+ this._initialIndex = dropContainer.getItemIndex(this);
836
+ }
837
+ else {
838
+ this.started.next({ source: this, event });
839
+ this._initialContainer = this._initialIndex = undefined;
840
+ }
841
+ // Important to run after we've called `start` on the parent container
842
+ // so that it has had time to resolve its scrollable parents.
843
+ this._parentPositions.cache(dropContainer ? dropContainer.getScrollableParents() : []);
844
+ }
845
+ /**
846
+ * Sets up the different variables and subscriptions
847
+ * that will be necessary for the dragging sequence.
848
+ * @param referenceElement Element that started the drag sequence.
849
+ * @param event Browser event object that started the sequence.
850
+ */
851
+ _initializeDragSequence(referenceElement, event) {
852
+ // Stop propagation if the item is inside another
853
+ // draggable so we don't start multiple drag sequences.
854
+ if (this._parentDragRef) {
855
+ event.stopPropagation();
856
+ }
857
+ const isDragging = this.isDragging();
858
+ const isTouchSequence = isTouchEvent(event);
859
+ const isAuxiliaryMouseButton = !isTouchSequence && event.button !== 0;
860
+ const rootElement = this._rootElement;
861
+ const target = _getEventTarget(event);
862
+ const isSyntheticEvent = !isTouchSequence &&
863
+ this._lastTouchEventTime &&
864
+ this._lastTouchEventTime + MOUSE_EVENT_IGNORE_TIME > Date.now();
865
+ const isFakeEvent = isTouchSequence
866
+ ? isFakeTouchstartFromScreenReader(event)
867
+ : isFakeMousedownFromScreenReader(event);
868
+ // If the event started from an element with the native HTML drag&drop, it'll interfere
869
+ // with our own dragging (e.g. `img` tags do it by default). Prevent the default action
870
+ // to stop it from happening. Note that preventing on `dragstart` also seems to work, but
871
+ // it's flaky and it fails if the user drags it away quickly. Also note that we only want
872
+ // to do this for `mousedown` since doing the same for `touchstart` will stop any `click`
873
+ // events from firing on touch devices.
874
+ if (target && target.draggable && event.type === 'mousedown') {
875
+ event.preventDefault();
876
+ }
877
+ // Abort if the user is already dragging or is using a mouse button other than the primary one.
878
+ if (isDragging || isAuxiliaryMouseButton || isSyntheticEvent || isFakeEvent) {
879
+ return;
880
+ }
881
+ // If we've got handles, we need to disable the tap highlight on the entire root element,
882
+ // otherwise iOS will still add it, even though all the drag interactions on the handle
883
+ // are disabled.
884
+ if (this._handles.length) {
885
+ const rootStyles = rootElement.style;
886
+ this._rootElementTapHighlight = rootStyles.webkitTapHighlightColor || '';
887
+ rootStyles.webkitTapHighlightColor = 'transparent';
888
+ }
889
+ this._hasStartedDragging = this._hasMoved = false;
890
+ // Avoid multiple subscriptions and memory leaks when multi touch
891
+ // (isDragging check above isn't enough because of possible temporal and/or dimensional delays)
892
+ this._removeSubscriptions();
893
+ this._initialClientRect = this._rootElement.getBoundingClientRect();
894
+ this._pointerMoveSubscription = this._dragDropRegistry.pointerMove.subscribe(this._pointerMove);
895
+ this._pointerUpSubscription = this._dragDropRegistry.pointerUp.subscribe(this._pointerUp);
896
+ this._scrollSubscription = this._dragDropRegistry
897
+ .scrolled(this._getShadowRoot())
898
+ .subscribe(scrollEvent => this._updateOnScroll(scrollEvent));
899
+ if (this._boundaryElement) {
900
+ this._boundaryRect = getMutableClientRect(this._boundaryElement);
901
+ }
902
+ // If we have a custom preview we can't know ahead of time how large it'll be so we position
903
+ // it next to the cursor. The exception is when the consumer has opted into making the preview
904
+ // the same size as the root element, in which case we do know the size.
905
+ const previewTemplate = this._previewTemplate;
906
+ this._pickupPositionInElement =
907
+ previewTemplate && previewTemplate.template && !previewTemplate.matchSize
908
+ ? { x: 0, y: 0 }
909
+ : this._getPointerPositionInElement(this._initialClientRect, referenceElement, event);
910
+ const pointerPosition = (this._pickupPositionOnPage =
911
+ this._lastKnownPointerPosition =
912
+ this._getPointerPositionOnPage(event));
913
+ this._pointerDirectionDelta = { x: 0, y: 0 };
914
+ this._pointerPositionAtLastDirectionChange = { x: pointerPosition.x, y: pointerPosition.y };
915
+ this._dragStartTime = Date.now();
916
+ this._dragDropRegistry.startDragging(this, event);
917
+ }
918
+ /** Cleans up the DOM artifacts that were added to facilitate the element being dragged. */
919
+ _cleanupDragArtifacts(event) {
920
+ // Restore the element's visibility and insert it at its old position in the DOM.
921
+ // It's important that we maintain the position, because moving the element around in the DOM
922
+ // can throw off `NgFor` which does smart diffing and re-creates elements only when necessary,
923
+ // while moving the existing elements in all other cases.
924
+ toggleVisibility(this._rootElement, true, dragImportantProperties);
925
+ this._anchor.parentNode.replaceChild(this._rootElement, this._anchor);
926
+ this._destroyPreview();
927
+ this._destroyPlaceholder();
928
+ this._initialClientRect =
929
+ this._boundaryRect =
930
+ this._previewRect =
931
+ this._initialTransform =
932
+ undefined;
933
+ // Re-enter the NgZone since we bound `document` events on the outside.
934
+ this._ngZone.run(() => {
935
+ const container = this._dropContainer;
936
+ const currentIndex = container.getItemIndex(this);
937
+ const pointerPosition = this._getPointerPositionOnPage(event);
938
+ const distance = this._getDragDistance(pointerPosition);
939
+ const isPointerOverContainer = container._isOverContainer(pointerPosition.x, pointerPosition.y);
940
+ this.ended.next({ source: this, distance, dropPoint: pointerPosition, event });
941
+ this.dropped.next({
942
+ item: this,
943
+ currentIndex,
944
+ previousIndex: this._initialIndex,
945
+ container: container,
946
+ previousContainer: this._initialContainer,
947
+ isPointerOverContainer,
948
+ distance,
949
+ dropPoint: pointerPosition,
950
+ event,
951
+ });
952
+ container.drop(this, currentIndex, this._initialIndex, this._initialContainer, isPointerOverContainer, distance, pointerPosition, event);
953
+ this._dropContainer = this._initialContainer;
954
+ });
955
+ }
956
+ /**
957
+ * Updates the item's position in its drop container, or moves it
958
+ * into a new one, depending on its current drag position.
959
+ */
960
+ _updateActiveDropContainer({ x, y }, { x: rawX, y: rawY }) {
961
+ // Drop container that draggable has been moved into.
962
+ let newContainer = this._initialContainer._getSiblingContainerFromPosition(this, x, y);
963
+ // If we couldn't find a new container to move the item into, and the item has left its
964
+ // initial container, check whether the it's over the initial container. This handles the
965
+ // case where two containers are connected one way and the user tries to undo dragging an
966
+ // item into a new container.
967
+ if (!newContainer &&
968
+ this._dropContainer !== this._initialContainer &&
969
+ this._initialContainer._isOverContainer(x, y)) {
970
+ newContainer = this._initialContainer;
971
+ }
972
+ if (newContainer && newContainer !== this._dropContainer) {
973
+ this._ngZone.run(() => {
974
+ // Notify the old container that the item has left.
975
+ this.exited.next({ item: this, container: this._dropContainer });
976
+ this._dropContainer.exit(this);
977
+ // Notify the new container that the item has entered.
978
+ this._dropContainer = newContainer;
979
+ this._dropContainer.enter(this, x, y, newContainer === this._initialContainer &&
980
+ // If we're re-entering the initial container and sorting is disabled,
981
+ // put item the into its starting index to begin with.
982
+ newContainer.sortingDisabled
983
+ ? this._initialIndex
984
+ : undefined);
985
+ this.entered.next({
986
+ item: this,
987
+ container: newContainer,
988
+ currentIndex: newContainer.getItemIndex(this),
989
+ });
990
+ });
991
+ }
992
+ // Dragging may have been interrupted as a result of the events above.
993
+ if (this.isDragging()) {
994
+ this._dropContainer._startScrollingIfNecessary(rawX, rawY);
995
+ this._dropContainer._sortItem(this, x, y, this._pointerDirectionDelta);
996
+ if (this.constrainPosition) {
997
+ this._applyPreviewTransform(x, y);
998
+ }
999
+ else {
1000
+ this._applyPreviewTransform(x - this._pickupPositionInElement.x, y - this._pickupPositionInElement.y);
1001
+ }
1002
+ }
1003
+ }
1004
+ /**
1005
+ * Creates the element that will be rendered next to the user's pointer
1006
+ * and will be used as a preview of the element that is being dragged.
1007
+ */
1008
+ _createPreviewElement() {
1009
+ const previewConfig = this._previewTemplate;
1010
+ const previewClass = this.previewClass;
1011
+ const previewTemplate = previewConfig ? previewConfig.template : null;
1012
+ let preview;
1013
+ if (previewTemplate && previewConfig) {
1014
+ // Measure the element before we've inserted the preview
1015
+ // since the insertion could throw off the measurement.
1016
+ const rootRect = previewConfig.matchSize ? this._initialClientRect : null;
1017
+ const viewRef = previewConfig.viewContainer.createEmbeddedView(previewTemplate, previewConfig.context);
1018
+ viewRef.detectChanges();
1019
+ preview = getRootNode(viewRef, this._document);
1020
+ this._previewRef = viewRef;
1021
+ if (previewConfig.matchSize) {
1022
+ matchElementSize(preview, rootRect);
1023
+ }
1024
+ else {
1025
+ preview.style.transform = getTransform(this._pickupPositionOnPage.x, this._pickupPositionOnPage.y);
1026
+ }
1027
+ }
1028
+ else {
1029
+ preview = deepCloneNode(this._rootElement);
1030
+ matchElementSize(preview, this._initialClientRect);
1031
+ if (this._initialTransform) {
1032
+ preview.style.transform = this._initialTransform;
1033
+ }
1034
+ }
1035
+ extendStyles(preview.style, {
1036
+ // It's important that we disable the pointer events on the preview, because
1037
+ // it can throw off the `document.elementFromPoint` calls in the `CdkDropList`.
1038
+ 'pointer-events': 'none',
1039
+ // We have to reset the margin, because it can throw off positioning relative to the viewport.
1040
+ 'margin': '0',
1041
+ 'position': 'fixed',
1042
+ 'top': '0',
1043
+ 'left': '0',
1044
+ 'z-index': `${this._config.zIndex || 1000}`,
1045
+ }, dragImportantProperties);
1046
+ toggleNativeDragInteractions(preview, false);
1047
+ preview.classList.add('cdk-drag-preview');
1048
+ preview.setAttribute('dir', this._direction);
1049
+ if (previewClass) {
1050
+ if (Array.isArray(previewClass)) {
1051
+ previewClass.forEach(className => preview.classList.add(className));
1052
+ }
1053
+ else {
1054
+ preview.classList.add(previewClass);
1055
+ }
1056
+ }
1057
+ return preview;
1058
+ }
1059
+ /**
1060
+ * Animates the preview element from its current position to the location of the drop placeholder.
1061
+ * @returns Promise that resolves when the animation completes.
1062
+ */
1063
+ _animatePreviewToPlaceholder() {
1064
+ // If the user hasn't moved yet, the transitionend event won't fire.
1065
+ if (!this._hasMoved) {
1066
+ return Promise.resolve();
1067
+ }
1068
+ const placeholderRect = this._placeholder.getBoundingClientRect();
1069
+ // Apply the class that adds a transition to the preview.
1070
+ this._preview.classList.add('cdk-drag-animating');
1071
+ // Move the preview to the placeholder position.
1072
+ this._applyPreviewTransform(placeholderRect.left, placeholderRect.top);
1073
+ // If the element doesn't have a `transition`, the `transitionend` event won't fire. Since
1074
+ // we need to trigger a style recalculation in order for the `cdk-drag-animating` class to
1075
+ // apply its style, we take advantage of the available info to figure out whether we need to
1076
+ // bind the event in the first place.
1077
+ const duration = getTransformTransitionDurationInMs(this._preview);
1078
+ if (duration === 0) {
1079
+ return Promise.resolve();
1080
+ }
1081
+ return this._ngZone.runOutsideAngular(() => {
1082
+ return new Promise(resolve => {
1083
+ const handler = ((event) => {
1084
+ var _a;
1085
+ if (!event ||
1086
+ (_getEventTarget(event) === this._preview && event.propertyName === 'transform')) {
1087
+ (_a = this._preview) === null || _a === void 0 ? void 0 : _a.removeEventListener('transitionend', handler);
1088
+ resolve();
1089
+ clearTimeout(timeout);
1090
+ }
1091
+ });
1092
+ // If a transition is short enough, the browser might not fire the `transitionend` event.
1093
+ // Since we know how long it's supposed to take, add a timeout with a 50% buffer that'll
1094
+ // fire if the transition hasn't completed when it was supposed to.
1095
+ const timeout = setTimeout(handler, duration * 1.5);
1096
+ this._preview.addEventListener('transitionend', handler);
1097
+ });
1098
+ });
1099
+ }
1100
+ /** Creates an element that will be shown instead of the current element while dragging. */
1101
+ _createPlaceholderElement() {
1102
+ const placeholderConfig = this._placeholderTemplate;
1103
+ const placeholderTemplate = placeholderConfig ? placeholderConfig.template : null;
1104
+ let placeholder;
1105
+ if (placeholderTemplate) {
1106
+ this._placeholderRef = placeholderConfig.viewContainer.createEmbeddedView(placeholderTemplate, placeholderConfig.context);
1107
+ this._placeholderRef.detectChanges();
1108
+ placeholder = getRootNode(this._placeholderRef, this._document);
1109
+ }
1110
+ else {
1111
+ placeholder = deepCloneNode(this._rootElement);
1112
+ }
1113
+ // Stop pointer events on the preview so the user can't
1114
+ // interact with it while the preview is animating.
1115
+ placeholder.style.pointerEvents = 'none';
1116
+ placeholder.classList.add('cdk-drag-placeholder');
1117
+ return placeholder;
1118
+ }
1119
+ /**
1120
+ * Figures out the coordinates at which an element was picked up.
1121
+ * @param referenceElement Element that initiated the dragging.
1122
+ * @param event Event that initiated the dragging.
1123
+ */
1124
+ _getPointerPositionInElement(elementRect, referenceElement, event) {
1125
+ const handleElement = referenceElement === this._rootElement ? null : referenceElement;
1126
+ const referenceRect = handleElement ? handleElement.getBoundingClientRect() : elementRect;
1127
+ const point = isTouchEvent(event) ? event.targetTouches[0] : event;
1128
+ const scrollPosition = this._getViewportScrollPosition();
1129
+ const x = point.pageX - referenceRect.left - scrollPosition.left;
1130
+ const y = point.pageY - referenceRect.top - scrollPosition.top;
1131
+ return {
1132
+ x: referenceRect.left - elementRect.left + x,
1133
+ y: referenceRect.top - elementRect.top + y,
1134
+ };
1135
+ }
1136
+ /** Determines the point of the page that was touched by the user. */
1137
+ _getPointerPositionOnPage(event) {
1138
+ const scrollPosition = this._getViewportScrollPosition();
1139
+ const point = isTouchEvent(event)
1140
+ ? // `touches` will be empty for start/end events so we have to fall back to `changedTouches`.
1141
+ // Also note that on real devices we're guaranteed for either `touches` or `changedTouches`
1142
+ // to have a value, but Firefox in device emulation mode has a bug where both can be empty
1143
+ // for `touchstart` and `touchend` so we fall back to a dummy object in order to avoid
1144
+ // throwing an error. The value returned here will be incorrect, but since this only
1145
+ // breaks inside a developer tool and the value is only used for secondary information,
1146
+ // we can get away with it. See https://bugzilla.mozilla.org/show_bug.cgi?id=1615824.
1147
+ event.touches[0] || event.changedTouches[0] || { pageX: 0, pageY: 0 }
1148
+ : event;
1149
+ const x = point.pageX - scrollPosition.left;
1150
+ const y = point.pageY - scrollPosition.top;
1151
+ // if dragging SVG element, try to convert from the screen coordinate system to the SVG
1152
+ // coordinate system
1153
+ if (this._ownerSVGElement) {
1154
+ const svgMatrix = this._ownerSVGElement.getScreenCTM();
1155
+ if (svgMatrix) {
1156
+ const svgPoint = this._ownerSVGElement.createSVGPoint();
1157
+ svgPoint.x = x;
1158
+ svgPoint.y = y;
1159
+ return svgPoint.matrixTransform(svgMatrix.inverse());
1160
+ }
1161
+ }
1162
+ return { x, y };
1163
+ }
1164
+ /** Gets the pointer position on the page, accounting for any position constraints. */
1165
+ _getConstrainedPointerPosition(point) {
1166
+ const dropContainerLock = this._dropContainer ? this._dropContainer.lockAxis : null;
1167
+ let { x, y } = this.constrainPosition
1168
+ ? this.constrainPosition(point, this, this._initialClientRect, this._pickupPositionInElement)
1169
+ : point;
1170
+ if (this.lockAxis === 'x' || dropContainerLock === 'x') {
1171
+ y = this._pickupPositionOnPage.y;
1172
+ }
1173
+ else if (this.lockAxis === 'y' || dropContainerLock === 'y') {
1174
+ x = this._pickupPositionOnPage.x;
1175
+ }
1176
+ if (this._boundaryRect) {
1177
+ const { x: pickupX, y: pickupY } = this._pickupPositionInElement;
1178
+ const boundaryRect = this._boundaryRect;
1179
+ const { width: previewWidth, height: previewHeight } = this._getPreviewRect();
1180
+ const minY = boundaryRect.top + pickupY;
1181
+ const maxY = boundaryRect.bottom - (previewHeight - pickupY);
1182
+ const minX = boundaryRect.left + pickupX;
1183
+ const maxX = boundaryRect.right - (previewWidth - pickupX);
1184
+ x = clamp$1(x, minX, maxX);
1185
+ y = clamp$1(y, minY, maxY);
1186
+ }
1187
+ return { x, y };
1188
+ }
1189
+ /** Updates the current drag delta, based on the user's current pointer position on the page. */
1190
+ _updatePointerDirectionDelta(pointerPositionOnPage) {
1191
+ const { x, y } = pointerPositionOnPage;
1192
+ const delta = this._pointerDirectionDelta;
1193
+ const positionSinceLastChange = this._pointerPositionAtLastDirectionChange;
1194
+ // Amount of pixels the user has dragged since the last time the direction changed.
1195
+ const changeX = Math.abs(x - positionSinceLastChange.x);
1196
+ const changeY = Math.abs(y - positionSinceLastChange.y);
1197
+ // Because we handle pointer events on a per-pixel basis, we don't want the delta
1198
+ // to change for every pixel, otherwise anything that depends on it can look erratic.
1199
+ // To make the delta more consistent, we track how much the user has moved since the last
1200
+ // delta change and we only update it after it has reached a certain threshold.
1201
+ if (changeX > this._config.pointerDirectionChangeThreshold) {
1202
+ delta.x = x > positionSinceLastChange.x ? 1 : -1;
1203
+ positionSinceLastChange.x = x;
1204
+ }
1205
+ if (changeY > this._config.pointerDirectionChangeThreshold) {
1206
+ delta.y = y > positionSinceLastChange.y ? 1 : -1;
1207
+ positionSinceLastChange.y = y;
1208
+ }
1209
+ return delta;
1210
+ }
1211
+ /** Toggles the native drag interactions, based on how many handles are registered. */
1212
+ _toggleNativeDragInteractions() {
1213
+ if (!this._rootElement || !this._handles) {
1214
+ return;
1215
+ }
1216
+ const shouldEnable = this._handles.length > 0 || !this.isDragging();
1217
+ if (shouldEnable !== this._nativeInteractionsEnabled) {
1218
+ this._nativeInteractionsEnabled = shouldEnable;
1219
+ toggleNativeDragInteractions(this._rootElement, shouldEnable);
1220
+ }
1221
+ }
1222
+ /** Removes the manually-added event listeners from the root element. */
1223
+ _removeRootElementListeners(element) {
1224
+ element.removeEventListener('mousedown', this._pointerDown, activeEventListenerOptions);
1225
+ element.removeEventListener('touchstart', this._pointerDown, passiveEventListenerOptions);
1226
+ element.removeEventListener('dragstart', this._nativeDragStart, activeEventListenerOptions);
1227
+ }
1228
+ /**
1229
+ * Applies a `transform` to the root element, taking into account any existing transforms on it.
1230
+ * @param x New transform value along the X axis.
1231
+ * @param y New transform value along the Y axis.
1232
+ */
1233
+ _applyRootElementTransform(x, y) {
1234
+ const transform = getTransform(x, y);
1235
+ const styles = this._rootElement.style;
1236
+ // Cache the previous transform amount only after the first drag sequence, because
1237
+ // we don't want our own transforms to stack on top of each other.
1238
+ // Should be excluded none because none + translate3d(x, y, x) is invalid css
1239
+ if (this._initialTransform == null) {
1240
+ this._initialTransform =
1241
+ styles.transform && styles.transform != 'none' ? styles.transform : '';
1242
+ }
1243
+ // Preserve the previous `transform` value, if there was one. Note that we apply our own
1244
+ // transform before the user's, because things like rotation can affect which direction
1245
+ // the element will be translated towards.
1246
+ styles.transform = combineTransforms(transform, this._initialTransform);
1247
+ }
1248
+ /**
1249
+ * Applies a `transform` to the preview, taking into account any existing transforms on it.
1250
+ * @param x New transform value along the X axis.
1251
+ * @param y New transform value along the Y axis.
1252
+ */
1253
+ _applyPreviewTransform(x, y) {
1254
+ var _a;
1255
+ // Only apply the initial transform if the preview is a clone of the original element, otherwise
1256
+ // it could be completely different and the transform might not make sense anymore.
1257
+ const initialTransform = ((_a = this._previewTemplate) === null || _a === void 0 ? void 0 : _a.template) ? undefined : this._initialTransform;
1258
+ const transform = getTransform(x, y);
1259
+ this._preview.style.transform = combineTransforms(transform, initialTransform);
1260
+ }
1261
+ /**
1262
+ * Gets the distance that the user has dragged during the current drag sequence.
1263
+ * @param currentPosition Current position of the user's pointer.
1264
+ */
1265
+ _getDragDistance(currentPosition) {
1266
+ const pickupPosition = this._pickupPositionOnPage;
1267
+ if (pickupPosition) {
1268
+ return { x: currentPosition.x - pickupPosition.x, y: currentPosition.y - pickupPosition.y };
1269
+ }
1270
+ return { x: 0, y: 0 };
1271
+ }
1272
+ /** Cleans up any cached element dimensions that we don't need after dragging has stopped. */
1273
+ _cleanupCachedDimensions() {
1274
+ this._boundaryRect = this._previewRect = undefined;
1275
+ this._parentPositions.clear();
1276
+ }
1277
+ /**
1278
+ * Checks whether the element is still inside its boundary after the viewport has been resized.
1279
+ * If not, the position is adjusted so that the element fits again.
1280
+ */
1281
+ _containInsideBoundaryOnResize() {
1282
+ let { x, y } = this._passiveTransform;
1283
+ if ((x === 0 && y === 0) || this.isDragging() || !this._boundaryElement) {
1284
+ return;
1285
+ }
1286
+ // Note: don't use `_clientRectAtStart` here, because we want the latest position.
1287
+ const elementRect = this._rootElement.getBoundingClientRect();
1288
+ const boundaryRect = this._boundaryElement.getBoundingClientRect();
1289
+ // It's possible that the element got hidden away after dragging (e.g. by switching to a
1290
+ // different tab). Don't do anything in this case so we don't clear the user's position.
1291
+ if ((boundaryRect.width === 0 && boundaryRect.height === 0) ||
1292
+ (elementRect.width === 0 && elementRect.height === 0)) {
1293
+ return;
1294
+ }
1295
+ const leftOverflow = boundaryRect.left - elementRect.left;
1296
+ const rightOverflow = elementRect.right - boundaryRect.right;
1297
+ const topOverflow = boundaryRect.top - elementRect.top;
1298
+ const bottomOverflow = elementRect.bottom - boundaryRect.bottom;
1299
+ // If the element has become wider than the boundary, we can't
1300
+ // do much to make it fit so we just anchor it to the left.
1301
+ if (boundaryRect.width > elementRect.width) {
1302
+ if (leftOverflow > 0) {
1303
+ x += leftOverflow;
1304
+ }
1305
+ if (rightOverflow > 0) {
1306
+ x -= rightOverflow;
1307
+ }
1308
+ }
1309
+ else {
1310
+ x = 0;
1311
+ }
1312
+ // If the element has become taller than the boundary, we can't
1313
+ // do much to make it fit so we just anchor it to the top.
1314
+ if (boundaryRect.height > elementRect.height) {
1315
+ if (topOverflow > 0) {
1316
+ y += topOverflow;
1317
+ }
1318
+ if (bottomOverflow > 0) {
1319
+ y -= bottomOverflow;
1320
+ }
1321
+ }
1322
+ else {
1323
+ y = 0;
1324
+ }
1325
+ if (x !== this._passiveTransform.x || y !== this._passiveTransform.y) {
1326
+ this.setFreeDragPosition({ y, x });
1327
+ }
1328
+ }
1329
+ /** Gets the drag start delay, based on the event type. */
1330
+ _getDragStartDelay(event) {
1331
+ const value = this.dragStartDelay;
1332
+ if (typeof value === 'number') {
1333
+ return value;
1334
+ }
1335
+ else if (isTouchEvent(event)) {
1336
+ return value.touch;
1337
+ }
1338
+ return value ? value.mouse : 0;
1339
+ }
1340
+ /** Updates the internal state of the draggable element when scrolling has occurred. */
1341
+ _updateOnScroll(event) {
1342
+ const scrollDifference = this._parentPositions.handleScroll(event);
1343
+ if (scrollDifference) {
1344
+ const target = _getEventTarget(event);
1345
+ // ClientRect dimensions are based on the scroll position of the page and its parent
1346
+ // node so we have to update the cached boundary ClientRect if the user has scrolled.
1347
+ if (this._boundaryRect &&
1348
+ target !== this._boundaryElement &&
1349
+ target.contains(this._boundaryElement)) {
1350
+ adjustClientRect(this._boundaryRect, scrollDifference.top, scrollDifference.left);
1351
+ }
1352
+ this._pickupPositionOnPage.x += scrollDifference.left;
1353
+ this._pickupPositionOnPage.y += scrollDifference.top;
1354
+ // If we're in free drag mode, we have to update the active transform, because
1355
+ // it isn't relative to the viewport like the preview inside a drop list.
1356
+ if (!this._dropContainer) {
1357
+ this._activeTransform.x -= scrollDifference.left;
1358
+ this._activeTransform.y -= scrollDifference.top;
1359
+ this._applyRootElementTransform(this._activeTransform.x, this._activeTransform.y);
1360
+ }
1361
+ }
1362
+ }
1363
+ /** Gets the scroll position of the viewport. */
1364
+ _getViewportScrollPosition() {
1365
+ var _a;
1366
+ return (((_a = this._parentPositions.positions.get(this._document)) === null || _a === void 0 ? void 0 : _a.scrollPosition) ||
1367
+ this._parentPositions.getViewportScrollPosition());
1368
+ }
1369
+ /**
1370
+ * Lazily resolves and returns the shadow root of the element. We do this in a function, rather
1371
+ * than saving it in property directly on init, because we want to resolve it as late as possible
1372
+ * in order to ensure that the element has been moved into the shadow DOM. Doing it inside the
1373
+ * constructor might be too early if the element is inside of something like `ngFor` or `ngIf`.
1374
+ */
1375
+ _getShadowRoot() {
1376
+ if (this._cachedShadowRoot === undefined) {
1377
+ this._cachedShadowRoot = _getShadowRoot(this._rootElement);
1378
+ }
1379
+ return this._cachedShadowRoot;
1380
+ }
1381
+ /** Gets the element into which the drag preview should be inserted. */
1382
+ _getPreviewInsertionPoint(initialParent, shadowRoot) {
1383
+ const previewContainer = this._previewContainer || 'global';
1384
+ if (previewContainer === 'parent') {
1385
+ return initialParent;
1386
+ }
1387
+ if (previewContainer === 'global') {
1388
+ const documentRef = this._document;
1389
+ // We can't use the body if the user is in fullscreen mode,
1390
+ // because the preview will render under the fullscreen element.
1391
+ // TODO(crisbeto): dedupe this with the `FullscreenOverlayContainer` eventually.
1392
+ return (shadowRoot ||
1393
+ documentRef.fullscreenElement ||
1394
+ documentRef.webkitFullscreenElement ||
1395
+ documentRef.mozFullScreenElement ||
1396
+ documentRef.msFullscreenElement ||
1397
+ documentRef.body);
1398
+ }
1399
+ return coerceElement(previewContainer);
1400
+ }
1401
+ /** Lazily resolves and returns the dimensions of the preview. */
1402
+ _getPreviewRect() {
1403
+ // Cache the preview element rect if we haven't cached it already or if
1404
+ // we cached it too early before the element dimensions were computed.
1405
+ if (!this._previewRect || (!this._previewRect.width && !this._previewRect.height)) {
1406
+ this._previewRect = this._preview
1407
+ ? this._preview.getBoundingClientRect()
1408
+ : this._initialClientRect;
1409
+ }
1410
+ return this._previewRect;
1411
+ }
1412
+ /** Gets a handle that is the target of an event. */
1413
+ _getTargetHandle(event) {
1414
+ return this._handles.find(handle => {
1415
+ return event.target && (event.target === handle || handle.contains(event.target));
1416
+ });
1417
+ }
1418
+ }
1419
+ /**
1420
+ * Gets a 3d `transform` that can be applied to an element.
1421
+ * @param x Desired position of the element along the X axis.
1422
+ * @param y Desired position of the element along the Y axis.
1423
+ */
1424
+ function getTransform(x, y) {
1425
+ // Round the transforms since some browsers will
1426
+ // blur the elements for sub-pixel transforms.
1427
+ return `translate3d(${Math.round(x)}px, ${Math.round(y)}px, 0)`;
1428
+ }
1429
+ /** Clamps a value between a minimum and a maximum. */
1430
+ function clamp$1(value, min, max) {
1431
+ return Math.max(min, Math.min(max, value));
1432
+ }
1433
+ /** Determines whether an event is a touch event. */
1434
+ function isTouchEvent(event) {
1435
+ // This function is called for every pixel that the user has dragged so we need it to be
1436
+ // as fast as possible. Since we only bind mouse events and touch events, we can assume
1437
+ // that if the event's name starts with `t`, it's a touch event.
1438
+ return event.type[0] === 't';
1439
+ }
1440
+ /**
1441
+ * Gets the root HTML element of an embedded view.
1442
+ * If the root is not an HTML element it gets wrapped in one.
1443
+ */
1444
+ function getRootNode(viewRef, _document) {
1445
+ const rootNodes = viewRef.rootNodes;
1446
+ if (rootNodes.length === 1 && rootNodes[0].nodeType === _document.ELEMENT_NODE) {
1447
+ return rootNodes[0];
1448
+ }
1449
+ const wrapper = _document.createElement('div');
1450
+ rootNodes.forEach(node => wrapper.appendChild(node));
1451
+ return wrapper;
1452
+ }
1453
+ /**
1454
+ * Matches the target element's size to the source's size.
1455
+ * @param target Element that needs to be resized.
1456
+ * @param sourceRect Dimensions of the source element.
1457
+ */
1458
+ function matchElementSize(target, sourceRect) {
1459
+ target.style.width = `${sourceRect.width}px`;
1460
+ target.style.height = `${sourceRect.height}px`;
1461
+ target.style.transform = getTransform(sourceRect.left, sourceRect.top);
1462
+ }
1463
+
1464
+ /**
1465
+ * @license
1466
+ * Copyright Google LLC All Rights Reserved.
1467
+ *
1468
+ * Use of this source code is governed by an MIT-style license that can be
1469
+ * found in the LICENSE file at https://angular.io/license
1470
+ */
1471
+ /**
1472
+ * Moves an item one index in an array to another.
1473
+ * @param array Array in which to move the item.
1474
+ * @param fromIndex Starting index of the item.
1475
+ * @param toIndex Index to which the item should be moved.
1476
+ */
1477
+ function moveItemInArray(array, fromIndex, toIndex) {
1478
+ const from = clamp(fromIndex, array.length - 1);
1479
+ const to = clamp(toIndex, array.length - 1);
1480
+ if (from === to) {
1481
+ return;
1482
+ }
1483
+ const target = array[from];
1484
+ const delta = to < from ? -1 : 1;
1485
+ for (let i = from; i !== to; i += delta) {
1486
+ array[i] = array[i + delta];
1487
+ }
1488
+ array[to] = target;
1489
+ }
1490
+ /**
1491
+ * Moves an item from one array to another.
1492
+ * @param currentArray Array from which to transfer the item.
1493
+ * @param targetArray Array into which to put the item.
1494
+ * @param currentIndex Index of the item in its current array.
1495
+ * @param targetIndex Index at which to insert the item.
1496
+ */
1497
+ function transferArrayItem(currentArray, targetArray, currentIndex, targetIndex) {
1498
+ const from = clamp(currentIndex, currentArray.length - 1);
1499
+ const to = clamp(targetIndex, targetArray.length);
1500
+ if (currentArray.length) {
1501
+ targetArray.splice(to, 0, currentArray.splice(from, 1)[0]);
1502
+ }
1503
+ }
1504
+ /**
1505
+ * Copies an item from one array to another, leaving it in its
1506
+ * original position in current array.
1507
+ * @param currentArray Array from which to copy the item.
1508
+ * @param targetArray Array into which is copy the item.
1509
+ * @param currentIndex Index of the item in its current array.
1510
+ * @param targetIndex Index at which to insert the item.
1511
+ *
1512
+ */
1513
+ function copyArrayItem(currentArray, targetArray, currentIndex, targetIndex) {
1514
+ const to = clamp(targetIndex, targetArray.length);
1515
+ if (currentArray.length) {
1516
+ targetArray.splice(to, 0, currentArray[currentIndex]);
1517
+ }
1518
+ }
1519
+ /** Clamps a number between zero and a maximum. */
1520
+ function clamp(value, max) {
1521
+ return Math.max(0, Math.min(max, value));
1522
+ }
1523
+
1524
+ /**
1525
+ * @license
1526
+ * Copyright Google LLC All Rights Reserved.
1527
+ *
1528
+ * Use of this source code is governed by an MIT-style license that can be
1529
+ * found in the LICENSE file at https://angular.io/license
1530
+ */
1531
+ /**
1532
+ * Strategy that only supports sorting along a single axis.
1533
+ * Items are reordered using CSS transforms which allows for sorting to be animated.
1534
+ * @docs-private
1535
+ */
1536
+ class SingleAxisSortStrategy {
1537
+ constructor(_element, _dragDropRegistry) {
1538
+ this._element = _element;
1539
+ this._dragDropRegistry = _dragDropRegistry;
1540
+ /** Cache of the dimensions of all the items inside the container. */
1541
+ this._itemPositions = [];
1542
+ /** Direction in which the list is oriented. */
1543
+ this.orientation = 'vertical';
1544
+ /**
1545
+ * Keeps track of the item that was last swapped with the dragged item, as well as what direction
1546
+ * the pointer was moving in when the swap occurred and whether the user's pointer continued to
1547
+ * overlap with the swapped item after the swapping occurred.
1548
+ */
1549
+ this._previousSwap = {
1550
+ drag: null,
1551
+ delta: 0,
1552
+ overlaps: false,
1553
+ };
1554
+ }
1555
+ /**
1556
+ * To be called when the drag sequence starts.
1557
+ * @param items Items that are currently in the list.
1558
+ */
1559
+ start(items) {
1560
+ this.withItems(items);
1561
+ }
1562
+ /**
1563
+ * To be called when an item is being sorted.
1564
+ * @param item Item to be sorted.
1565
+ * @param pointerX Position of the item along the X axis.
1566
+ * @param pointerY Position of the item along the Y axis.
1567
+ * @param pointerDelta Direction in which the pointer is moving along each axis.
1568
+ */
1569
+ sort(item, pointerX, pointerY, pointerDelta) {
1570
+ const siblings = this._itemPositions;
1571
+ const newIndex = this._getItemIndexFromPointerPosition(item, pointerX, pointerY, pointerDelta);
1572
+ if (newIndex === -1 && siblings.length > 0) {
1573
+ return null;
1574
+ }
1575
+ const isHorizontal = this.orientation === 'horizontal';
1576
+ const currentIndex = siblings.findIndex(currentItem => currentItem.drag === item);
1577
+ const siblingAtNewPosition = siblings[newIndex];
1578
+ const currentPosition = siblings[currentIndex].clientRect;
1579
+ const newPosition = siblingAtNewPosition.clientRect;
1580
+ const delta = currentIndex > newIndex ? 1 : -1;
1581
+ // How many pixels the item's placeholder should be offset.
1582
+ const itemOffset = this._getItemOffsetPx(currentPosition, newPosition, delta);
1583
+ // How many pixels all the other items should be offset.
1584
+ const siblingOffset = this._getSiblingOffsetPx(currentIndex, siblings, delta);
1585
+ // Save the previous order of the items before moving the item to its new index.
1586
+ // We use this to check whether an item has been moved as a result of the sorting.
1587
+ const oldOrder = siblings.slice();
1588
+ // Shuffle the array in place.
1589
+ moveItemInArray(siblings, currentIndex, newIndex);
1590
+ siblings.forEach((sibling, index) => {
1591
+ // Don't do anything if the position hasn't changed.
1592
+ if (oldOrder[index] === sibling) {
1593
+ return;
1594
+ }
1595
+ const isDraggedItem = sibling.drag === item;
1596
+ const offset = isDraggedItem ? itemOffset : siblingOffset;
1597
+ const elementToOffset = isDraggedItem
1598
+ ? item.getPlaceholderElement()
1599
+ : sibling.drag.getRootElement();
1600
+ // Update the offset to reflect the new position.
1601
+ sibling.offset += offset;
1602
+ // Since we're moving the items with a `transform`, we need to adjust their cached
1603
+ // client rects to reflect their new position, as well as swap their positions in the cache.
1604
+ // Note that we shouldn't use `getBoundingClientRect` here to update the cache, because the
1605
+ // elements may be mid-animation which will give us a wrong result.
1606
+ if (isHorizontal) {
1607
+ // Round the transforms since some browsers will
1608
+ // blur the elements, for sub-pixel transforms.
1609
+ elementToOffset.style.transform = combineTransforms(`translate3d(${Math.round(sibling.offset)}px, 0, 0)`, sibling.initialTransform);
1610
+ adjustClientRect(sibling.clientRect, 0, offset);
1611
+ }
1612
+ else {
1613
+ elementToOffset.style.transform = combineTransforms(`translate3d(0, ${Math.round(sibling.offset)}px, 0)`, sibling.initialTransform);
1614
+ adjustClientRect(sibling.clientRect, offset, 0);
1615
+ }
1616
+ });
1617
+ // Note that it's important that we do this after the client rects have been adjusted.
1618
+ this._previousSwap.overlaps = isInsideClientRect(newPosition, pointerX, pointerY);
1619
+ this._previousSwap.drag = siblingAtNewPosition.drag;
1620
+ this._previousSwap.delta = isHorizontal ? pointerDelta.x : pointerDelta.y;
1621
+ return { previousIndex: currentIndex, currentIndex: newIndex };
1622
+ }
1623
+ /**
1624
+ * Called when an item is being moved into the container.
1625
+ * @param item Item that was moved into the container.
1626
+ * @param pointerX Position of the item along the X axis.
1627
+ * @param pointerY Position of the item along the Y axis.
1628
+ * @param index Index at which the item entered. If omitted, the container will try to figure it
1629
+ * out automatically.
1630
+ */
1631
+ enter(item, pointerX, pointerY, index) {
1632
+ const newIndex = index == null || index < 0
1633
+ ? // We use the coordinates of where the item entered the drop
1634
+ // zone to figure out at which index it should be inserted.
1635
+ this._getItemIndexFromPointerPosition(item, pointerX, pointerY)
1636
+ : index;
1637
+ const activeDraggables = this._activeDraggables;
1638
+ const currentIndex = activeDraggables.indexOf(item);
1639
+ const placeholder = item.getPlaceholderElement();
1640
+ let newPositionReference = activeDraggables[newIndex];
1641
+ // If the item at the new position is the same as the item that is being dragged,
1642
+ // it means that we're trying to restore the item to its initial position. In this
1643
+ // case we should use the next item from the list as the reference.
1644
+ if (newPositionReference === item) {
1645
+ newPositionReference = activeDraggables[newIndex + 1];
1646
+ }
1647
+ // If we didn't find a new position reference, it means that either the item didn't start off
1648
+ // in this container, or that the item requested to be inserted at the end of the list.
1649
+ if (!newPositionReference &&
1650
+ (newIndex == null || newIndex === -1 || newIndex < activeDraggables.length - 1) &&
1651
+ this._shouldEnterAsFirstChild(pointerX, pointerY)) {
1652
+ newPositionReference = activeDraggables[0];
1653
+ }
1654
+ // Since the item may be in the `activeDraggables` already (e.g. if the user dragged it
1655
+ // into another container and back again), we have to ensure that it isn't duplicated.
1656
+ if (currentIndex > -1) {
1657
+ activeDraggables.splice(currentIndex, 1);
1658
+ }
1659
+ // Don't use items that are being dragged as a reference, because
1660
+ // their element has been moved down to the bottom of the body.
1661
+ if (newPositionReference && !this._dragDropRegistry.isDragging(newPositionReference)) {
1662
+ const element = newPositionReference.getRootElement();
1663
+ element.parentElement.insertBefore(placeholder, element);
1664
+ activeDraggables.splice(newIndex, 0, item);
1665
+ }
1666
+ else {
1667
+ coerceElement(this._element).appendChild(placeholder);
1668
+ activeDraggables.push(item);
1669
+ }
1670
+ // The transform needs to be cleared so it doesn't throw off the measurements.
1671
+ placeholder.style.transform = '';
1672
+ // Note that usually `start` is called together with `enter` when an item goes into a new
1673
+ // container. This will cache item positions, but we need to refresh them since the amount
1674
+ // of items has changed.
1675
+ this._cacheItemPositions();
1676
+ }
1677
+ /** Sets the items that are currently part of the list. */
1678
+ withItems(items) {
1679
+ this._activeDraggables = items.slice();
1680
+ this._cacheItemPositions();
1681
+ }
1682
+ /** Assigns a sort predicate to the strategy. */
1683
+ withSortPredicate(predicate) {
1684
+ this._sortPredicate = predicate;
1685
+ }
1686
+ /** Resets the strategy to its initial state before dragging was started. */
1687
+ reset() {
1688
+ // TODO(crisbeto): may have to wait for the animations to finish.
1689
+ this._activeDraggables.forEach(item => {
1690
+ var _a;
1691
+ const rootElement = item.getRootElement();
1692
+ if (rootElement) {
1693
+ const initialTransform = (_a = this._itemPositions.find(p => p.drag === item)) === null || _a === void 0 ? void 0 : _a.initialTransform;
1694
+ rootElement.style.transform = initialTransform || '';
1695
+ }
1696
+ });
1697
+ this._itemPositions = [];
1698
+ this._activeDraggables = [];
1699
+ this._previousSwap.drag = null;
1700
+ this._previousSwap.delta = 0;
1701
+ this._previousSwap.overlaps = false;
1702
+ }
1703
+ /**
1704
+ * Gets a snapshot of items currently in the list.
1705
+ * Can include items that we dragged in from another list.
1706
+ */
1707
+ getActiveItemsSnapshot() {
1708
+ return this._activeDraggables;
1709
+ }
1710
+ /** Gets the index of a specific item. */
1711
+ getItemIndex(item) {
1712
+ // Items are sorted always by top/left in the cache, however they flow differently in RTL.
1713
+ // The rest of the logic still stands no matter what orientation we're in, however
1714
+ // we need to invert the array when determining the index.
1715
+ const items = this.orientation === 'horizontal' && this.direction === 'rtl'
1716
+ ? this._itemPositions.slice().reverse()
1717
+ : this._itemPositions;
1718
+ return items.findIndex(currentItem => currentItem.drag === item);
1719
+ }
1720
+ /** Used to notify the strategy that the scroll position has changed. */
1721
+ updateOnScroll(topDifference, leftDifference) {
1722
+ // Since we know the amount that the user has scrolled we can shift all of the
1723
+ // client rectangles ourselves. This is cheaper than re-measuring everything and
1724
+ // we can avoid inconsistent behavior where we might be measuring the element before
1725
+ // its position has changed.
1726
+ this._itemPositions.forEach(({ clientRect }) => {
1727
+ adjustClientRect(clientRect, topDifference, leftDifference);
1728
+ });
1729
+ // We need two loops for this, because we want all of the cached
1730
+ // positions to be up-to-date before we re-sort the item.
1731
+ this._itemPositions.forEach(({ drag }) => {
1732
+ if (this._dragDropRegistry.isDragging(drag)) {
1733
+ // We need to re-sort the item manually, because the pointer move
1734
+ // events won't be dispatched while the user is scrolling.
1735
+ drag._sortFromLastPointerPosition();
1736
+ }
1737
+ });
1738
+ }
1739
+ /** Refreshes the position cache of the items and sibling containers. */
1740
+ _cacheItemPositions() {
1741
+ const isHorizontal = this.orientation === 'horizontal';
1742
+ this._itemPositions = this._activeDraggables
1743
+ .map(drag => {
1744
+ const elementToMeasure = drag.getVisibleElement();
1745
+ return {
1746
+ drag,
1747
+ offset: 0,
1748
+ initialTransform: elementToMeasure.style.transform || '',
1749
+ clientRect: getMutableClientRect(elementToMeasure),
1750
+ };
1751
+ })
1752
+ .sort((a, b) => {
1753
+ return isHorizontal
1754
+ ? a.clientRect.left - b.clientRect.left
1755
+ : a.clientRect.top - b.clientRect.top;
1756
+ });
1757
+ }
1758
+ /**
1759
+ * Gets the offset in pixels by which the item that is being dragged should be moved.
1760
+ * @param currentPosition Current position of the item.
1761
+ * @param newPosition Position of the item where the current item should be moved.
1762
+ * @param delta Direction in which the user is moving.
1763
+ */
1764
+ _getItemOffsetPx(currentPosition, newPosition, delta) {
1765
+ const isHorizontal = this.orientation === 'horizontal';
1766
+ let itemOffset = isHorizontal
1767
+ ? newPosition.left - currentPosition.left
1768
+ : newPosition.top - currentPosition.top;
1769
+ // Account for differences in the item width/height.
1770
+ if (delta === -1) {
1771
+ itemOffset += isHorizontal
1772
+ ? newPosition.width - currentPosition.width
1773
+ : newPosition.height - currentPosition.height;
1774
+ }
1775
+ return itemOffset;
1776
+ }
1777
+ /**
1778
+ * Gets the offset in pixels by which the items that aren't being dragged should be moved.
1779
+ * @param currentIndex Index of the item currently being dragged.
1780
+ * @param siblings All of the items in the list.
1781
+ * @param delta Direction in which the user is moving.
1782
+ */
1783
+ _getSiblingOffsetPx(currentIndex, siblings, delta) {
1784
+ const isHorizontal = this.orientation === 'horizontal';
1785
+ const currentPosition = siblings[currentIndex].clientRect;
1786
+ const immediateSibling = siblings[currentIndex + delta * -1];
1787
+ let siblingOffset = currentPosition[isHorizontal ? 'width' : 'height'] * delta;
1788
+ if (immediateSibling) {
1789
+ const start = isHorizontal ? 'left' : 'top';
1790
+ const end = isHorizontal ? 'right' : 'bottom';
1791
+ // Get the spacing between the start of the current item and the end of the one immediately
1792
+ // after it in the direction in which the user is dragging, or vice versa. We add it to the
1793
+ // offset in order to push the element to where it will be when it's inline and is influenced
1794
+ // by the `margin` of its siblings.
1795
+ if (delta === -1) {
1796
+ siblingOffset -= immediateSibling.clientRect[start] - currentPosition[end];
1797
+ }
1798
+ else {
1799
+ siblingOffset += currentPosition[start] - immediateSibling.clientRect[end];
1800
+ }
1801
+ }
1802
+ return siblingOffset;
1803
+ }
1804
+ /**
1805
+ * Checks if pointer is entering in the first position
1806
+ * @param pointerX Position of the user's pointer along the X axis.
1807
+ * @param pointerY Position of the user's pointer along the Y axis.
1808
+ */
1809
+ _shouldEnterAsFirstChild(pointerX, pointerY) {
1810
+ if (!this._activeDraggables.length) {
1811
+ return false;
1812
+ }
1813
+ const itemPositions = this._itemPositions;
1814
+ const isHorizontal = this.orientation === 'horizontal';
1815
+ // `itemPositions` are sorted by position while `activeDraggables` are sorted by child index
1816
+ // check if container is using some sort of "reverse" ordering (eg: flex-direction: row-reverse)
1817
+ const reversed = itemPositions[0].drag !== this._activeDraggables[0];
1818
+ if (reversed) {
1819
+ const lastItemRect = itemPositions[itemPositions.length - 1].clientRect;
1820
+ return isHorizontal ? pointerX >= lastItemRect.right : pointerY >= lastItemRect.bottom;
1821
+ }
1822
+ else {
1823
+ const firstItemRect = itemPositions[0].clientRect;
1824
+ return isHorizontal ? pointerX <= firstItemRect.left : pointerY <= firstItemRect.top;
1825
+ }
1826
+ }
1827
+ /**
1828
+ * Gets the index of an item in the drop container, based on the position of the user's pointer.
1829
+ * @param item Item that is being sorted.
1830
+ * @param pointerX Position of the user's pointer along the X axis.
1831
+ * @param pointerY Position of the user's pointer along the Y axis.
1832
+ * @param delta Direction in which the user is moving their pointer.
1833
+ */
1834
+ _getItemIndexFromPointerPosition(item, pointerX, pointerY, delta) {
1835
+ const isHorizontal = this.orientation === 'horizontal';
1836
+ const index = this._itemPositions.findIndex(({ drag, clientRect }) => {
1837
+ // Skip the item itself.
1838
+ if (drag === item) {
1839
+ return false;
1840
+ }
1841
+ if (delta) {
1842
+ const direction = isHorizontal ? delta.x : delta.y;
1843
+ // If the user is still hovering over the same item as last time, their cursor hasn't left
1844
+ // the item after we made the swap, and they didn't change the direction in which they're
1845
+ // dragging, we don't consider it a direction swap.
1846
+ if (drag === this._previousSwap.drag &&
1847
+ this._previousSwap.overlaps &&
1848
+ direction === this._previousSwap.delta) {
1849
+ return false;
1850
+ }
1851
+ }
1852
+ return isHorizontal
1853
+ ? // Round these down since most browsers report client rects with
1854
+ // sub-pixel precision, whereas the pointer coordinates are rounded to pixels.
1855
+ pointerX >= Math.floor(clientRect.left) && pointerX < Math.floor(clientRect.right)
1856
+ : pointerY >= Math.floor(clientRect.top) && pointerY < Math.floor(clientRect.bottom);
1857
+ });
1858
+ return index === -1 || !this._sortPredicate(index, item) ? -1 : index;
1859
+ }
1860
+ }
1861
+
1862
+ /**
1863
+ * @license
1864
+ * Copyright Google LLC All Rights Reserved.
1865
+ *
1866
+ * Use of this source code is governed by an MIT-style license that can be
1867
+ * found in the LICENSE file at https://angular.io/license
1868
+ */
1869
+ /**
1870
+ * Proximity, as a ratio to width/height, at which a
1871
+ * dragged item will affect the drop container.
1872
+ */
1873
+ const DROP_PROXIMITY_THRESHOLD = 0.05;
1874
+ /**
1875
+ * Proximity, as a ratio to width/height at which to start auto-scrolling the drop list or the
1876
+ * viewport. The value comes from trying it out manually until it feels right.
1877
+ */
1878
+ const SCROLL_PROXIMITY_THRESHOLD = 0.05;
1879
+ /**
1880
+ * Reference to a drop list. Used to manipulate or dispose of the container.
1881
+ */
1882
+ class DropListRef {
1883
+ constructor(element, _dragDropRegistry, _document, _ngZone, _viewportRuler) {
1884
+ this._dragDropRegistry = _dragDropRegistry;
1885
+ this._ngZone = _ngZone;
1886
+ this._viewportRuler = _viewportRuler;
1887
+ /** Whether starting a dragging sequence from this container is disabled. */
1888
+ this.disabled = false;
1889
+ /** Whether sorting items within the list is disabled. */
1890
+ this.sortingDisabled = false;
1891
+ /**
1892
+ * Whether auto-scrolling the view when the user
1893
+ * moves their pointer close to the edges is disabled.
1894
+ */
1895
+ this.autoScrollDisabled = false;
1896
+ /** Number of pixels to scroll for each frame when auto-scrolling an element. */
1897
+ this.autoScrollStep = 2;
1898
+ /**
1899
+ * Function that is used to determine whether an item
1900
+ * is allowed to be moved into a drop container.
1901
+ */
1902
+ this.enterPredicate = () => true;
1903
+ /** Function that is used to determine whether an item can be sorted into a particular index. */
1904
+ this.sortPredicate = () => true;
1905
+ /** Emits right before dragging has started. */
1906
+ this.beforeStarted = new Subject();
1907
+ /**
1908
+ * Emits when the user has moved a new drag item into this container.
1909
+ */
1910
+ this.entered = new Subject();
1911
+ /**
1912
+ * Emits when the user removes an item from the container
1913
+ * by dragging it into another container.
1914
+ */
1915
+ this.exited = new Subject();
1916
+ /** Emits when the user drops an item inside the container. */
1917
+ this.dropped = new Subject();
1918
+ /** Emits as the user is swapping items while actively dragging. */
1919
+ this.sorted = new Subject();
1920
+ /** Whether an item in the list is being dragged. */
1921
+ this._isDragging = false;
1922
+ /** Draggable items in the container. */
1923
+ this._draggables = [];
1924
+ /** Drop lists that are connected to the current one. */
1925
+ this._siblings = [];
1926
+ /** Connected siblings that currently have a dragged item. */
1927
+ this._activeSiblings = new Set();
1928
+ /** Subscription to the window being scrolled. */
1929
+ this._viewportScrollSubscription = Subscription.EMPTY;
1930
+ /** Vertical direction in which the list is currently scrolling. */
1931
+ this._verticalScrollDirection = 0 /* AutoScrollVerticalDirection.NONE */;
1932
+ /** Horizontal direction in which the list is currently scrolling. */
1933
+ this._horizontalScrollDirection = 0 /* AutoScrollHorizontalDirection.NONE */;
1934
+ /** Used to signal to the current auto-scroll sequence when to stop. */
1935
+ this._stopScrollTimers = new Subject();
1936
+ /** Shadow root of the current element. Necessary for `elementFromPoint` to resolve correctly. */
1937
+ this._cachedShadowRoot = null;
1938
+ /** Starts the interval that'll auto-scroll the element. */
1939
+ this._startScrollInterval = () => {
1940
+ this._stopScrolling();
1941
+ interval(0, animationFrameScheduler)
1942
+ .pipe(takeUntil(this._stopScrollTimers))
1943
+ .subscribe(() => {
1944
+ const node = this._scrollNode;
1945
+ const scrollStep = this.autoScrollStep;
1946
+ if (this._verticalScrollDirection === 1 /* AutoScrollVerticalDirection.UP */) {
1947
+ node.scrollBy(0, -scrollStep);
1948
+ }
1949
+ else if (this._verticalScrollDirection === 2 /* AutoScrollVerticalDirection.DOWN */) {
1950
+ node.scrollBy(0, scrollStep);
1951
+ }
1952
+ if (this._horizontalScrollDirection === 1 /* AutoScrollHorizontalDirection.LEFT */) {
1953
+ node.scrollBy(-scrollStep, 0);
1954
+ }
1955
+ else if (this._horizontalScrollDirection === 2 /* AutoScrollHorizontalDirection.RIGHT */) {
1956
+ node.scrollBy(scrollStep, 0);
1957
+ }
1958
+ });
1959
+ };
1960
+ this.element = coerceElement(element);
1961
+ this._document = _document;
1962
+ this.withScrollableParents([this.element]);
1963
+ _dragDropRegistry.registerDropContainer(this);
1964
+ this._parentPositions = new ParentPositionTracker(_document);
1965
+ this._sortStrategy = new SingleAxisSortStrategy(this.element, _dragDropRegistry);
1966
+ this._sortStrategy.withSortPredicate((index, item) => this.sortPredicate(index, item, this));
1967
+ }
1968
+ /** Removes the drop list functionality from the DOM element. */
1969
+ dispose() {
1970
+ this._stopScrolling();
1971
+ this._stopScrollTimers.complete();
1972
+ this._viewportScrollSubscription.unsubscribe();
1973
+ this.beforeStarted.complete();
1974
+ this.entered.complete();
1975
+ this.exited.complete();
1976
+ this.dropped.complete();
1977
+ this.sorted.complete();
1978
+ this._activeSiblings.clear();
1979
+ this._scrollNode = null;
1980
+ this._parentPositions.clear();
1981
+ this._dragDropRegistry.removeDropContainer(this);
1982
+ }
1983
+ /** Whether an item from this list is currently being dragged. */
1984
+ isDragging() {
1985
+ return this._isDragging;
1986
+ }
1987
+ /** Starts dragging an item. */
1988
+ start() {
1989
+ this._draggingStarted();
1990
+ this._notifyReceivingSiblings();
1991
+ }
1992
+ /**
1993
+ * Attempts to move an item into the container.
1994
+ * @param item Item that was moved into the container.
1995
+ * @param pointerX Position of the item along the X axis.
1996
+ * @param pointerY Position of the item along the Y axis.
1997
+ * @param index Index at which the item entered. If omitted, the container will try to figure it
1998
+ * out automatically.
1999
+ */
2000
+ enter(item, pointerX, pointerY, index) {
2001
+ this._draggingStarted();
2002
+ // If sorting is disabled, we want the item to return to its starting
2003
+ // position if the user is returning it to its initial container.
2004
+ if (index == null && this.sortingDisabled) {
2005
+ index = this._draggables.indexOf(item);
2006
+ }
2007
+ this._sortStrategy.enter(item, pointerX, pointerY, index);
2008
+ // Note that this usually happens inside `_draggingStarted` as well, but the dimensions
2009
+ // can change when the sort strategy moves the item around inside `enter`.
2010
+ this._cacheParentPositions();
2011
+ // Notify siblings at the end so that the item has been inserted into the `activeDraggables`.
2012
+ this._notifyReceivingSiblings();
2013
+ this.entered.next({ item, container: this, currentIndex: this.getItemIndex(item) });
2014
+ }
2015
+ /**
2016
+ * Removes an item from the container after it was dragged into another container by the user.
2017
+ * @param item Item that was dragged out.
2018
+ */
2019
+ exit(item) {
2020
+ this._reset();
2021
+ this.exited.next({ item, container: this });
2022
+ }
2023
+ /**
2024
+ * Drops an item into this container.
2025
+ * @param item Item being dropped into the container.
2026
+ * @param currentIndex Index at which the item should be inserted.
2027
+ * @param previousIndex Index of the item when dragging started.
2028
+ * @param previousContainer Container from which the item got dragged in.
2029
+ * @param isPointerOverContainer Whether the user's pointer was over the
2030
+ * container when the item was dropped.
2031
+ * @param distance Distance the user has dragged since the start of the dragging sequence.
2032
+ * @param event Event that triggered the dropping sequence.
2033
+ *
2034
+ * @breaking-change 15.0.0 `previousIndex` and `event` parameters to become required.
2035
+ */
2036
+ drop(item, currentIndex, previousIndex, previousContainer, isPointerOverContainer, distance, dropPoint, event = {}) {
2037
+ this._reset();
2038
+ this.dropped.next({
2039
+ item,
2040
+ currentIndex,
2041
+ previousIndex,
2042
+ container: this,
2043
+ previousContainer,
2044
+ isPointerOverContainer,
2045
+ distance,
2046
+ dropPoint,
2047
+ event,
2048
+ });
2049
+ }
2050
+ /**
2051
+ * Sets the draggable items that are a part of this list.
2052
+ * @param items Items that are a part of this list.
2053
+ */
2054
+ withItems(items) {
2055
+ const previousItems = this._draggables;
2056
+ this._draggables = items;
2057
+ items.forEach(item => item._withDropContainer(this));
2058
+ if (this.isDragging()) {
2059
+ const draggedItems = previousItems.filter(item => item.isDragging());
2060
+ // If all of the items being dragged were removed
2061
+ // from the list, abort the current drag sequence.
2062
+ if (draggedItems.every(item => items.indexOf(item) === -1)) {
2063
+ this._reset();
2064
+ }
2065
+ else {
2066
+ this._sortStrategy.withItems(this._draggables);
2067
+ }
2068
+ }
2069
+ return this;
2070
+ }
2071
+ /** Sets the layout direction of the drop list. */
2072
+ withDirection(direction) {
2073
+ this._sortStrategy.direction = direction;
2074
+ return this;
2075
+ }
2076
+ /**
2077
+ * Sets the containers that are connected to this one. When two or more containers are
2078
+ * connected, the user will be allowed to transfer items between them.
2079
+ * @param connectedTo Other containers that the current containers should be connected to.
2080
+ */
2081
+ connectedTo(connectedTo) {
2082
+ this._siblings = connectedTo.slice();
2083
+ return this;
2084
+ }
2085
+ /**
2086
+ * Sets the orientation of the container.
2087
+ * @param orientation New orientation for the container.
2088
+ */
2089
+ withOrientation(orientation) {
2090
+ // TODO(crisbeto): eventually we should be constructing the new sort strategy here based on
2091
+ // the new orientation. For now we can assume that it'll always be `SingleAxisSortStrategy`.
2092
+ this._sortStrategy.orientation = orientation;
2093
+ return this;
2094
+ }
2095
+ /**
2096
+ * Sets which parent elements are can be scrolled while the user is dragging.
2097
+ * @param elements Elements that can be scrolled.
2098
+ */
2099
+ withScrollableParents(elements) {
2100
+ const element = coerceElement(this.element);
2101
+ // We always allow the current element to be scrollable
2102
+ // so we need to ensure that it's in the array.
2103
+ this._scrollableElements =
2104
+ elements.indexOf(element) === -1 ? [element, ...elements] : elements.slice();
2105
+ return this;
2106
+ }
2107
+ /** Gets the scrollable parents that are registered with this drop container. */
2108
+ getScrollableParents() {
2109
+ return this._scrollableElements;
2110
+ }
2111
+ /**
2112
+ * Figures out the index of an item in the container.
2113
+ * @param item Item whose index should be determined.
2114
+ */
2115
+ getItemIndex(item) {
2116
+ return this._isDragging
2117
+ ? this._sortStrategy.getItemIndex(item)
2118
+ : this._draggables.indexOf(item);
2119
+ }
2120
+ /**
2121
+ * Whether the list is able to receive the item that
2122
+ * is currently being dragged inside a connected drop list.
2123
+ */
2124
+ isReceiving() {
2125
+ return this._activeSiblings.size > 0;
2126
+ }
2127
+ /**
2128
+ * Sorts an item inside the container based on its position.
2129
+ * @param item Item to be sorted.
2130
+ * @param pointerX Position of the item along the X axis.
2131
+ * @param pointerY Position of the item along the Y axis.
2132
+ * @param pointerDelta Direction in which the pointer is moving along each axis.
2133
+ */
2134
+ _sortItem(item, pointerX, pointerY, pointerDelta) {
2135
+ // Don't sort the item if sorting is disabled or it's out of range.
2136
+ if (this.sortingDisabled ||
2137
+ !this._clientRect ||
2138
+ !isPointerNearClientRect(this._clientRect, DROP_PROXIMITY_THRESHOLD, pointerX, pointerY)) {
2139
+ return;
2140
+ }
2141
+ const result = this._sortStrategy.sort(item, pointerX, pointerY, pointerDelta);
2142
+ if (result) {
2143
+ this.sorted.next({
2144
+ previousIndex: result.previousIndex,
2145
+ currentIndex: result.currentIndex,
2146
+ container: this,
2147
+ item,
2148
+ });
2149
+ }
2150
+ }
2151
+ /**
2152
+ * Checks whether the user's pointer is close to the edges of either the
2153
+ * viewport or the drop list and starts the auto-scroll sequence.
2154
+ * @param pointerX User's pointer position along the x axis.
2155
+ * @param pointerY User's pointer position along the y axis.
2156
+ */
2157
+ _startScrollingIfNecessary(pointerX, pointerY) {
2158
+ if (this.autoScrollDisabled) {
2159
+ return;
2160
+ }
2161
+ let scrollNode;
2162
+ let verticalScrollDirection = 0 /* AutoScrollVerticalDirection.NONE */;
2163
+ let horizontalScrollDirection = 0 /* AutoScrollHorizontalDirection.NONE */;
2164
+ // Check whether we should start scrolling any of the parent containers.
2165
+ this._parentPositions.positions.forEach((position, element) => {
2166
+ // We have special handling for the `document` below. Also this would be
2167
+ // nicer with a for...of loop, but it requires changing a compiler flag.
2168
+ if (element === this._document || !position.clientRect || scrollNode) {
2169
+ return;
2170
+ }
2171
+ if (isPointerNearClientRect(position.clientRect, DROP_PROXIMITY_THRESHOLD, pointerX, pointerY)) {
2172
+ [verticalScrollDirection, horizontalScrollDirection] = getElementScrollDirections(element, position.clientRect, pointerX, pointerY);
2173
+ if (verticalScrollDirection || horizontalScrollDirection) {
2174
+ scrollNode = element;
2175
+ }
2176
+ }
2177
+ });
2178
+ // Otherwise check if we can start scrolling the viewport.
2179
+ if (!verticalScrollDirection && !horizontalScrollDirection) {
2180
+ const { width, height } = this._viewportRuler.getViewportSize();
2181
+ const clientRect = {
2182
+ width,
2183
+ height,
2184
+ top: 0,
2185
+ right: width,
2186
+ bottom: height,
2187
+ left: 0,
2188
+ };
2189
+ verticalScrollDirection = getVerticalScrollDirection(clientRect, pointerY);
2190
+ horizontalScrollDirection = getHorizontalScrollDirection(clientRect, pointerX);
2191
+ scrollNode = window;
2192
+ }
2193
+ if (scrollNode &&
2194
+ (verticalScrollDirection !== this._verticalScrollDirection ||
2195
+ horizontalScrollDirection !== this._horizontalScrollDirection ||
2196
+ scrollNode !== this._scrollNode)) {
2197
+ this._verticalScrollDirection = verticalScrollDirection;
2198
+ this._horizontalScrollDirection = horizontalScrollDirection;
2199
+ this._scrollNode = scrollNode;
2200
+ if ((verticalScrollDirection || horizontalScrollDirection) && scrollNode) {
2201
+ this._ngZone.runOutsideAngular(this._startScrollInterval);
2202
+ }
2203
+ else {
2204
+ this._stopScrolling();
2205
+ }
2206
+ }
2207
+ }
2208
+ /** Stops any currently-running auto-scroll sequences. */
2209
+ _stopScrolling() {
2210
+ this._stopScrollTimers.next();
2211
+ }
2212
+ /** Starts the dragging sequence within the list. */
2213
+ _draggingStarted() {
2214
+ const styles = coerceElement(this.element).style;
2215
+ this.beforeStarted.next();
2216
+ this._isDragging = true;
2217
+ // We need to disable scroll snapping while the user is dragging, because it breaks automatic
2218
+ // scrolling. The browser seems to round the value based on the snapping points which means
2219
+ // that we can't increment/decrement the scroll position.
2220
+ this._initialScrollSnap = styles.msScrollSnapType || styles.scrollSnapType || '';
2221
+ styles.scrollSnapType = styles.msScrollSnapType = 'none';
2222
+ this._sortStrategy.start(this._draggables);
2223
+ this._cacheParentPositions();
2224
+ this._viewportScrollSubscription.unsubscribe();
2225
+ this._listenToScrollEvents();
2226
+ }
2227
+ /** Caches the positions of the configured scrollable parents. */
2228
+ _cacheParentPositions() {
2229
+ const element = coerceElement(this.element);
2230
+ this._parentPositions.cache(this._scrollableElements);
2231
+ // The list element is always in the `scrollableElements`
2232
+ // so we can take advantage of the cached `ClientRect`.
2233
+ this._clientRect = this._parentPositions.positions.get(element).clientRect;
2234
+ }
2235
+ /** Resets the container to its initial state. */
2236
+ _reset() {
2237
+ this._isDragging = false;
2238
+ const styles = coerceElement(this.element).style;
2239
+ styles.scrollSnapType = styles.msScrollSnapType = this._initialScrollSnap;
2240
+ this._siblings.forEach(sibling => sibling._stopReceiving(this));
2241
+ this._sortStrategy.reset();
2242
+ this._stopScrolling();
2243
+ this._viewportScrollSubscription.unsubscribe();
2244
+ this._parentPositions.clear();
2245
+ }
2246
+ /**
2247
+ * Checks whether the user's pointer is positioned over the container.
2248
+ * @param x Pointer position along the X axis.
2249
+ * @param y Pointer position along the Y axis.
2250
+ */
2251
+ _isOverContainer(x, y) {
2252
+ return this._clientRect != null && isInsideClientRect(this._clientRect, x, y);
2253
+ }
2254
+ /**
2255
+ * Figures out whether an item should be moved into a sibling
2256
+ * drop container, based on its current position.
2257
+ * @param item Drag item that is being moved.
2258
+ * @param x Position of the item along the X axis.
2259
+ * @param y Position of the item along the Y axis.
2260
+ */
2261
+ _getSiblingContainerFromPosition(item, x, y) {
2262
+ return this._siblings.find(sibling => sibling._canReceive(item, x, y));
2263
+ }
2264
+ /**
2265
+ * Checks whether the drop list can receive the passed-in item.
2266
+ * @param item Item that is being dragged into the list.
2267
+ * @param x Position of the item along the X axis.
2268
+ * @param y Position of the item along the Y axis.
2269
+ */
2270
+ _canReceive(item, x, y) {
2271
+ if (!this._clientRect ||
2272
+ !isInsideClientRect(this._clientRect, x, y) ||
2273
+ !this.enterPredicate(item, this)) {
2274
+ return false;
2275
+ }
2276
+ const elementFromPoint = this._getShadowRoot().elementFromPoint(x, y);
2277
+ // If there's no element at the pointer position, then
2278
+ // the client rect is probably scrolled out of the view.
2279
+ if (!elementFromPoint) {
2280
+ return false;
2281
+ }
2282
+ const nativeElement = coerceElement(this.element);
2283
+ // The `ClientRect`, that we're using to find the container over which the user is
2284
+ // hovering, doesn't give us any information on whether the element has been scrolled
2285
+ // out of the view or whether it's overlapping with other containers. This means that
2286
+ // we could end up transferring the item into a container that's invisible or is positioned
2287
+ // below another one. We use the result from `elementFromPoint` to get the top-most element
2288
+ // at the pointer position and to find whether it's one of the intersecting drop containers.
2289
+ return elementFromPoint === nativeElement || nativeElement.contains(elementFromPoint);
2290
+ }
2291
+ /**
2292
+ * Called by one of the connected drop lists when a dragging sequence has started.
2293
+ * @param sibling Sibling in which dragging has started.
2294
+ */
2295
+ _startReceiving(sibling, items) {
2296
+ const activeSiblings = this._activeSiblings;
2297
+ if (!activeSiblings.has(sibling) &&
2298
+ items.every(item => {
2299
+ // Note that we have to add an exception to the `enterPredicate` for items that started off
2300
+ // in this drop list. The drag ref has logic that allows an item to return to its initial
2301
+ // container, if it has left the initial container and none of the connected containers
2302
+ // allow it to enter. See `DragRef._updateActiveDropContainer` for more context.
2303
+ return this.enterPredicate(item, this) || this._draggables.indexOf(item) > -1;
2304
+ })) {
2305
+ activeSiblings.add(sibling);
2306
+ this._cacheParentPositions();
2307
+ this._listenToScrollEvents();
2308
+ }
2309
+ }
2310
+ /**
2311
+ * Called by a connected drop list when dragging has stopped.
2312
+ * @param sibling Sibling whose dragging has stopped.
2313
+ */
2314
+ _stopReceiving(sibling) {
2315
+ this._activeSiblings.delete(sibling);
2316
+ this._viewportScrollSubscription.unsubscribe();
2317
+ }
2318
+ /**
2319
+ * Starts listening to scroll events on the viewport.
2320
+ * Used for updating the internal state of the list.
2321
+ */
2322
+ _listenToScrollEvents() {
2323
+ this._viewportScrollSubscription = this._dragDropRegistry
2324
+ .scrolled(this._getShadowRoot())
2325
+ .subscribe(event => {
2326
+ if (this.isDragging()) {
2327
+ const scrollDifference = this._parentPositions.handleScroll(event);
2328
+ if (scrollDifference) {
2329
+ this._sortStrategy.updateOnScroll(scrollDifference.top, scrollDifference.left);
2330
+ }
2331
+ }
2332
+ else if (this.isReceiving()) {
2333
+ this._cacheParentPositions();
2334
+ }
2335
+ });
2336
+ }
2337
+ /**
2338
+ * Lazily resolves and returns the shadow root of the element. We do this in a function, rather
2339
+ * than saving it in property directly on init, because we want to resolve it as late as possible
2340
+ * in order to ensure that the element has been moved into the shadow DOM. Doing it inside the
2341
+ * constructor might be too early if the element is inside of something like `ngFor` or `ngIf`.
2342
+ */
2343
+ _getShadowRoot() {
2344
+ if (!this._cachedShadowRoot) {
2345
+ const shadowRoot = _getShadowRoot(coerceElement(this.element));
2346
+ this._cachedShadowRoot = (shadowRoot || this._document);
2347
+ }
2348
+ return this._cachedShadowRoot;
2349
+ }
2350
+ /** Notifies any siblings that may potentially receive the item. */
2351
+ _notifyReceivingSiblings() {
2352
+ const draggedItems = this._sortStrategy
2353
+ .getActiveItemsSnapshot()
2354
+ .filter(item => item.isDragging());
2355
+ this._siblings.forEach(sibling => sibling._startReceiving(this, draggedItems));
2356
+ }
2357
+ }
2358
+ /**
2359
+ * Gets whether the vertical auto-scroll direction of a node.
2360
+ * @param clientRect Dimensions of the node.
2361
+ * @param pointerY Position of the user's pointer along the y axis.
2362
+ */
2363
+ function getVerticalScrollDirection(clientRect, pointerY) {
2364
+ const { top, bottom, height } = clientRect;
2365
+ const yThreshold = height * SCROLL_PROXIMITY_THRESHOLD;
2366
+ if (pointerY >= top - yThreshold && pointerY <= top + yThreshold) {
2367
+ return 1 /* AutoScrollVerticalDirection.UP */;
2368
+ }
2369
+ else if (pointerY >= bottom - yThreshold && pointerY <= bottom + yThreshold) {
2370
+ return 2 /* AutoScrollVerticalDirection.DOWN */;
2371
+ }
2372
+ return 0 /* AutoScrollVerticalDirection.NONE */;
2373
+ }
2374
+ /**
2375
+ * Gets whether the horizontal auto-scroll direction of a node.
2376
+ * @param clientRect Dimensions of the node.
2377
+ * @param pointerX Position of the user's pointer along the x axis.
2378
+ */
2379
+ function getHorizontalScrollDirection(clientRect, pointerX) {
2380
+ const { left, right, width } = clientRect;
2381
+ const xThreshold = width * SCROLL_PROXIMITY_THRESHOLD;
2382
+ if (pointerX >= left - xThreshold && pointerX <= left + xThreshold) {
2383
+ return 1 /* AutoScrollHorizontalDirection.LEFT */;
2384
+ }
2385
+ else if (pointerX >= right - xThreshold && pointerX <= right + xThreshold) {
2386
+ return 2 /* AutoScrollHorizontalDirection.RIGHT */;
2387
+ }
2388
+ return 0 /* AutoScrollHorizontalDirection.NONE */;
2389
+ }
2390
+ /**
2391
+ * Gets the directions in which an element node should be scrolled,
2392
+ * assuming that the user's pointer is already within it scrollable region.
2393
+ * @param element Element for which we should calculate the scroll direction.
2394
+ * @param clientRect Bounding client rectangle of the element.
2395
+ * @param pointerX Position of the user's pointer along the x axis.
2396
+ * @param pointerY Position of the user's pointer along the y axis.
2397
+ */
2398
+ function getElementScrollDirections(element, clientRect, pointerX, pointerY) {
2399
+ const computedVertical = getVerticalScrollDirection(clientRect, pointerY);
2400
+ const computedHorizontal = getHorizontalScrollDirection(clientRect, pointerX);
2401
+ let verticalScrollDirection = 0 /* AutoScrollVerticalDirection.NONE */;
2402
+ let horizontalScrollDirection = 0 /* AutoScrollHorizontalDirection.NONE */;
2403
+ // Note that we here we do some extra checks for whether the element is actually scrollable in
2404
+ // a certain direction and we only assign the scroll direction if it is. We do this so that we
2405
+ // can allow other elements to be scrolled, if the current element can't be scrolled anymore.
2406
+ // This allows us to handle cases where the scroll regions of two scrollable elements overlap.
2407
+ if (computedVertical) {
2408
+ const scrollTop = element.scrollTop;
2409
+ if (computedVertical === 1 /* AutoScrollVerticalDirection.UP */) {
2410
+ if (scrollTop > 0) {
2411
+ verticalScrollDirection = 1 /* AutoScrollVerticalDirection.UP */;
2412
+ }
2413
+ }
2414
+ else if (element.scrollHeight - scrollTop > element.clientHeight) {
2415
+ verticalScrollDirection = 2 /* AutoScrollVerticalDirection.DOWN */;
2416
+ }
2417
+ }
2418
+ if (computedHorizontal) {
2419
+ const scrollLeft = element.scrollLeft;
2420
+ if (computedHorizontal === 1 /* AutoScrollHorizontalDirection.LEFT */) {
2421
+ if (scrollLeft > 0) {
2422
+ horizontalScrollDirection = 1 /* AutoScrollHorizontalDirection.LEFT */;
2423
+ }
2424
+ }
2425
+ else if (element.scrollWidth - scrollLeft > element.clientWidth) {
2426
+ horizontalScrollDirection = 2 /* AutoScrollHorizontalDirection.RIGHT */;
2427
+ }
2428
+ }
2429
+ return [verticalScrollDirection, horizontalScrollDirection];
2430
+ }
2431
+
2432
+ /**
2433
+ * @license
2434
+ * Copyright Google LLC All Rights Reserved.
2435
+ *
2436
+ * Use of this source code is governed by an MIT-style license that can be
2437
+ * found in the LICENSE file at https://angular.io/license
2438
+ */
2439
+ /** Event options that can be used to bind an active, capturing event. */
2440
+ const activeCapturingEventOptions = normalizePassiveListenerOptions({
2441
+ passive: false,
2442
+ capture: true,
2443
+ });
2444
+ /**
2445
+ * Service that keeps track of all the drag item and drop container
2446
+ * instances, and manages global event listeners on the `document`.
2447
+ * @docs-private
2448
+ */
2449
+ // Note: this class is generic, rather than referencing CdkDrag and CdkDropList directly, in order
2450
+ // to avoid circular imports. If we were to reference them here, importing the registry into the
2451
+ // classes that are registering themselves will introduce a circular import.
2452
+ class DragDropRegistry {
2453
+ constructor(_ngZone, _document) {
2454
+ this._ngZone = _ngZone;
2455
+ /** Registered drop container instances. */
2456
+ this._dropInstances = new Set();
2457
+ /** Registered drag item instances. */
2458
+ this._dragInstances = new Set();
2459
+ /** Drag item instances that are currently being dragged. */
2460
+ this._activeDragInstances = [];
2461
+ /** Keeps track of the event listeners that we've bound to the `document`. */
2462
+ this._globalListeners = new Map();
2463
+ /**
2464
+ * Predicate function to check if an item is being dragged. Moved out into a property,
2465
+ * because it'll be called a lot and we don't want to create a new function every time.
2466
+ */
2467
+ this._draggingPredicate = (item) => item.isDragging();
2468
+ /**
2469
+ * Emits the `touchmove` or `mousemove` events that are dispatched
2470
+ * while the user is dragging a drag item instance.
2471
+ */
2472
+ this.pointerMove = new Subject();
2473
+ /**
2474
+ * Emits the `touchend` or `mouseup` events that are dispatched
2475
+ * while the user is dragging a drag item instance.
2476
+ */
2477
+ this.pointerUp = new Subject();
2478
+ /**
2479
+ * Emits when the viewport has been scrolled while the user is dragging an item.
2480
+ * @deprecated To be turned into a private member. Use the `scrolled` method instead.
2481
+ * @breaking-change 13.0.0
2482
+ */
2483
+ this.scroll = new Subject();
2484
+ /**
2485
+ * Event listener that will prevent the default browser action while the user is dragging.
2486
+ * @param event Event whose default action should be prevented.
2487
+ */
2488
+ this._preventDefaultWhileDragging = (event) => {
2489
+ if (this._activeDragInstances.length > 0) {
2490
+ event.preventDefault();
2491
+ }
2492
+ };
2493
+ /** Event listener for `touchmove` that is bound even if no dragging is happening. */
2494
+ this._persistentTouchmoveListener = (event) => {
2495
+ if (this._activeDragInstances.length > 0) {
2496
+ // Note that we only want to prevent the default action after dragging has actually started.
2497
+ // Usually this is the same time at which the item is added to the `_activeDragInstances`,
2498
+ // but it could be pushed back if the user has set up a drag delay or threshold.
2499
+ if (this._activeDragInstances.some(this._draggingPredicate)) {
2500
+ event.preventDefault();
2501
+ }
2502
+ this.pointerMove.next(event);
2503
+ }
2504
+ };
2505
+ this._document = _document;
2506
+ }
2507
+ /** Adds a drop container to the registry. */
2508
+ registerDropContainer(drop) {
2509
+ if (!this._dropInstances.has(drop)) {
2510
+ this._dropInstances.add(drop);
2511
+ }
2512
+ }
2513
+ /** Adds a drag item instance to the registry. */
2514
+ registerDragItem(drag) {
2515
+ this._dragInstances.add(drag);
2516
+ // The `touchmove` event gets bound once, ahead of time, because WebKit
2517
+ // won't preventDefault on a dynamically-added `touchmove` listener.
2518
+ // See https://bugs.webkit.org/show_bug.cgi?id=184250.
2519
+ if (this._dragInstances.size === 1) {
2520
+ this._ngZone.runOutsideAngular(() => {
2521
+ // The event handler has to be explicitly active,
2522
+ // because newer browsers make it passive by default.
2523
+ this._document.addEventListener('touchmove', this._persistentTouchmoveListener, activeCapturingEventOptions);
2524
+ });
2525
+ }
2526
+ }
2527
+ /** Removes a drop container from the registry. */
2528
+ removeDropContainer(drop) {
2529
+ this._dropInstances.delete(drop);
2530
+ }
2531
+ /** Removes a drag item instance from the registry. */
2532
+ removeDragItem(drag) {
2533
+ this._dragInstances.delete(drag);
2534
+ this.stopDragging(drag);
2535
+ if (this._dragInstances.size === 0) {
2536
+ this._document.removeEventListener('touchmove', this._persistentTouchmoveListener, activeCapturingEventOptions);
2537
+ }
2538
+ }
2539
+ /**
2540
+ * Starts the dragging sequence for a drag instance.
2541
+ * @param drag Drag instance which is being dragged.
2542
+ * @param event Event that initiated the dragging.
2543
+ */
2544
+ startDragging(drag, event) {
2545
+ // Do not process the same drag twice to avoid memory leaks and redundant listeners
2546
+ if (this._activeDragInstances.indexOf(drag) > -1) {
2547
+ return;
2548
+ }
2549
+ this._activeDragInstances.push(drag);
2550
+ if (this._activeDragInstances.length === 1) {
2551
+ const isTouchEvent = event.type.startsWith('touch');
2552
+ // We explicitly bind __active__ listeners here, because newer browsers will default to
2553
+ // passive ones for `mousemove` and `touchmove`. The events need to be active, because we
2554
+ // use `preventDefault` to prevent the page from scrolling while the user is dragging.
2555
+ this._globalListeners
2556
+ .set(isTouchEvent ? 'touchend' : 'mouseup', {
2557
+ handler: (e) => this.pointerUp.next(e),
2558
+ options: true,
2559
+ })
2560
+ .set('scroll', {
2561
+ handler: (e) => this.scroll.next(e),
2562
+ // Use capturing so that we pick up scroll changes in any scrollable nodes that aren't
2563
+ // the document. See https://github.com/angular/components/issues/17144.
2564
+ options: true,
2565
+ })
2566
+ // Preventing the default action on `mousemove` isn't enough to disable text selection
2567
+ // on Safari so we need to prevent the selection event as well. Alternatively this can
2568
+ // be done by setting `user-select: none` on the `body`, however it has causes a style
2569
+ // recalculation which can be expensive on pages with a lot of elements.
2570
+ .set('selectstart', {
2571
+ handler: this._preventDefaultWhileDragging,
2572
+ options: activeCapturingEventOptions,
2573
+ });
2574
+ // We don't have to bind a move event for touch drag sequences, because
2575
+ // we already have a persistent global one bound from `registerDragItem`.
2576
+ if (!isTouchEvent) {
2577
+ this._globalListeners.set('mousemove', {
2578
+ handler: (e) => this.pointerMove.next(e),
2579
+ options: activeCapturingEventOptions,
2580
+ });
2581
+ }
2582
+ this._ngZone.runOutsideAngular(() => {
2583
+ this._globalListeners.forEach((config, name) => {
2584
+ this._document.addEventListener(name, config.handler, config.options);
2585
+ });
2586
+ });
2587
+ }
2588
+ }
2589
+ /** Stops dragging a drag item instance. */
2590
+ stopDragging(drag) {
2591
+ const index = this._activeDragInstances.indexOf(drag);
2592
+ if (index > -1) {
2593
+ this._activeDragInstances.splice(index, 1);
2594
+ if (this._activeDragInstances.length === 0) {
2595
+ this._clearGlobalListeners();
2596
+ }
2597
+ }
2598
+ }
2599
+ /** Gets whether a drag item instance is currently being dragged. */
2600
+ isDragging(drag) {
2601
+ return this._activeDragInstances.indexOf(drag) > -1;
2602
+ }
2603
+ /**
2604
+ * Gets a stream that will emit when any element on the page is scrolled while an item is being
2605
+ * dragged.
2606
+ * @param shadowRoot Optional shadow root that the current dragging sequence started from.
2607
+ * Top-level listeners won't pick up events coming from the shadow DOM so this parameter can
2608
+ * be used to include an additional top-level listener at the shadow root level.
2609
+ */
2610
+ scrolled(shadowRoot) {
2611
+ const streams = [this.scroll];
2612
+ if (shadowRoot && shadowRoot !== this._document) {
2613
+ // Note that this is basically the same as `fromEvent` from rxjs, but we do it ourselves,
2614
+ // because we want to guarantee that the event is bound outside of the `NgZone`. With
2615
+ // `fromEvent` it'll only happen if the subscription is outside the `NgZone`.
2616
+ streams.push(new Observable((observer) => {
2617
+ return this._ngZone.runOutsideAngular(() => {
2618
+ const eventOptions = true;
2619
+ const callback = (event) => {
2620
+ if (this._activeDragInstances.length) {
2621
+ observer.next(event);
2622
+ }
2623
+ };
2624
+ shadowRoot.addEventListener('scroll', callback, eventOptions);
2625
+ return () => {
2626
+ shadowRoot.removeEventListener('scroll', callback, eventOptions);
2627
+ };
2628
+ });
2629
+ }));
2630
+ }
2631
+ return merge(...streams);
2632
+ }
2633
+ ngOnDestroy() {
2634
+ this._dragInstances.forEach(instance => this.removeDragItem(instance));
2635
+ this._dropInstances.forEach(instance => this.removeDropContainer(instance));
2636
+ this._clearGlobalListeners();
2637
+ this.pointerMove.complete();
2638
+ this.pointerUp.complete();
2639
+ }
2640
+ /** Clears out the global event listeners from the `document`. */
2641
+ _clearGlobalListeners() {
2642
+ this._globalListeners.forEach((config, name) => {
2643
+ this._document.removeEventListener(name, config.handler, config.options);
2644
+ });
2645
+ this._globalListeners.clear();
2646
+ }
2647
+ }
2648
+ DragDropRegistry.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: DragDropRegistry, deps: [{ token: i0.NgZone }, { token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Injectable });
2649
+ DragDropRegistry.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: DragDropRegistry, providedIn: 'root' });
2650
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: DragDropRegistry, decorators: [{
2651
+ type: Injectable,
2652
+ args: [{ providedIn: 'root' }]
2653
+ }], ctorParameters: function () {
2654
+ return [{ type: i0.NgZone }, { type: undefined, decorators: [{
2655
+ type: Inject,
2656
+ args: [DOCUMENT]
2657
+ }] }];
2658
+ } });
2659
+
2660
+ /**
2661
+ * @license
2662
+ * Copyright Google LLC All Rights Reserved.
2663
+ *
2664
+ * Use of this source code is governed by an MIT-style license that can be
2665
+ * found in the LICENSE file at https://angular.io/license
2666
+ */
2667
+ /** Default configuration to be used when creating a `DragRef`. */
2668
+ const DEFAULT_CONFIG = {
2669
+ dragStartThreshold: 5,
2670
+ pointerDirectionChangeThreshold: 5,
2671
+ };
2672
+ /**
2673
+ * Service that allows for drag-and-drop functionality to be attached to DOM elements.
2674
+ */
2675
+ class DragDrop {
2676
+ constructor(_document, _ngZone, _viewportRuler, _dragDropRegistry) {
2677
+ this._document = _document;
2678
+ this._ngZone = _ngZone;
2679
+ this._viewportRuler = _viewportRuler;
2680
+ this._dragDropRegistry = _dragDropRegistry;
2681
+ }
2682
+ /**
2683
+ * Turns an element into a draggable item.
2684
+ * @param element Element to which to attach the dragging functionality.
2685
+ * @param config Object used to configure the dragging behavior.
2686
+ */
2687
+ createDrag(element, config = DEFAULT_CONFIG) {
2688
+ return new DragRef(element, config, this._document, this._ngZone, this._viewportRuler, this._dragDropRegistry);
2689
+ }
2690
+ /**
2691
+ * Turns an element into a drop list.
2692
+ * @param element Element to which to attach the drop list functionality.
2693
+ */
2694
+ createDropList(element) {
2695
+ return new DropListRef(element, this._dragDropRegistry, this._document, this._ngZone, this._viewportRuler);
2696
+ }
2697
+ }
2698
+ DragDrop.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: DragDrop, deps: [{ token: DOCUMENT }, { token: i0.NgZone }, { token: i1.ViewportRuler }, { token: DragDropRegistry }], target: i0.ɵɵFactoryTarget.Injectable });
2699
+ DragDrop.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: DragDrop, providedIn: 'root' });
2700
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: DragDrop, decorators: [{
2701
+ type: Injectable,
2702
+ args: [{ providedIn: 'root' }]
2703
+ }], ctorParameters: function () {
2704
+ return [{ type: undefined, decorators: [{
2705
+ type: Inject,
2706
+ args: [DOCUMENT]
2707
+ }] }, { type: i0.NgZone }, { type: i1.ViewportRuler }, { type: DragDropRegistry }];
2708
+ } });
2709
+
2710
+ /**
2711
+ * @license
2712
+ * Copyright Google LLC All Rights Reserved.
2713
+ *
2714
+ * Use of this source code is governed by an MIT-style license that can be
2715
+ * found in the LICENSE file at https://angular.io/license
2716
+ */
2717
+ /**
2718
+ * Injection token that can be used for a `CdkDrag` to provide itself as a parent to the
2719
+ * drag-specific child directive (`CdkDragHandle`, `CdkDragPreview` etc.). Used primarily
2720
+ * to avoid circular imports.
2721
+ * @docs-private
2722
+ */
2723
+ const CDK_DRAG_PARENT = new InjectionToken('CDK_DRAG_PARENT');
2724
+
2725
+ /**
2726
+ * @license
2727
+ * Copyright Google LLC All Rights Reserved.
2728
+ *
2729
+ * Use of this source code is governed by an MIT-style license that can be
2730
+ * found in the LICENSE file at https://angular.io/license
2731
+ */
2732
+ /**
2733
+ * Injection token that can be used to reference instances of `CdkDropListGroup`. It serves as
2734
+ * alternative token to the actual `CdkDropListGroup` class which could cause unnecessary
2735
+ * retention of the class and its directive metadata.
2736
+ */
2737
+ const CDK_DROP_LIST_GROUP = new InjectionToken('CdkDropListGroup');
2738
+ /**
2739
+ * Declaratively connects sibling `cdkDropList` instances together. All of the `cdkDropList`
2740
+ * elements that are placed inside a `cdkDropListGroup` will be connected to each other
2741
+ * automatically. Can be used as an alternative to the `cdkDropListConnectedTo` input
2742
+ * from `cdkDropList`.
2743
+ */
2744
+ class CdkDropListGroup {
2745
+ constructor() {
2746
+ /** Drop lists registered inside the group. */
2747
+ this._items = new Set();
2748
+ this._disabled = false;
2749
+ }
2750
+ /** Whether starting a dragging sequence from inside this group is disabled. */
2751
+ get disabled() {
2752
+ return this._disabled;
2753
+ }
2754
+ set disabled(value) {
2755
+ this._disabled = coerceBooleanProperty(value);
2756
+ }
2757
+ ngOnDestroy() {
2758
+ this._items.clear();
2759
+ }
2760
+ }
2761
+ CdkDropListGroup.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: CdkDropListGroup, deps: [], target: i0.ɵɵFactoryTarget.Directive });
2762
+ CdkDropListGroup.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.0", type: CdkDropListGroup, selector: "[cdkDropListGroup]", inputs: { disabled: ["cdkDropListGroupDisabled", "disabled"] }, providers: [{ provide: CDK_DROP_LIST_GROUP, useExisting: CdkDropListGroup }], exportAs: ["cdkDropListGroup"], ngImport: i0 });
2763
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: CdkDropListGroup, decorators: [{
2764
+ type: Directive,
2765
+ args: [{
2766
+ selector: '[cdkDropListGroup]',
2767
+ exportAs: 'cdkDropListGroup',
2768
+ providers: [{ provide: CDK_DROP_LIST_GROUP, useExisting: CdkDropListGroup }],
2769
+ }]
2770
+ }], propDecorators: { disabled: [{
2771
+ type: Input,
2772
+ args: ['cdkDropListGroupDisabled']
2773
+ }] } });
2774
+
2775
+ /**
2776
+ * @license
2777
+ * Copyright Google LLC All Rights Reserved.
2778
+ *
2779
+ * Use of this source code is governed by an MIT-style license that can be
2780
+ * found in the LICENSE file at https://angular.io/license
2781
+ */
2782
+ /**
2783
+ * Injection token that can be used to configure the
2784
+ * behavior of the drag&drop-related components.
2785
+ */
2786
+ const CDK_DRAG_CONFIG = new InjectionToken('CDK_DRAG_CONFIG');
2787
+
2788
+ /**
2789
+ * @license
2790
+ * Copyright Google LLC All Rights Reserved.
2791
+ *
2792
+ * Use of this source code is governed by an MIT-style license that can be
2793
+ * found in the LICENSE file at https://angular.io/license
2794
+ */
2795
+ /**
2796
+ * Asserts that a particular node is an element.
2797
+ * @param node Node to be checked.
2798
+ * @param name Name to attach to the error message.
2799
+ */
2800
+ function assertElementNode(node, name) {
2801
+ if (node.nodeType !== 1) {
2802
+ throw Error(`${name} must be attached to an element node. ` + `Currently attached to "${node.nodeName}".`);
2803
+ }
2804
+ }
2805
+
2806
+ /**
2807
+ * @license
2808
+ * Copyright Google LLC All Rights Reserved.
2809
+ *
2810
+ * Use of this source code is governed by an MIT-style license that can be
2811
+ * found in the LICENSE file at https://angular.io/license
2812
+ */
2813
+ /** Counter used to generate unique ids for drop zones. */
2814
+ let _uniqueIdCounter = 0;
2815
+ /**
2816
+ * Injection token that can be used to reference instances of `CdkDropList`. It serves as
2817
+ * alternative token to the actual `CdkDropList` class which could cause unnecessary
2818
+ * retention of the class and its directive metadata.
2819
+ */
2820
+ const CDK_DROP_LIST = new InjectionToken('CdkDropList');
2821
+ /** Container that wraps a set of draggable items. */
2822
+ class CdkDropList {
2823
+ constructor(
2824
+ /** Element that the drop list is attached to. */
2825
+ element, dragDrop, _changeDetectorRef, _scrollDispatcher, _dir, _group, config) {
2826
+ this.element = element;
2827
+ this._changeDetectorRef = _changeDetectorRef;
2828
+ this._scrollDispatcher = _scrollDispatcher;
2829
+ this._dir = _dir;
2830
+ this._group = _group;
2831
+ /** Emits when the list has been destroyed. */
2832
+ this._destroyed = new Subject();
2833
+ /**
2834
+ * Other draggable containers that this container is connected to and into which the
2835
+ * container's items can be transferred. Can either be references to other drop containers,
2836
+ * or their unique IDs.
2837
+ */
2838
+ this.connectedTo = [];
2839
+ /**
2840
+ * Unique ID for the drop zone. Can be used as a reference
2841
+ * in the `connectedTo` of another `CdkDropList`.
2842
+ */
2843
+ this.id = `cdk-drop-list-${_uniqueIdCounter++}`;
2844
+ /**
2845
+ * Function that is used to determine whether an item
2846
+ * is allowed to be moved into a drop container.
2847
+ */
2848
+ this.enterPredicate = () => true;
2849
+ /** Functions that is used to determine whether an item can be sorted into a particular index. */
2850
+ this.sortPredicate = () => true;
2851
+ /** Emits when the user drops an item inside the container. */
2852
+ this.dropped = new EventEmitter();
2853
+ /**
2854
+ * Emits when the user has moved a new drag item into this container.
2855
+ */
2856
+ this.entered = new EventEmitter();
2857
+ /**
2858
+ * Emits when the user removes an item from the container
2859
+ * by dragging it into another container.
2860
+ */
2861
+ this.exited = new EventEmitter();
2862
+ /** Emits as the user is swapping items while actively dragging. */
2863
+ this.sorted = new EventEmitter();
2864
+ /**
2865
+ * Keeps track of the items that are registered with this container. Historically we used to
2866
+ * do this with a `ContentChildren` query, however queries don't handle transplanted views very
2867
+ * well which means that we can't handle cases like dragging the headers of a `mat-table`
2868
+ * correctly. What we do instead is to have the items register themselves with the container
2869
+ * and then we sort them based on their position in the DOM.
2870
+ */
2871
+ this._unsortedItems = new Set();
2872
+ if (typeof ngDevMode === 'undefined' || ngDevMode) {
2873
+ assertElementNode(element.nativeElement, 'cdkDropList');
2874
+ }
2875
+ this._dropListRef = dragDrop.createDropList(element);
2876
+ this._dropListRef.data = this;
2877
+ if (config) {
2878
+ this._assignDefaults(config);
2879
+ }
2880
+ this._dropListRef.enterPredicate = (drag, drop) => {
2881
+ return this.enterPredicate(drag.data, drop.data);
2882
+ };
2883
+ this._dropListRef.sortPredicate = (index, drag, drop) => {
2884
+ return this.sortPredicate(index, drag.data, drop.data);
2885
+ };
2886
+ this._setupInputSyncSubscription(this._dropListRef);
2887
+ this._handleEvents(this._dropListRef);
2888
+ CdkDropList._dropLists.push(this);
2889
+ if (_group) {
2890
+ _group._items.add(this);
2891
+ }
2892
+ }
2893
+ /** Whether starting a dragging sequence from this container is disabled. */
2894
+ get disabled() {
2895
+ return this._disabled || (!!this._group && this._group.disabled);
2896
+ }
2897
+ set disabled(value) {
2898
+ // Usually we sync the directive and ref state right before dragging starts, in order to have
2899
+ // a single point of failure and to avoid having to use setters for everything. `disabled` is
2900
+ // a special case, because it can prevent the `beforeStarted` event from firing, which can lock
2901
+ // the user in a disabled state, so we also need to sync it as it's being set.
2902
+ this._dropListRef.disabled = this._disabled = coerceBooleanProperty(value);
2903
+ }
2904
+ /** Registers an items with the drop list. */
2905
+ addItem(item) {
2906
+ this._unsortedItems.add(item);
2907
+ if (this._dropListRef.isDragging()) {
2908
+ this._syncItemsWithRef();
2909
+ }
2910
+ }
2911
+ /** Removes an item from the drop list. */
2912
+ removeItem(item) {
2913
+ this._unsortedItems.delete(item);
2914
+ if (this._dropListRef.isDragging()) {
2915
+ this._syncItemsWithRef();
2916
+ }
2917
+ }
2918
+ /** Gets the registered items in the list, sorted by their position in the DOM. */
2919
+ getSortedItems() {
2920
+ return Array.from(this._unsortedItems).sort((a, b) => {
2921
+ const documentPosition = a._dragRef
2922
+ .getVisibleElement()
2923
+ .compareDocumentPosition(b._dragRef.getVisibleElement());
2924
+ // `compareDocumentPosition` returns a bitmask so we have to use a bitwise operator.
2925
+ // https://developer.mozilla.org/en-US/docs/Web/API/Node/compareDocumentPosition
2926
+ // tslint:disable-next-line:no-bitwise
2927
+ return documentPosition & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1;
2928
+ });
2929
+ }
2930
+ ngOnDestroy() {
2931
+ const index = CdkDropList._dropLists.indexOf(this);
2932
+ if (index > -1) {
2933
+ CdkDropList._dropLists.splice(index, 1);
2934
+ }
2935
+ if (this._group) {
2936
+ this._group._items.delete(this);
2937
+ }
2938
+ this._unsortedItems.clear();
2939
+ this._dropListRef.dispose();
2940
+ this._destroyed.next();
2941
+ this._destroyed.complete();
2942
+ }
2943
+ /** Syncs the inputs of the CdkDropList with the options of the underlying DropListRef. */
2944
+ _setupInputSyncSubscription(ref) {
2945
+ if (this._dir) {
2946
+ this._dir.change
2947
+ .pipe(startWith(this._dir.value), takeUntil(this._destroyed))
2948
+ .subscribe(value => ref.withDirection(value));
2949
+ }
2950
+ ref.beforeStarted.subscribe(() => {
2951
+ const siblings = coerceArray(this.connectedTo).map(drop => {
2952
+ if (typeof drop === 'string') {
2953
+ const correspondingDropList = CdkDropList._dropLists.find(list => list.id === drop);
2954
+ if (!correspondingDropList && (typeof ngDevMode === 'undefined' || ngDevMode)) {
2955
+ console.warn(`CdkDropList could not find connected drop list with id "${drop}"`);
2956
+ }
2957
+ return correspondingDropList;
2958
+ }
2959
+ return drop;
2960
+ });
2961
+ if (this._group) {
2962
+ this._group._items.forEach(drop => {
2963
+ if (siblings.indexOf(drop) === -1) {
2964
+ siblings.push(drop);
2965
+ }
2966
+ });
2967
+ }
2968
+ // Note that we resolve the scrollable parents here so that we delay the resolution
2969
+ // as long as possible, ensuring that the element is in its final place in the DOM.
2970
+ if (!this._scrollableParentsResolved) {
2971
+ const scrollableParents = this._scrollDispatcher
2972
+ .getAncestorScrollContainers(this.element)
2973
+ .map(scrollable => scrollable.getElementRef().nativeElement);
2974
+ this._dropListRef.withScrollableParents(scrollableParents);
2975
+ // Only do this once since it involves traversing the DOM and the parents
2976
+ // shouldn't be able to change without the drop list being destroyed.
2977
+ this._scrollableParentsResolved = true;
2978
+ }
2979
+ ref.disabled = this.disabled;
2980
+ ref.lockAxis = this.lockAxis;
2981
+ ref.sortingDisabled = coerceBooleanProperty(this.sortingDisabled);
2982
+ ref.autoScrollDisabled = coerceBooleanProperty(this.autoScrollDisabled);
2983
+ ref.autoScrollStep = coerceNumberProperty(this.autoScrollStep, 2);
2984
+ ref
2985
+ .connectedTo(siblings.filter(drop => drop && drop !== this).map(list => list._dropListRef))
2986
+ .withOrientation(this.orientation);
2987
+ });
2988
+ }
2989
+ /** Handles events from the underlying DropListRef. */
2990
+ _handleEvents(ref) {
2991
+ ref.beforeStarted.subscribe(() => {
2992
+ this._syncItemsWithRef();
2993
+ this._changeDetectorRef.markForCheck();
2994
+ });
2995
+ ref.entered.subscribe(event => {
2996
+ this.entered.emit({
2997
+ container: this,
2998
+ item: event.item.data,
2999
+ currentIndex: event.currentIndex,
3000
+ });
3001
+ });
3002
+ ref.exited.subscribe(event => {
3003
+ this.exited.emit({
3004
+ container: this,
3005
+ item: event.item.data,
3006
+ });
3007
+ this._changeDetectorRef.markForCheck();
3008
+ });
3009
+ ref.sorted.subscribe(event => {
3010
+ this.sorted.emit({
3011
+ previousIndex: event.previousIndex,
3012
+ currentIndex: event.currentIndex,
3013
+ container: this,
3014
+ item: event.item.data,
3015
+ });
3016
+ });
3017
+ ref.dropped.subscribe(dropEvent => {
3018
+ this.dropped.emit({
3019
+ previousIndex: dropEvent.previousIndex,
3020
+ currentIndex: dropEvent.currentIndex,
3021
+ previousContainer: dropEvent.previousContainer.data,
3022
+ container: dropEvent.container.data,
3023
+ item: dropEvent.item.data,
3024
+ isPointerOverContainer: dropEvent.isPointerOverContainer,
3025
+ distance: dropEvent.distance,
3026
+ dropPoint: dropEvent.dropPoint,
3027
+ event: dropEvent.event,
3028
+ });
3029
+ // Mark for check since all of these events run outside of change
3030
+ // detection and we're not guaranteed for something else to have triggered it.
3031
+ this._changeDetectorRef.markForCheck();
3032
+ });
3033
+ }
3034
+ /** Assigns the default input values based on a provided config object. */
3035
+ _assignDefaults(config) {
3036
+ const { lockAxis, draggingDisabled, sortingDisabled, listAutoScrollDisabled, listOrientation } = config;
3037
+ this.disabled = draggingDisabled == null ? false : draggingDisabled;
3038
+ this.sortingDisabled = sortingDisabled == null ? false : sortingDisabled;
3039
+ this.autoScrollDisabled = listAutoScrollDisabled == null ? false : listAutoScrollDisabled;
3040
+ this.orientation = listOrientation || 'vertical';
3041
+ if (lockAxis) {
3042
+ this.lockAxis = lockAxis;
3043
+ }
3044
+ }
3045
+ /** Syncs up the registered drag items with underlying drop list ref. */
3046
+ _syncItemsWithRef() {
3047
+ this._dropListRef.withItems(this.getSortedItems().map(item => item._dragRef));
3048
+ }
3049
+ }
3050
+ /** Keeps track of the drop lists that are currently on the page. */
3051
+ CdkDropList._dropLists = [];
3052
+ CdkDropList.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: CdkDropList, deps: [{ token: i0.ElementRef }, { token: DragDrop }, { token: i0.ChangeDetectorRef }, { token: i1.ScrollDispatcher }, { token: i3.Directionality, optional: true }, { token: CDK_DROP_LIST_GROUP, optional: true, skipSelf: true }, { token: CDK_DRAG_CONFIG, optional: true }], target: i0.ɵɵFactoryTarget.Directive });
3053
+ CdkDropList.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.0", type: CdkDropList, selector: "[cdkDropList], cdk-drop-list", inputs: { connectedTo: ["cdkDropListConnectedTo", "connectedTo"], data: ["cdkDropListData", "data"], orientation: ["cdkDropListOrientation", "orientation"], id: "id", lockAxis: ["cdkDropListLockAxis", "lockAxis"], disabled: ["cdkDropListDisabled", "disabled"], sortingDisabled: ["cdkDropListSortingDisabled", "sortingDisabled"], enterPredicate: ["cdkDropListEnterPredicate", "enterPredicate"], sortPredicate: ["cdkDropListSortPredicate", "sortPredicate"], autoScrollDisabled: ["cdkDropListAutoScrollDisabled", "autoScrollDisabled"], autoScrollStep: ["cdkDropListAutoScrollStep", "autoScrollStep"] }, outputs: { dropped: "cdkDropListDropped", entered: "cdkDropListEntered", exited: "cdkDropListExited", sorted: "cdkDropListSorted" }, host: { properties: { "attr.id": "id", "class.cdk-drop-list-disabled": "disabled", "class.cdk-drop-list-dragging": "_dropListRef.isDragging()", "class.cdk-drop-list-receiving": "_dropListRef.isReceiving()" }, classAttribute: "cdk-drop-list" }, providers: [
3054
+ // Prevent child drop lists from picking up the same group as their parent.
3055
+ { provide: CDK_DROP_LIST_GROUP, useValue: undefined },
3056
+ { provide: CDK_DROP_LIST, useExisting: CdkDropList },
3057
+ ], exportAs: ["cdkDropList"], ngImport: i0 });
3058
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: CdkDropList, decorators: [{
3059
+ type: Directive,
3060
+ args: [{
3061
+ selector: '[cdkDropList], cdk-drop-list',
3062
+ exportAs: 'cdkDropList',
3063
+ providers: [
3064
+ // Prevent child drop lists from picking up the same group as their parent.
3065
+ { provide: CDK_DROP_LIST_GROUP, useValue: undefined },
3066
+ { provide: CDK_DROP_LIST, useExisting: CdkDropList },
3067
+ ],
3068
+ host: {
3069
+ 'class': 'cdk-drop-list',
3070
+ '[attr.id]': 'id',
3071
+ '[class.cdk-drop-list-disabled]': 'disabled',
3072
+ '[class.cdk-drop-list-dragging]': '_dropListRef.isDragging()',
3073
+ '[class.cdk-drop-list-receiving]': '_dropListRef.isReceiving()',
3074
+ },
3075
+ }]
3076
+ }], ctorParameters: function () {
3077
+ return [{ type: i0.ElementRef }, { type: DragDrop }, { type: i0.ChangeDetectorRef }, { type: i1.ScrollDispatcher }, { type: i3.Directionality, decorators: [{
3078
+ type: Optional
3079
+ }] }, { type: CdkDropListGroup, decorators: [{
3080
+ type: Optional
3081
+ }, {
3082
+ type: Inject,
3083
+ args: [CDK_DROP_LIST_GROUP]
3084
+ }, {
3085
+ type: SkipSelf
3086
+ }] }, { type: undefined, decorators: [{
3087
+ type: Optional
3088
+ }, {
3089
+ type: Inject,
3090
+ args: [CDK_DRAG_CONFIG]
3091
+ }] }];
3092
+ }, propDecorators: { connectedTo: [{
3093
+ type: Input,
3094
+ args: ['cdkDropListConnectedTo']
3095
+ }], data: [{
3096
+ type: Input,
3097
+ args: ['cdkDropListData']
3098
+ }], orientation: [{
3099
+ type: Input,
3100
+ args: ['cdkDropListOrientation']
3101
+ }], id: [{
3102
+ type: Input
3103
+ }], lockAxis: [{
3104
+ type: Input,
3105
+ args: ['cdkDropListLockAxis']
3106
+ }], disabled: [{
3107
+ type: Input,
3108
+ args: ['cdkDropListDisabled']
3109
+ }], sortingDisabled: [{
3110
+ type: Input,
3111
+ args: ['cdkDropListSortingDisabled']
3112
+ }], enterPredicate: [{
3113
+ type: Input,
3114
+ args: ['cdkDropListEnterPredicate']
3115
+ }], sortPredicate: [{
3116
+ type: Input,
3117
+ args: ['cdkDropListSortPredicate']
3118
+ }], autoScrollDisabled: [{
3119
+ type: Input,
3120
+ args: ['cdkDropListAutoScrollDisabled']
3121
+ }], autoScrollStep: [{
3122
+ type: Input,
3123
+ args: ['cdkDropListAutoScrollStep']
3124
+ }], dropped: [{
3125
+ type: Output,
3126
+ args: ['cdkDropListDropped']
3127
+ }], entered: [{
3128
+ type: Output,
3129
+ args: ['cdkDropListEntered']
3130
+ }], exited: [{
3131
+ type: Output,
3132
+ args: ['cdkDropListExited']
3133
+ }], sorted: [{
3134
+ type: Output,
3135
+ args: ['cdkDropListSorted']
3136
+ }] } });
3137
+
3138
+ /**
3139
+ * @license
3140
+ * Copyright Google LLC All Rights Reserved.
3141
+ *
3142
+ * Use of this source code is governed by an MIT-style license that can be
3143
+ * found in the LICENSE file at https://angular.io/license
3144
+ */
3145
+ /**
3146
+ * Injection token that can be used to reference instances of `CdkDragHandle`. It serves as
3147
+ * alternative token to the actual `CdkDragHandle` class which could cause unnecessary
3148
+ * retention of the class and its directive metadata.
3149
+ */
3150
+ const CDK_DRAG_HANDLE = new InjectionToken('CdkDragHandle');
3151
+ /** Handle that can be used to drag a CdkDrag instance. */
3152
+ class CdkDragHandle {
3153
+ constructor(element, parentDrag) {
3154
+ this.element = element;
3155
+ /** Emits when the state of the handle has changed. */
3156
+ this._stateChanges = new Subject();
3157
+ this._disabled = false;
3158
+ if (typeof ngDevMode === 'undefined' || ngDevMode) {
3159
+ assertElementNode(element.nativeElement, 'cdkDragHandle');
3160
+ }
3161
+ this._parentDrag = parentDrag;
3162
+ }
3163
+ /** Whether starting to drag through this handle is disabled. */
3164
+ get disabled() {
3165
+ return this._disabled;
3166
+ }
3167
+ set disabled(value) {
3168
+ this._disabled = coerceBooleanProperty(value);
3169
+ this._stateChanges.next(this);
3170
+ }
3171
+ ngOnDestroy() {
3172
+ this._stateChanges.complete();
3173
+ }
3174
+ }
3175
+ CdkDragHandle.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: CdkDragHandle, deps: [{ token: i0.ElementRef }, { token: CDK_DRAG_PARENT, optional: true, skipSelf: true }], target: i0.ɵɵFactoryTarget.Directive });
3176
+ CdkDragHandle.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.0", type: CdkDragHandle, selector: "[cdkDragHandle]", inputs: { disabled: ["cdkDragHandleDisabled", "disabled"] }, host: { classAttribute: "cdk-drag-handle" }, providers: [{ provide: CDK_DRAG_HANDLE, useExisting: CdkDragHandle }], ngImport: i0 });
3177
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: CdkDragHandle, decorators: [{
3178
+ type: Directive,
3179
+ args: [{
3180
+ selector: '[cdkDragHandle]',
3181
+ host: {
3182
+ 'class': 'cdk-drag-handle',
3183
+ },
3184
+ providers: [{ provide: CDK_DRAG_HANDLE, useExisting: CdkDragHandle }],
3185
+ }]
3186
+ }], ctorParameters: function () {
3187
+ return [{ type: i0.ElementRef }, { type: undefined, decorators: [{
3188
+ type: Inject,
3189
+ args: [CDK_DRAG_PARENT]
3190
+ }, {
3191
+ type: Optional
3192
+ }, {
3193
+ type: SkipSelf
3194
+ }] }];
3195
+ }, propDecorators: { disabled: [{
3196
+ type: Input,
3197
+ args: ['cdkDragHandleDisabled']
3198
+ }] } });
3199
+
3200
+ /**
3201
+ * @license
3202
+ * Copyright Google LLC All Rights Reserved.
3203
+ *
3204
+ * Use of this source code is governed by an MIT-style license that can be
3205
+ * found in the LICENSE file at https://angular.io/license
3206
+ */
3207
+ /**
3208
+ * Injection token that can be used to reference instances of `CdkDragPlaceholder`. It serves as
3209
+ * alternative token to the actual `CdkDragPlaceholder` class which could cause unnecessary
3210
+ * retention of the class and its directive metadata.
3211
+ */
3212
+ const CDK_DRAG_PLACEHOLDER = new InjectionToken('CdkDragPlaceholder');
3213
+ /**
3214
+ * Element that will be used as a template for the placeholder of a CdkDrag when
3215
+ * it is being dragged. The placeholder is displayed in place of the element being dragged.
3216
+ */
3217
+ class CdkDragPlaceholder {
3218
+ constructor(templateRef) {
3219
+ this.templateRef = templateRef;
3220
+ }
3221
+ }
3222
+ CdkDragPlaceholder.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: CdkDragPlaceholder, deps: [{ token: i0.TemplateRef }], target: i0.ɵɵFactoryTarget.Directive });
3223
+ CdkDragPlaceholder.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.0", type: CdkDragPlaceholder, selector: "ng-template[cdkDragPlaceholder]", inputs: { data: "data" }, providers: [{ provide: CDK_DRAG_PLACEHOLDER, useExisting: CdkDragPlaceholder }], ngImport: i0 });
3224
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: CdkDragPlaceholder, decorators: [{
3225
+ type: Directive,
3226
+ args: [{
3227
+ selector: 'ng-template[cdkDragPlaceholder]',
3228
+ providers: [{ provide: CDK_DRAG_PLACEHOLDER, useExisting: CdkDragPlaceholder }],
3229
+ }]
3230
+ }], ctorParameters: function () { return [{ type: i0.TemplateRef }]; }, propDecorators: { data: [{
3231
+ type: Input
3232
+ }] } });
3233
+
3234
+ /**
3235
+ * @license
3236
+ * Copyright Google LLC All Rights Reserved.
3237
+ *
3238
+ * Use of this source code is governed by an MIT-style license that can be
3239
+ * found in the LICENSE file at https://angular.io/license
3240
+ */
3241
+ /**
3242
+ * Injection token that can be used to reference instances of `CdkDragPreview`. It serves as
3243
+ * alternative token to the actual `CdkDragPreview` class which could cause unnecessary
3244
+ * retention of the class and its directive metadata.
3245
+ */
3246
+ const CDK_DRAG_PREVIEW = new InjectionToken('CdkDragPreview');
3247
+ /**
3248
+ * Element that will be used as a template for the preview
3249
+ * of a CdkDrag when it is being dragged.
3250
+ */
3251
+ class CdkDragPreview {
3252
+ constructor(templateRef) {
3253
+ this.templateRef = templateRef;
3254
+ this._matchSize = false;
3255
+ }
3256
+ /** Whether the preview should preserve the same size as the item that is being dragged. */
3257
+ get matchSize() {
3258
+ return this._matchSize;
3259
+ }
3260
+ set matchSize(value) {
3261
+ this._matchSize = coerceBooleanProperty(value);
3262
+ }
3263
+ }
3264
+ CdkDragPreview.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: CdkDragPreview, deps: [{ token: i0.TemplateRef }], target: i0.ɵɵFactoryTarget.Directive });
3265
+ CdkDragPreview.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.0", type: CdkDragPreview, selector: "ng-template[cdkDragPreview]", inputs: { data: "data", matchSize: "matchSize" }, providers: [{ provide: CDK_DRAG_PREVIEW, useExisting: CdkDragPreview }], ngImport: i0 });
3266
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: CdkDragPreview, decorators: [{
3267
+ type: Directive,
3268
+ args: [{
3269
+ selector: 'ng-template[cdkDragPreview]',
3270
+ providers: [{ provide: CDK_DRAG_PREVIEW, useExisting: CdkDragPreview }],
3271
+ }]
3272
+ }], ctorParameters: function () { return [{ type: i0.TemplateRef }]; }, propDecorators: { data: [{
3273
+ type: Input
3274
+ }], matchSize: [{
3275
+ type: Input
3276
+ }] } });
3277
+
3278
+ const DRAG_HOST_CLASS = 'cdk-drag';
3279
+ /** Element that can be moved inside a CdkDropList container. */
3280
+ class CdkDrag {
3281
+ constructor(
3282
+ /** Element that the draggable is attached to. */
3283
+ element,
3284
+ /** Droppable container that the draggable is a part of. */
3285
+ dropContainer,
3286
+ /**
3287
+ * @deprecated `_document` parameter no longer being used and will be removed.
3288
+ * @breaking-change 12.0.0
3289
+ */
3290
+ _document, _ngZone, _viewContainerRef, config, _dir, dragDrop, _changeDetectorRef, _selfHandle, _parentDrag) {
3291
+ this.element = element;
3292
+ this.dropContainer = dropContainer;
3293
+ this._ngZone = _ngZone;
3294
+ this._viewContainerRef = _viewContainerRef;
3295
+ this._dir = _dir;
3296
+ this._changeDetectorRef = _changeDetectorRef;
3297
+ this._selfHandle = _selfHandle;
3298
+ this._parentDrag = _parentDrag;
3299
+ this._destroyed = new Subject();
3300
+ /** Emits when the user starts dragging the item. */
3301
+ this.started = new EventEmitter();
3302
+ /** Emits when the user has released a drag item, before any animations have started. */
3303
+ this.released = new EventEmitter();
3304
+ /** Emits when the user stops dragging an item in the container. */
3305
+ this.ended = new EventEmitter();
3306
+ /** Emits when the user has moved the item into a new container. */
3307
+ this.entered = new EventEmitter();
3308
+ /** Emits when the user removes the item its container by dragging it into another container. */
3309
+ this.exited = new EventEmitter();
3310
+ /** Emits when the user drops the item inside a container. */
3311
+ this.dropped = new EventEmitter();
3312
+ /**
3313
+ * Emits as the user is dragging the item. Use with caution,
3314
+ * because this event will fire for every pixel that the user has dragged.
3315
+ */
3316
+ this.moved = new Observable((observer) => {
3317
+ const subscription = this._dragRef.moved
3318
+ .pipe(map(movedEvent => ({
3319
+ source: this,
3320
+ pointerPosition: movedEvent.pointerPosition,
3321
+ event: movedEvent.event,
3322
+ delta: movedEvent.delta,
3323
+ distance: movedEvent.distance,
3324
+ })))
3325
+ .subscribe(observer);
3326
+ return () => {
3327
+ subscription.unsubscribe();
3328
+ };
3329
+ });
3330
+ this._dragRef = dragDrop.createDrag(element, {
3331
+ dragStartThreshold: config && config.dragStartThreshold != null ? config.dragStartThreshold : 5,
3332
+ pointerDirectionChangeThreshold: config && config.pointerDirectionChangeThreshold != null
3333
+ ? config.pointerDirectionChangeThreshold
3334
+ : 5,
3335
+ zIndex: config === null || config === void 0 ? void 0 : config.zIndex,
3336
+ });
3337
+ this._dragRef.data = this;
3338
+ // We have to keep track of the drag instances in order to be able to match an element to
3339
+ // a drag instance. We can't go through the global registry of `DragRef`, because the root
3340
+ // element could be different.
3341
+ CdkDrag._dragInstances.push(this);
3342
+ if (config) {
3343
+ this._assignDefaults(config);
3344
+ }
3345
+ // Note that usually the container is assigned when the drop list is picks up the item, but in
3346
+ // some cases (mainly transplanted views with OnPush, see #18341) we may end up in a situation
3347
+ // where there are no items on the first change detection pass, but the items get picked up as
3348
+ // soon as the user triggers another pass by dragging. This is a problem, because the item would
3349
+ // have to switch from standalone mode to drag mode in the middle of the dragging sequence which
3350
+ // is too late since the two modes save different kinds of information. We work around it by
3351
+ // assigning the drop container both from here and the list.
3352
+ if (dropContainer) {
3353
+ this._dragRef._withDropContainer(dropContainer._dropListRef);
3354
+ dropContainer.addItem(this);
3355
+ }
3356
+ this._syncInputs(this._dragRef);
3357
+ this._handleEvents(this._dragRef);
3358
+ }
3359
+ /** Whether starting to drag this element is disabled. */
3360
+ get disabled() {
3361
+ return this._disabled || (this.dropContainer && this.dropContainer.disabled);
3362
+ }
3363
+ set disabled(value) {
3364
+ this._disabled = coerceBooleanProperty(value);
3365
+ this._dragRef.disabled = this._disabled;
3366
+ }
3367
+ /**
3368
+ * Returns the element that is being used as a placeholder
3369
+ * while the current element is being dragged.
3370
+ */
3371
+ getPlaceholderElement() {
3372
+ return this._dragRef.getPlaceholderElement();
3373
+ }
3374
+ /** Returns the root draggable element. */
3375
+ getRootElement() {
3376
+ return this._dragRef.getRootElement();
3377
+ }
3378
+ /** Resets a standalone drag item to its initial position. */
3379
+ reset() {
3380
+ this._dragRef.reset();
3381
+ }
3382
+ /**
3383
+ * Gets the pixel coordinates of the draggable outside of a drop container.
3384
+ */
3385
+ getFreeDragPosition() {
3386
+ return this._dragRef.getFreeDragPosition();
3387
+ }
3388
+ /**
3389
+ * Sets the current position in pixels the draggable outside of a drop container.
3390
+ * @param value New position to be set.
3391
+ */
3392
+ setFreeDragPosition(value) {
3393
+ this._dragRef.setFreeDragPosition(value);
3394
+ }
3395
+ ngAfterViewInit() {
3396
+ // Normally this isn't in the zone, but it can cause major performance regressions for apps
3397
+ // using `zone-patch-rxjs` because it'll trigger a change detection when it unsubscribes.
3398
+ this._ngZone.runOutsideAngular(() => {
3399
+ // We need to wait for the zone to stabilize, in order for the reference
3400
+ // element to be in the proper place in the DOM. This is mostly relevant
3401
+ // for draggable elements inside portals since they get stamped out in
3402
+ // their original DOM position and then they get transferred to the portal.
3403
+ this._ngZone.onStable.pipe(take(1), takeUntil(this._destroyed)).subscribe(() => {
3404
+ this._updateRootElement();
3405
+ this._setupHandlesListener();
3406
+ if (this.freeDragPosition) {
3407
+ this._dragRef.setFreeDragPosition(this.freeDragPosition);
3408
+ }
3409
+ });
3410
+ });
3411
+ }
3412
+ ngOnChanges(changes) {
3413
+ const rootSelectorChange = changes['rootElementSelector'];
3414
+ const positionChange = changes['freeDragPosition'];
3415
+ // We don't have to react to the first change since it's being
3416
+ // handled in `ngAfterViewInit` where it needs to be deferred.
3417
+ if (rootSelectorChange && !rootSelectorChange.firstChange) {
3418
+ this._updateRootElement();
3419
+ }
3420
+ // Skip the first change since it's being handled in `ngAfterViewInit`.
3421
+ if (positionChange && !positionChange.firstChange && this.freeDragPosition) {
3422
+ this._dragRef.setFreeDragPosition(this.freeDragPosition);
3423
+ }
3424
+ }
3425
+ ngOnDestroy() {
3426
+ if (this.dropContainer) {
3427
+ this.dropContainer.removeItem(this);
3428
+ }
3429
+ const index = CdkDrag._dragInstances.indexOf(this);
3430
+ if (index > -1) {
3431
+ CdkDrag._dragInstances.splice(index, 1);
3432
+ }
3433
+ // Unnecessary in most cases, but used to avoid extra change detections with `zone-paths-rxjs`.
3434
+ this._ngZone.runOutsideAngular(() => {
3435
+ this._destroyed.next();
3436
+ this._destroyed.complete();
3437
+ this._dragRef.dispose();
3438
+ });
3439
+ }
3440
+ /** Syncs the root element with the `DragRef`. */
3441
+ _updateRootElement() {
3442
+ var _a;
3443
+ const element = this.element.nativeElement;
3444
+ let rootElement = element;
3445
+ if (this.rootElementSelector) {
3446
+ rootElement =
3447
+ element.closest !== undefined
3448
+ ? element.closest(this.rootElementSelector)
3449
+ : // Comment tag doesn't have closest method, so use parent's one.
3450
+ (_a = element.parentElement) === null || _a === void 0 ? void 0 : _a.closest(this.rootElementSelector);
3451
+ }
3452
+ if (rootElement && (typeof ngDevMode === 'undefined' || ngDevMode)) {
3453
+ assertElementNode(rootElement, 'cdkDrag');
3454
+ }
3455
+ this._dragRef.withRootElement(rootElement || element);
3456
+ }
3457
+ /** Gets the boundary element, based on the `boundaryElement` value. */
3458
+ _getBoundaryElement() {
3459
+ const boundary = this.boundaryElement;
3460
+ if (!boundary) {
3461
+ return null;
3462
+ }
3463
+ if (typeof boundary === 'string') {
3464
+ return this.element.nativeElement.closest(boundary);
3465
+ }
3466
+ return coerceElement(boundary);
3467
+ }
3468
+ /** Syncs the inputs of the CdkDrag with the options of the underlying DragRef. */
3469
+ _syncInputs(ref) {
3470
+ ref.beforeStarted.subscribe(() => {
3471
+ if (!ref.isDragging()) {
3472
+ const dir = this._dir;
3473
+ const dragStartDelay = this.dragStartDelay;
3474
+ const placeholder = this._placeholderTemplate
3475
+ ? {
3476
+ template: this._placeholderTemplate.templateRef,
3477
+ context: this._placeholderTemplate.data,
3478
+ viewContainer: this._viewContainerRef,
3479
+ }
3480
+ : null;
3481
+ const preview = this._previewTemplate
3482
+ ? {
3483
+ template: this._previewTemplate.templateRef,
3484
+ context: this._previewTemplate.data,
3485
+ matchSize: this._previewTemplate.matchSize,
3486
+ viewContainer: this._viewContainerRef,
3487
+ }
3488
+ : null;
3489
+ ref.disabled = this.disabled;
3490
+ ref.lockAxis = this.lockAxis;
3491
+ ref.dragStartDelay =
3492
+ typeof dragStartDelay === 'object' && dragStartDelay
3493
+ ? dragStartDelay
3494
+ : coerceNumberProperty(dragStartDelay);
3495
+ ref.constrainPosition = this.constrainPosition;
3496
+ ref.previewClass = this.previewClass;
3497
+ ref
3498
+ .withBoundaryElement(this._getBoundaryElement())
3499
+ .withPlaceholderTemplate(placeholder)
3500
+ .withPreviewTemplate(preview)
3501
+ .withPreviewContainer(this.previewContainer || 'global');
3502
+ if (dir) {
3503
+ ref.withDirection(dir.value);
3504
+ }
3505
+ }
3506
+ });
3507
+ // This only needs to be resolved once.
3508
+ ref.beforeStarted.pipe(take(1)).subscribe(() => {
3509
+ var _a;
3510
+ // If we managed to resolve a parent through DI, use it.
3511
+ if (this._parentDrag) {
3512
+ ref.withParent(this._parentDrag._dragRef);
3513
+ return;
3514
+ }
3515
+ // Otherwise fall back to resolving the parent by looking up the DOM. This can happen if
3516
+ // the item was projected into another item by something like `ngTemplateOutlet`.
3517
+ let parent = this.element.nativeElement.parentElement;
3518
+ while (parent) {
3519
+ if (parent.classList.contains(DRAG_HOST_CLASS)) {
3520
+ ref.withParent(((_a = CdkDrag._dragInstances.find(drag => {
3521
+ return drag.element.nativeElement === parent;
3522
+ })) === null || _a === void 0 ? void 0 : _a._dragRef) || null);
3523
+ break;
3524
+ }
3525
+ parent = parent.parentElement;
3526
+ }
3527
+ });
3528
+ }
3529
+ /** Handles the events from the underlying `DragRef`. */
3530
+ _handleEvents(ref) {
3531
+ ref.started.subscribe(startEvent => {
3532
+ this.started.emit({ source: this, event: startEvent.event });
3533
+ // Since all of these events run outside of change detection,
3534
+ // we need to ensure that everything is marked correctly.
3535
+ this._changeDetectorRef.markForCheck();
3536
+ });
3537
+ ref.released.subscribe(releaseEvent => {
3538
+ this.released.emit({ source: this, event: releaseEvent.event });
3539
+ });
3540
+ ref.ended.subscribe(endEvent => {
3541
+ this.ended.emit({
3542
+ source: this,
3543
+ distance: endEvent.distance,
3544
+ dropPoint: endEvent.dropPoint,
3545
+ event: endEvent.event,
3546
+ });
3547
+ // Since all of these events run outside of change detection,
3548
+ // we need to ensure that everything is marked correctly.
3549
+ this._changeDetectorRef.markForCheck();
3550
+ });
3551
+ ref.entered.subscribe(enterEvent => {
3552
+ this.entered.emit({
3553
+ container: enterEvent.container.data,
3554
+ item: this,
3555
+ currentIndex: enterEvent.currentIndex,
3556
+ });
3557
+ });
3558
+ ref.exited.subscribe(exitEvent => {
3559
+ this.exited.emit({
3560
+ container: exitEvent.container.data,
3561
+ item: this,
3562
+ });
3563
+ });
3564
+ ref.dropped.subscribe(dropEvent => {
3565
+ this.dropped.emit({
3566
+ previousIndex: dropEvent.previousIndex,
3567
+ currentIndex: dropEvent.currentIndex,
3568
+ previousContainer: dropEvent.previousContainer.data,
3569
+ container: dropEvent.container.data,
3570
+ isPointerOverContainer: dropEvent.isPointerOverContainer,
3571
+ item: this,
3572
+ distance: dropEvent.distance,
3573
+ dropPoint: dropEvent.dropPoint,
3574
+ event: dropEvent.event,
3575
+ });
3576
+ });
3577
+ }
3578
+ /** Assigns the default input values based on a provided config object. */
3579
+ _assignDefaults(config) {
3580
+ const { lockAxis, dragStartDelay, constrainPosition, previewClass, boundaryElement, draggingDisabled, rootElementSelector, previewContainer, } = config;
3581
+ this.disabled = draggingDisabled == null ? false : draggingDisabled;
3582
+ this.dragStartDelay = dragStartDelay || 0;
3583
+ if (lockAxis) {
3584
+ this.lockAxis = lockAxis;
3585
+ }
3586
+ if (constrainPosition) {
3587
+ this.constrainPosition = constrainPosition;
3588
+ }
3589
+ if (previewClass) {
3590
+ this.previewClass = previewClass;
3591
+ }
3592
+ if (boundaryElement) {
3593
+ this.boundaryElement = boundaryElement;
3594
+ }
3595
+ if (rootElementSelector) {
3596
+ this.rootElementSelector = rootElementSelector;
3597
+ }
3598
+ if (previewContainer) {
3599
+ this.previewContainer = previewContainer;
3600
+ }
3601
+ }
3602
+ /** Sets up the listener that syncs the handles with the drag ref. */
3603
+ _setupHandlesListener() {
3604
+ // Listen for any newly-added handles.
3605
+ this._handles.changes
3606
+ .pipe(startWith(this._handles),
3607
+ // Sync the new handles with the DragRef.
3608
+ tap((handles) => {
3609
+ const childHandleElements = handles
3610
+ .filter(handle => handle._parentDrag === this)
3611
+ .map(handle => handle.element);
3612
+ // Usually handles are only allowed to be a descendant of the drag element, but if
3613
+ // the consumer defined a different drag root, we should allow the drag element
3614
+ // itself to be a handle too.
3615
+ if (this._selfHandle && this.rootElementSelector) {
3616
+ childHandleElements.push(this.element);
3617
+ }
3618
+ this._dragRef.withHandles(childHandleElements);
3619
+ }),
3620
+ // Listen if the state of any of the handles changes.
3621
+ switchMap((handles) => {
3622
+ return merge(...handles.map(item => {
3623
+ return item._stateChanges.pipe(startWith(item));
3624
+ }));
3625
+ }), takeUntil(this._destroyed))
3626
+ .subscribe(handleInstance => {
3627
+ // Enabled/disable the handle that changed in the DragRef.
3628
+ const dragRef = this._dragRef;
3629
+ const handle = handleInstance.element.nativeElement;
3630
+ handleInstance.disabled ? dragRef.disableHandle(handle) : dragRef.enableHandle(handle);
3631
+ });
3632
+ }
3633
+ }
3634
+ CdkDrag._dragInstances = [];
3635
+ CdkDrag.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: CdkDrag, deps: [{ token: i0.ElementRef }, { token: CDK_DROP_LIST, optional: true, skipSelf: true }, { token: DOCUMENT }, { token: i0.NgZone }, { token: i0.ViewContainerRef }, { token: CDK_DRAG_CONFIG, optional: true }, { token: i3.Directionality, optional: true }, { token: DragDrop }, { token: i0.ChangeDetectorRef }, { token: CDK_DRAG_HANDLE, optional: true, self: true }, { token: CDK_DRAG_PARENT, optional: true, skipSelf: true }], target: i0.ɵɵFactoryTarget.Directive });
3636
+ CdkDrag.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.0", type: CdkDrag, selector: "[cdkDrag]", inputs: { data: ["cdkDragData", "data"], lockAxis: ["cdkDragLockAxis", "lockAxis"], rootElementSelector: ["cdkDragRootElement", "rootElementSelector"], boundaryElement: ["cdkDragBoundary", "boundaryElement"], dragStartDelay: ["cdkDragStartDelay", "dragStartDelay"], freeDragPosition: ["cdkDragFreeDragPosition", "freeDragPosition"], disabled: ["cdkDragDisabled", "disabled"], constrainPosition: ["cdkDragConstrainPosition", "constrainPosition"], previewClass: ["cdkDragPreviewClass", "previewClass"], previewContainer: ["cdkDragPreviewContainer", "previewContainer"] }, outputs: { started: "cdkDragStarted", released: "cdkDragReleased", ended: "cdkDragEnded", entered: "cdkDragEntered", exited: "cdkDragExited", dropped: "cdkDragDropped", moved: "cdkDragMoved" }, host: { properties: { "class.cdk-drag-disabled": "disabled", "class.cdk-drag-dragging": "_dragRef.isDragging()" }, classAttribute: "cdk-drag" }, providers: [{ provide: CDK_DRAG_PARENT, useExisting: CdkDrag }], queries: [{ propertyName: "_previewTemplate", first: true, predicate: CDK_DRAG_PREVIEW, descendants: true }, { propertyName: "_placeholderTemplate", first: true, predicate: CDK_DRAG_PLACEHOLDER, descendants: true }, { propertyName: "_handles", predicate: CDK_DRAG_HANDLE, descendants: true }], exportAs: ["cdkDrag"], usesOnChanges: true, ngImport: i0 });
3637
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: CdkDrag, decorators: [{
3638
+ type: Directive,
3639
+ args: [{
3640
+ selector: '[cdkDrag]',
3641
+ exportAs: 'cdkDrag',
3642
+ host: {
3643
+ 'class': DRAG_HOST_CLASS,
3644
+ '[class.cdk-drag-disabled]': 'disabled',
3645
+ '[class.cdk-drag-dragging]': '_dragRef.isDragging()',
3646
+ },
3647
+ providers: [{ provide: CDK_DRAG_PARENT, useExisting: CdkDrag }],
3648
+ }]
3649
+ }], ctorParameters: function () {
3650
+ return [{ type: i0.ElementRef }, { type: undefined, decorators: [{
3651
+ type: Inject,
3652
+ args: [CDK_DROP_LIST]
3653
+ }, {
3654
+ type: Optional
3655
+ }, {
3656
+ type: SkipSelf
3657
+ }] }, { type: undefined, decorators: [{
3658
+ type: Inject,
3659
+ args: [DOCUMENT]
3660
+ }] }, { type: i0.NgZone }, { type: i0.ViewContainerRef }, { type: undefined, decorators: [{
3661
+ type: Optional
3662
+ }, {
3663
+ type: Inject,
3664
+ args: [CDK_DRAG_CONFIG]
3665
+ }] }, { type: i3.Directionality, decorators: [{
3666
+ type: Optional
3667
+ }] }, { type: DragDrop }, { type: i0.ChangeDetectorRef }, { type: CdkDragHandle, decorators: [{
3668
+ type: Optional
3669
+ }, {
3670
+ type: Self
3671
+ }, {
3672
+ type: Inject,
3673
+ args: [CDK_DRAG_HANDLE]
3674
+ }] }, { type: CdkDrag, decorators: [{
3675
+ type: Optional
3676
+ }, {
3677
+ type: SkipSelf
3678
+ }, {
3679
+ type: Inject,
3680
+ args: [CDK_DRAG_PARENT]
3681
+ }] }];
3682
+ }, propDecorators: { _handles: [{
3683
+ type: ContentChildren,
3684
+ args: [CDK_DRAG_HANDLE, { descendants: true }]
3685
+ }], _previewTemplate: [{
3686
+ type: ContentChild,
3687
+ args: [CDK_DRAG_PREVIEW]
3688
+ }], _placeholderTemplate: [{
3689
+ type: ContentChild,
3690
+ args: [CDK_DRAG_PLACEHOLDER]
3691
+ }], data: [{
3692
+ type: Input,
3693
+ args: ['cdkDragData']
3694
+ }], lockAxis: [{
3695
+ type: Input,
3696
+ args: ['cdkDragLockAxis']
3697
+ }], rootElementSelector: [{
3698
+ type: Input,
3699
+ args: ['cdkDragRootElement']
3700
+ }], boundaryElement: [{
3701
+ type: Input,
3702
+ args: ['cdkDragBoundary']
3703
+ }], dragStartDelay: [{
3704
+ type: Input,
3705
+ args: ['cdkDragStartDelay']
3706
+ }], freeDragPosition: [{
3707
+ type: Input,
3708
+ args: ['cdkDragFreeDragPosition']
3709
+ }], disabled: [{
3710
+ type: Input,
3711
+ args: ['cdkDragDisabled']
3712
+ }], constrainPosition: [{
3713
+ type: Input,
3714
+ args: ['cdkDragConstrainPosition']
3715
+ }], previewClass: [{
3716
+ type: Input,
3717
+ args: ['cdkDragPreviewClass']
3718
+ }], previewContainer: [{
3719
+ type: Input,
3720
+ args: ['cdkDragPreviewContainer']
3721
+ }], started: [{
3722
+ type: Output,
3723
+ args: ['cdkDragStarted']
3724
+ }], released: [{
3725
+ type: Output,
3726
+ args: ['cdkDragReleased']
3727
+ }], ended: [{
3728
+ type: Output,
3729
+ args: ['cdkDragEnded']
3730
+ }], entered: [{
3731
+ type: Output,
3732
+ args: ['cdkDragEntered']
3733
+ }], exited: [{
3734
+ type: Output,
3735
+ args: ['cdkDragExited']
3736
+ }], dropped: [{
3737
+ type: Output,
3738
+ args: ['cdkDragDropped']
3739
+ }], moved: [{
3740
+ type: Output,
3741
+ args: ['cdkDragMoved']
3742
+ }] } });
3743
+
3744
+ /**
3745
+ * @license
3746
+ * Copyright Google LLC All Rights Reserved.
3747
+ *
3748
+ * Use of this source code is governed by an MIT-style license that can be
3749
+ * found in the LICENSE file at https://angular.io/license
3750
+ */
3751
+ class DragDropModule {
3752
+ }
3753
+ DragDropModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: DragDropModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
3754
+ DragDropModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.2.0", ngImport: i0, type: DragDropModule, declarations: [CdkDropList,
3755
+ CdkDropListGroup,
3756
+ CdkDrag,
3757
+ CdkDragHandle,
3758
+ CdkDragPreview,
3759
+ CdkDragPlaceholder], exports: [CdkScrollableModule,
3760
+ CdkDropList,
3761
+ CdkDropListGroup,
3762
+ CdkDrag,
3763
+ CdkDragHandle,
3764
+ CdkDragPreview,
3765
+ CdkDragPlaceholder] });
3766
+ DragDropModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: DragDropModule, providers: [DragDrop], imports: [CdkScrollableModule] });
3767
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: DragDropModule, decorators: [{
3768
+ type: NgModule,
3769
+ args: [{
3770
+ declarations: [
3771
+ CdkDropList,
3772
+ CdkDropListGroup,
3773
+ CdkDrag,
3774
+ CdkDragHandle,
3775
+ CdkDragPreview,
3776
+ CdkDragPlaceholder,
3777
+ ],
3778
+ exports: [
3779
+ CdkScrollableModule,
3780
+ CdkDropList,
3781
+ CdkDropListGroup,
3782
+ CdkDrag,
3783
+ CdkDragHandle,
3784
+ CdkDragPreview,
3785
+ CdkDragPlaceholder,
3786
+ ],
3787
+ providers: [DragDrop],
3788
+ }]
3789
+ }] });
3790
+
3791
+ /**
3792
+ * @license
3793
+ * Copyright Google LLC All Rights Reserved.
3794
+ *
3795
+ * Use of this source code is governed by an MIT-style license that can be
3796
+ * found in the LICENSE file at https://angular.io/license
3797
+ */
3798
+
3799
+ /**
3800
+ * @license
3801
+ * Copyright Google LLC All Rights Reserved.
3802
+ *
3803
+ * Use of this source code is governed by an MIT-style license that can be
3804
+ * found in the LICENSE file at https://angular.io/license
3805
+ */
3806
+
3807
+ /**
3808
+ * Generated bundle index. Do not edit.
3809
+ */
3810
+
3811
+ export { CDK_DRAG_CONFIG, CDK_DRAG_HANDLE, CDK_DRAG_PARENT, CDK_DRAG_PLACEHOLDER, CDK_DRAG_PREVIEW, CDK_DROP_LIST, CDK_DROP_LIST_GROUP, CdkDrag, CdkDragHandle, CdkDragPlaceholder, CdkDragPreview, CdkDropList, CdkDropListGroup, DragDrop, DragDropModule, DragDropRegistry, DragRef, DropListRef, copyArrayItem, moveItemInArray, transferArrayItem };
3812
+ //# sourceMappingURL=drag-drop.mjs.map