all files / component/mouse-dragdrop/ mouse-dragdrop.service.ts

95.45% Statements 21/22
100% Branches 0/0
87.5% Functions 7/8
95% Lines 19/20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61                            21× 21× 21× 21× 21×   21× 21× 23× 23× 22×                                                      
/*
 *  @license
 *  Copyright Hôpitaux Universitaires de Genève. All Rights Reserved.
 *
 *  Use of this source code is governed by an Apache-2.0 license that can be
 *  found in the LICENSE file at https://github.com/DSI-HUG/dejajs-components/blob/master/LICENSE
 */
 
/**
 * Dragdrop service for mouse drag and drop
 */
import { Injectable } from '@angular/core';
import { BehaviorSubject ,  Subject } from 'rxjs';
import {filter, tap} from 'rxjs/operators';
import { Position } from '../../common/core/graphics/position';
 
@Injectable()
export class DejaMouseDragDropService {
    private _context = {} as IDragDropContext;
    private _isDragging = false;
    public dragCursor$ = new BehaviorSubject<IDragCursorInfos>(undefined);
    public dropCursor$ = new Subject<IDropCursorInfos>();
    public dragging$ = new BehaviorSubject<boolean>(false);
 
    constructor() {
        this.dragging$.pipe(
            tap((value) => this._isDragging = value),
            filter((value) => !value))
            .subscribe(() => this._context = {});
    }
 
    public get isDragging() {
        return this._isDragging;
    }
 
    public set context(value: IDragDropContext) {
        this._context = value;
    }
 
    public get context() {
        return this._context;
    }
}
 
export interface IDragDropContext {
    [key: string]: any;
}
 
export interface IDropCursorInfos {
    html?: string;
    width?: number;
    height?: number;
    className?: string;
}
 
export interface IDragCursorInfos extends IDropCursorInfos {
    position: Position;
    originalEvent: MouseEvent;
}