aboutsummaryrefslogtreecommitdiff
path: root/src/client/util/SnappingManager.ts
blob: 057843c6886f0a49a8334983d39b338cfb3e7d99 (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
import { observable, action, runInAction } from "mobx";
import { computedFn } from "mobx-utils";
import { Doc } from "../../fields/Doc";

export namespace SnappingManager {

    class Manager {
        @observable IsDragging: boolean = false;
        @observable public horizSnapLines: number[] = [];
        @observable public vertSnapLines: number[] = [];
        @action public clearSnapLines() {
            this.vertSnapLines = [];
            this.horizSnapLines = [];
        }
        @action public setSnapLines(horizLines: number[], vertLines: number[]) {
            this.horizSnapLines = horizLines;
            this.vertSnapLines = vertLines;
        }

        @observable cachedGroups: string[] = [];
        @action setCachedGroups(groups: string[]) { this.cachedGroups = groups; }
    }

    const manager = new Manager();

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

    export function SetIsDragging(dragging: boolean) { runInAction(() => manager.IsDragging = dragging); }
    export function GetIsDragging() { return manager.IsDragging; }

    export function SetShowSnapLines(show: boolean) { runInAction(() => Doc.UserDoc().showSnapLines = show); }
    export function GetShowSnapLines() { return Doc.UserDoc().showSnapLines; }

    /// bcz; argh!! TODO;   These do not belong here, but there were include order problems with leaving them in util.ts
    // need to investigate further what caused the mobx update problems and move to a better location.
    const getCachedGroupByNameCache = computedFn(function (name: string) { return manager.cachedGroups.includes(name); }, true);
    export function GetCachedGroupByName(name: string) { return getCachedGroupByNameCache(name); }
    export function SetCachedGroups(groups: string[]) { manager.setCachedGroups(groups); }
}