aboutsummaryrefslogtreecommitdiff
path: root/src/client/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/util')
-rw-r--r--src/client/util/DragManager.ts34
-rw-r--r--src/client/util/SelectionManager.ts3
-rw-r--r--src/client/util/SnappingManager.ts29
3 files changed, 43 insertions, 23 deletions
diff --git a/src/client/util/DragManager.ts b/src/client/util/DragManager.ts
index 348aba588..0d208cf1b 100644
--- a/src/client/util/DragManager.ts
+++ b/src/client/util/DragManager.ts
@@ -11,6 +11,7 @@ import { emptyFunction } from "../../Utils";
import { Docs, DocUtils } from "../documents/Documents";
import * as globalCssVariables from "../views/globalCssVariables.scss";
import { UndoManager } from "./UndoManager";
+import { SnappingManager } from "./SnappingManager";
export type dropActionType = "alias" | "copy" | "move" | undefined; // undefined = move
export function SetupDrag(
@@ -49,7 +50,7 @@ export function SetupDrag(
if (e.shiftKey) {
e.persist();
const dragDoc = await docFunc();
- dragDoc && DragManager.Vals.Instance.StartWindowDrag?.({
+ dragDoc && DragManager.StartWindowDrag?.({
pageX: e.pageX,
pageY: e.pageY,
preventDefault: emptyFunction,
@@ -66,19 +67,7 @@ export function SetupDrag(
export namespace DragManager {
let dragDiv: HTMLDivElement;
- export class Vals {
- static Instance: Vals = new Vals();
- @observable public IsDragging: boolean = false;
- @observable public horizSnapLines: number[] = [];
- @observable public vertSnapLines: number[] = [];
- public StartWindowDrag: Opt<((e: any, dragDocs: Doc[]) => void)> = undefined;
- public SetIsDragging(dragging: boolean) { runInAction(() => this.IsDragging = dragging); }
- public GetIsDragging() { return this.IsDragging; }
- @action public clearSnapLines() {
- this.vertSnapLines.length = 0;
- this.horizSnapLines.length = 0;
- }
- }
+ export let StartWindowDrag: Opt<((e: any, dragDocs: Doc[]) => void)> = undefined;
export function Root() {
const root = document.getElementById("root");
@@ -267,8 +256,7 @@ export namespace DragManager {
}
export function SetSnapLines(horizLines: number[], vertLines: number[]) {
- DragManager.Vals.Instance.horizSnapLines.push(...horizLines);
- DragManager.Vals.Instance.vertSnapLines.push(...vertLines);
+ SnappingManager.setSnapLines(horizLines, vertLines);
}
export function snapDrag(e: PointerEvent, xFromLeft: number, yFromTop: number, xFromRight: number, yFromBottom: number) {
@@ -286,8 +274,8 @@ export namespace DragManager {
};
return {
- thisX: snapVal([xFromLeft, xFromRight], e.pageX, DragManager.Vals.Instance.vertSnapLines),
- thisY: snapVal([yFromTop, yFromBottom], e.pageY, DragManager.Vals.Instance.horizSnapLines)
+ thisX: snapVal([xFromLeft, xFromRight], e.pageX, SnappingManager.vertSnapLines()),
+ thisY: snapVal([yFromTop, yFromBottom], e.pageY, SnappingManager.horizSnapLines())
};
}
export let docsBeingDragged: Doc[] = [];
@@ -299,7 +287,7 @@ export namespace DragManager {
dragDiv.style.pointerEvents = "none";
DragManager.Root().appendChild(dragDiv);
}
- DragManager.Vals.Instance.SetIsDragging(true);
+ SnappingManager.SetIsDragging(true);
const scaleXs: number[] = [];
const scaleYs: number[] = [];
const xs: number[] = [];
@@ -388,7 +376,7 @@ export namespace DragManager {
}
AbortDrag();
finishDrag?.(new DragCompleteEvent(true, dragData));
- DragManager.Vals.Instance.StartWindowDrag?.({
+ DragManager.StartWindowDrag?.({
pageX: e.pageX,
pageY: e.pageY,
preventDefault: emptyFunction,
@@ -415,19 +403,19 @@ export namespace DragManager {
const endDrag = action(() => {
document.removeEventListener("pointermove", moveHandler, true);
document.removeEventListener("pointerup", upHandler);
- DragManager.Vals.Instance.clearSnapLines();
+ SnappingManager.clearSnapLines();
});
AbortDrag = () => {
hideDragShowOriginalElements();
- DragManager.Vals.Instance.SetIsDragging(false);
+ SnappingManager.SetIsDragging(false);
options?.dragComplete?.(new DragCompleteEvent(true, dragData));
endDrag();
};
const upHandler = (e: PointerEvent) => {
hideDragShowOriginalElements();
dispatchDrag(eles, e, dragData, xFromLeft, yFromTop, xFromRight, yFromBottom, options, finishDrag);
- DragManager.Vals.Instance.SetIsDragging(false);
+ SnappingManager.SetIsDragging(false);
endDrag();
options?.dragComplete?.(new DragCompleteEvent(false, dragData));
};
diff --git a/src/client/util/SelectionManager.ts b/src/client/util/SelectionManager.ts
index d509168b6..11d2cafb2 100644
--- a/src/client/util/SelectionManager.ts
+++ b/src/client/util/SelectionManager.ts
@@ -8,6 +8,7 @@ export namespace SelectionManager {
class Manager {
+ @observable IsDragging: boolean = false;
SelectedDocuments: ObservableMap<DocumentView, boolean> = new ObservableMap();
@action
@@ -53,6 +54,8 @@ export namespace SelectionManager {
manager.SelectDoc(docView, ctrlPressed);
}
+ export function SetIsDragging(dragging: boolean) { runInAction(() => manager.IsDragging = dragging); }
+ export function GetIsDragging() { return manager.IsDragging; }
// computed functions, such as used in IsSelected generate errors if they're called outside of a
// reaction context. Specifying the context with 'outsideReaction' allows an efficiency feature
// to avoid unnecessary mobx invalidations when running inside a reaction.
diff --git a/src/client/util/SnappingManager.ts b/src/client/util/SnappingManager.ts
new file mode 100644
index 000000000..fc07e8ab4
--- /dev/null
+++ b/src/client/util/SnappingManager.ts
@@ -0,0 +1,29 @@
+import { observable, action, runInAction } from "mobx";
+
+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;
+ }
+ }
+
+ 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; }
+}
+