aboutsummaryrefslogtreecommitdiff
path: root/src/client/util/SnappingManager.ts
blob: 1337d271f7bf9e1fce3ea2e73d89a45d10f42fe6 (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
69
70
71
72
73
74
75
76
77
78
79
80
import { observable, action, runInAction, makeObservable } from 'mobx';

export enum freeformScrollMode {
    Pan = 'pan',
    Zoom = 'zoom',
}
export class SnappingManager {
    // eslint-disable-next-line no-use-before-define
    private static _manager: SnappingManager;
    private static get Instance() {
        return SnappingManager._manager ?? new SnappingManager();
    }

    @observable _shiftKey = false;
    @observable _ctrlKey = false;
    @observable _metaKey = false;
    @observable _showPresPaths = false;
    @observable _isLinkFollowing = false;
    @observable _isDragging: boolean = false;
    @observable _isResizing: string | undefined = undefined; // the string is the Id of the document being resized
    @observable _canEmbed: boolean = false;
    @observable _horizSnapLines: number[] = [];
    @observable _vertSnapLines: number[] = [];
    @observable _exploreMode = false;
    @observable _userPanned = false;
    @observable _serverVersion: string = '';
    @observable _lastBtnId: string = '';
    @observable _propertyWid: number = 0;
    @observable _printToConsole: boolean = false;

    private constructor() {
        SnappingManager._manager = this;
        makeObservable(this);
    }

    @action public static clearSnapLines = () => {
        this.Instance._vertSnapLines.length = this.Instance._horizSnapLines.length = 0;
    };
    @action public static addSnapLines = (horizLines: number[], vertLines: number[]) => {
        this.Instance._horizSnapLines.push(...horizLines);
        this.Instance._vertSnapLines.push(...vertLines);
    };

    public static get HorizSnapLines() { return this.Instance._horizSnapLines; } // prettier-ignore
    public static get VertSnapLines()  { return this.Instance._vertSnapLines; } // prettier-ignore
    public static get ShiftKey()       { return this.Instance._shiftKey; } // prettier-ignore
    public static get CtrlKey()        { return this.Instance._ctrlKey; } // prettier-ignore
    public static get MetaKey()        { return this.Instance._metaKey; } // prettier-ignore
    public static get ShowPresPaths()  { return this.Instance._showPresPaths; } // prettier-ignore
    public static get IsLinkFollowing(){ return this.Instance._isLinkFollowing; } // prettier-ignore
    public static get IsDragging()     { return this.Instance._isDragging; } // prettier-ignore
    public static get IsResizing()     { return this.Instance._isResizing; } // prettier-ignore
    public static get CanEmbed()       { return this.Instance._canEmbed; } // prettier-ignore
    public static get ExploreMode()    { return this.Instance._exploreMode; } // prettier-ignore
    public static get UserPanned()     { return this.Instance._userPanned; } // prettier-ignore
    public static get ServerVersion()  { return this.Instance._serverVersion; } // prettier-ignore
    public static get LastPressedBtn() { return this.Instance._lastBtnId; } // prettier-ignore
    public static get PropertiesWidth(){ return this.Instance._propertyWid; } // prettier-ignore
    public static get PrintToConsole() { return this.Instance._printToConsole; } // prettier-ignore

    public static SetShiftKey       = (down: boolean) => runInAction(() => {this.Instance._shiftKey = down}); // prettier-ignore
    public static SetCtrlKey        = (down: boolean) => runInAction(() => {this.Instance._ctrlKey = down}); // prettier-ignore
    public static SetMetaKey        = (down: boolean) => runInAction(() => {this.Instance._metaKey = down}); // prettier-ignore
    public static SetShowPresPaths  = (paths:boolean) => runInAction(() => {this.Instance._showPresPaths = paths}); // prettier-ignore
    public static SetIsLinkFollowing= (follow:boolean)=> runInAction(() => {this.Instance._isLinkFollowing = follow}); // prettier-ignore
    public static SetIsDragging     = (drag: boolean) => runInAction(() => {this.Instance._isDragging = drag}); // prettier-ignore
    public static SetIsResizing     = (docid?:string) => runInAction(() => {this.Instance._isResizing = docid}); // prettier-ignore
    public static SetCanEmbed       = (embed:boolean) => runInAction(() => {this.Instance._canEmbed = embed}); // prettier-ignore
    public static SetExploreMode    = (state:boolean) => runInAction(() => {this.Instance._exploreMode = state}); // prettier-ignore
    public static TriggerUserPanned = ()              => runInAction(() => {this.Instance._userPanned = !this.Instance._userPanned}); // prettier-ignore
    public static SetServerVersion  = (version:string) =>runInAction(() => {this.Instance._serverVersion = version}); // prettier-ignore
    public static SetLastPressedBtn = (id:string)      =>runInAction(() => {this.Instance._lastBtnId = id}); // prettier-ignore
    public static SetPropertiesWidth= (wid:number)     =>runInAction(() => {this.Instance._propertyWid = wid}); // prettier-ignore
    public static SetPrintToConsole = (state:boolean)  =>runInAction(() => {this.Instance._printToConsole = state}); // prettier-ignore

    public static userColor: string | undefined;
    public static userVariantColor: string | undefined;
    public static userBackgroundColor: string | undefined;
    public static SettingsStyle: any;
}