import { TagInputComponent } from '../../components/tag-input/tag-input' ; import { TagModel } from '../tag-model' ; import { Injectable } from '@angular/core' ; export declare interface DraggedTag { index : number ; tag : TagModel ; zone : string ; } import { DRAG_AND_DROP_KEY } from '../../core/constants' ; export declare interface State { dragging : boolean ; dropping : boolean ; index : number | undefined ; } export declare type StateProperty = keyof State ; @ Injectable ( ) export class DragProvider { public sender : TagInputComponent ; public receiver : TagInputComponent ; public state : State = { dragging : false , dropping : false , index : undefined } ; name param event param tag public setDraggedItem ( event , tag ) { if ( event && event . dataTransfer ) { event . dataTransfer . setData ( DRAG_AND_DROP_KEY , JSON . stringify ( tag ) ) ; } } name param event public getDraggedItem ( event ) { if ( event && event . dataTransfer ) { const data = event . dataTransfer . getData ( DRAG_AND_DROP_KEY ) ; try { return JSON . parse ( data ) as DraggedTag ; } catch { return ; } } } name param sender public setSender ( sender ) { this . sender = sender ; } name param receiver public setReceiver ( receiver ) { this . receiver = receiver ; } name param tag param indexDragged param indexDropped public onTagDropped ( tag , indexDragged , indexDropped ? ) { this . onDragEnd ( ) ; this . sender . onRemoveRequested ( tag , indexDragged ) ; this . receiver . onAddingRequested ( false , tag , indexDropped ) ; } name param state public setState ( state ) { this . state = { ... this . state , ... state } ; } name param key public getState ( key ? ) { return key ? this . state [ key ] : this . state ; } name public onDragEnd ( ) { this . setState ( { dragging : false , dropping : false , index : undefined } ) ; } }