import { SkyhookDndService , DropTargetSpec } from "@angular-skyhook/core" ; import { Subject , Subscription , Observable } from "rxjs" ; import { of , race , empty , never } from "rxjs" ; import { distinctUntilChanged , filter , switchMapTo , delay , takeUntil , take , tap } from "rxjs/operators" ; type Types = string | symbol | ( string | symbol ) [ ] ; export class ActivatedWith { constructor ( public type , public item ) { } } export type ActivatorSpec = DropTargetSpec & { onActivate : ( a : ActivatedWith ) => void ; } ; export function activatorDropTarget ( dnd , types , waitMillis , spec ) { const dt = dnd . dropTarget ( types , { ... spec as DropTargetSpec , hover : monitor => { hoverSubject$ . next ( new ActivatedWith ( monitor . getItemType ( ) , monitor . getItem ( ) ) ) ; spec . hover && spec . hover ( monitor ) ; } } ) ; const startedHovering$ = dt . listen ( m => m . isOver ( ) && m . canDrop ( ) ) . pipe ( distinctUntilChanged ( ) , filter ( isOver => isOver ) ) ; const stoppedHovering$ = dt . listen ( m => m . isOver ( ) ) . pipe ( distinctUntilChanged ( ) , filter ( canDrop => canDrop === false ) ) ; const hoverSubject$ = new Subject < ActivatedWith > ( ) ; const activations$ = startedHovering$ . pipe ( switchMapTo ( hoverSubject$ . pipe ( delay ( waitMillis ) , takeUntil ( stoppedHovering$ ) , take ( 1 ) ) ) ) ; let subsc = activations$ . subscribe ( spec . onActivate ) ; dt . add ( subsc ) ; return dt ; } ;