@angular/cdk 19.2.13 → 19.2.15

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