aboutsummaryrefslogtreecommitdiff
path: root/src/client/util/SnappingManager.ts
blob: 715eb021fedc24dfb18ccbf08f4df5e86c39c4fb (plain)
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
62
63
64
65
66
67
68
import { observable, action, runInAction } from 'mobx';
import { Doc } from '../../fields/Doc';

export namespace SnappingManager {
    class Manager {
        @observable ShiftKey = false;
        @observable CtrlKey = false;
        @observable IsDragging: boolean = false;
        @observable IsResizing: Doc | undefined = undefined;
        @observable CanEmbed: boolean = false;
        @observable public horizSnapLines: number[] = [];
        @observable public vertSnapLines: number[] = [];
        @action public clearSnapLines() {
            this.vertSnapLines = [];
            this.horizSnapLines = [];
        }
        @action public addSnapLines(horizLines: number[], vertLines: number[]) {
            this.horizSnapLines.push(...horizLines);
            this.vertSnapLines.push(...vertLines);
        }
    }

    const manager = new Manager();

    export function clearSnapLines() {
        manager.clearSnapLines();
    }
    export function addSnapLines(horizLines: number[], vertLines: number[]) {
        manager.addSnapLines(horizLines, vertLines);
    }
    export function horizSnapLines() {
        return manager.horizSnapLines;
    }
    export function vertSnapLines() {
        return manager.vertSnapLines;
    }

    export function SetShiftKey(down: boolean) {
        runInAction(() => (manager.ShiftKey = down));
    }
    export function SetCtrlKey(down: boolean) {
        runInAction(() => (manager.CtrlKey = down));
    }
    export function SetIsDragging(dragging: boolean) {
        runInAction(() => (manager.IsDragging = dragging));
    }
    export function SetIsResizing(doc: Doc | undefined) {
        runInAction(() => (manager.IsResizing = doc));
    }
    export function SetCanEmbed(canEmbed: boolean) {
        runInAction(() => (manager.CanEmbed = canEmbed));
    }
    export function GetShiftKey() {
        return manager.ShiftKey;
    }
    export function GetCtrlKey() {
        return manager.CtrlKey;
    }
    export function GetIsDragging() {
        return manager.IsDragging;
    }
    export function GetIsResizing() {
        return manager.IsResizing;
    }
    export function GetCanEmbed() {
        return manager.CanEmbed;
    }
}