66 * found in the LICENSE file at https://angular.dev/license
77 */
88
9- import { Injectable , NgZone , ElementRef , inject , RendererFactory2 , DOCUMENT } from '@angular/core' ;
10-
11- import { ViewportRuler } from '../scrolling' ;
12- import { DragRef , DragRefConfig } from './drag-ref' ;
13- import { DropListRef } from './drop-list-ref' ;
14- import { DragDropRegistry } from './drag-drop-registry' ;
15-
16- /** Default configuration to be used when creating a `DragRef`. */
17- const DEFAULT_CONFIG = {
18- dragStartThreshold : 5 ,
19- pointerDirectionChangeThreshold : 5 ,
20- } ;
9+ import { Injectable , ElementRef , inject , Injector } from '@angular/core' ;
10+ import { createDragRef , DragRef , DragRefConfig } from './drag-ref' ;
11+ import { createDropListRef , DropListRef } from './drop-list-ref' ;
2112
2213/**
2314 * Service that allows for drag-and-drop functionality to be attached to DOM elements.
15+ * @deprecated Use the `createDragRef` or `createDropListRef` function for better tree shaking.
16+ * Will be removed in v23.
17+ * @breaking -change 23.0.0
2418 */
2519@Injectable ( { providedIn : 'root' } )
2620export class DragDrop {
27- private _document = inject ( DOCUMENT ) ;
28- private _ngZone = inject ( NgZone ) ;
29- private _viewportRuler = inject ( ViewportRuler ) ;
30- private _dragDropRegistry = inject ( DragDropRegistry ) ;
31- private _renderer = inject ( RendererFactory2 ) . createRenderer ( null , null ) ;
21+ private _injector = inject ( Injector ) ;
3222
3323 constructor ( ...args : unknown [ ] ) ;
3424 constructor ( ) { }
@@ -37,33 +27,23 @@ export class DragDrop {
3727 * Turns an element into a draggable item.
3828 * @param element Element to which to attach the dragging functionality.
3929 * @param config Object used to configure the dragging behavior.
30+ * @deprecated Use the `createDragRef` function that provides better tree shaking.
31+ * @breaking -change 23.0.0
4032 */
4133 createDrag < T = any > (
4234 element : ElementRef < HTMLElement > | HTMLElement ,
43- config : DragRefConfig = DEFAULT_CONFIG ,
35+ config ? : DragRefConfig ,
4436 ) : DragRef < T > {
45- return new DragRef < T > (
46- element ,
47- config ,
48- this . _document ,
49- this . _ngZone ,
50- this . _viewportRuler ,
51- this . _dragDropRegistry ,
52- this . _renderer ,
53- ) ;
37+ return createDragRef ( this . _injector , element , config ) ;
5438 }
5539
5640 /**
5741 * Turns an element into a drop list.
5842 * @param element Element to which to attach the drop list functionality.
43+ * @deprecated Use the `createDropListRef` function that provides better tree shaking.
44+ * @breaking -change 23.0.0
5945 */
6046 createDropList < T = any > ( element : ElementRef < HTMLElement > | HTMLElement ) : DropListRef < T > {
61- return new DropListRef < T > (
62- element ,
63- this . _dragDropRegistry ,
64- this . _document ,
65- this . _ngZone ,
66- this . _viewportRuler ,
67- ) ;
47+ return createDropListRef ( this . _injector , element ) ;
6848 }
6949}
0 commit comments