import { Directive , ElementRef , HostListener } from '@angular/core' ; import { DndState , DndDraggableConfig , DndStateConfig , } from '../services' ; @ Directive ( { selector : '[dndNoDrag]' , } ) export class DndNoDrag { private readonly dragState : DndStateConfig ; private nativeElement : HTMLElement ; private draggableString : string = 'draggable' ; constructor ( readonly element , readonly dndState ) { this . dragState = dndState . dragState ; this . nativeElement = element . nativeElement ; this . nativeElement . setAttribute ( this . draggableString , 'true' ) ; } @ HostListener ( 'dragstart' , [ '$event' ] ) public handleDragStart ( event ) { event = event [ 'originalEvent' ] || event ; if ( ! event [ '_dndHandle' ] ) { if ( ! ( event . dataTransfer . types && event . dataTransfer . types . length ) ) { event . preventDefault ( ) ; } event . stopPropagation ( ) ; } } @ HostListener ( 'dragend' , [ '$event' ] ) public handleDragEnd ( event ) { event = event [ 'originalEvent' ] || event ; if ( ! event [ '_dndHandle' ] ) { event . stopPropagation ( ) ; } } }