aboutsummaryrefslogtreecommitdiff
path: root/src/client/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/util')
-rw-r--r--src/client/util/CaptureManager.tsx2
-rw-r--r--src/client/util/DictationManager.ts2
-rw-r--r--src/client/util/DragManager.ts4
-rw-r--r--src/client/util/HypothesisUtils.ts2
-rw-r--r--src/client/util/SelectionManager.ts124
-rw-r--r--src/client/util/SharingManager.tsx8
-rw-r--r--src/client/util/SnappingManager.ts28
7 files changed, 76 insertions, 94 deletions
diff --git a/src/client/util/CaptureManager.tsx b/src/client/util/CaptureManager.tsx
index 8a4f37121..271cf7495 100644
--- a/src/client/util/CaptureManager.tsx
+++ b/src/client/util/CaptureManager.tsx
@@ -81,7 +81,7 @@ export class CaptureManager extends React.Component<{}> {
<div
className="cancel"
onClick={() => {
- const selected = SelectionManager.Views().slice();
+ const selected = SelectionManager.Views.slice();
SelectionManager.DeselectAll();
selected.map(dv => dv.props.removeDocument?.(dv.props.Document));
this.close();
diff --git a/src/client/util/DictationManager.ts b/src/client/util/DictationManager.ts
index 0fd7e840c..039bb360e 100644
--- a/src/client/util/DictationManager.ts
+++ b/src/client/util/DictationManager.ts
@@ -236,7 +236,7 @@ export namespace DictationManager {
export const execute = async (phrase: string) => {
return UndoManager.RunInBatch(async () => {
console.log('PHRASE: ' + phrase);
- const targets = SelectionManager.Views();
+ const targets = SelectionManager.Views;
if (!targets || !targets.length) {
return;
}
diff --git a/src/client/util/DragManager.ts b/src/client/util/DragManager.ts
index e96bbcaaf..c711db31a 100644
--- a/src/client/util/DragManager.ts
+++ b/src/client/util/DragManager.ts
@@ -618,7 +618,7 @@ export namespace DragManager {
ScriptingGlobals.add(function toggleRaiseOnDrag(readOnly?: boolean) {
if (readOnly) {
- return SelectionManager.Views().some(dv => dv.Document.keepZWhenDragged);
+ return SelectionManager.Views.some(dv => dv.Document.keepZWhenDragged);
}
- SelectionManager.Views().map(dv => (dv.Document.keepZWhenDragged = !dv.Document.keepZWhenDragged));
+ SelectionManager.Views.map(dv => (dv.Document.keepZWhenDragged = !dv.Document.keepZWhenDragged));
});
diff --git a/src/client/util/HypothesisUtils.ts b/src/client/util/HypothesisUtils.ts
index 151f18d6f..990798ed3 100644
--- a/src/client/util/HypothesisUtils.ts
+++ b/src/client/util/HypothesisUtils.ts
@@ -27,7 +27,7 @@ export namespace Hypothesis {
* Search for a WebDocument whose url field matches the given uri, return undefined if not found
*/
export const findWebDoc = async (uri: string) => {
- const currentDoc = SelectionManager.Docs().lastElement();
+ const currentDoc = SelectionManager.Docs.lastElement();
if (currentDoc && Cast(currentDoc.data, WebField)?.url.href === uri) return currentDoc; // always check first whether the currently selected doc is the annotation's source, only use Search otherwise
const results: Doc[] = [];
diff --git a/src/client/util/SelectionManager.ts b/src/client/util/SelectionManager.ts
index b837cdd08..64cced3f1 100644
--- a/src/client/util/SelectionManager.ts
+++ b/src/client/util/SelectionManager.ts
@@ -10,90 +10,72 @@ import { LinkManager } from './LinkManager';
import { ScriptingGlobals } from './ScriptingGlobals';
import { UndoManager } from './UndoManager';
-export namespace SelectionManager {
- class Manager {
- @observable.shallow SelectedViews: DocumentView[] = [];
- @observable IsDragging: boolean = false;
- @observable SelectedSchemaDocument: Doc | undefined = undefined;
-
- constructor() {
- makeObservable(this);
- }
-
- @action
- SelectSchemaViewDoc(doc: Opt<Doc>) {
- manager.SelectedSchemaDocument = doc;
- }
- @action
- SelectView(docView: DocumentView, extendSelection: boolean): void {
- if (!docView.SELECTED) {
- if (!extendSelection) this.DeselectAll();
- manager.SelectedViews.push(docView);
- docView.SELECTED = true;
- docView._props.whenChildContentsActiveChanged(true);
- }
- }
- @action
- DeselectView(docView?: DocumentView): void {
- if (docView && manager.SelectedViews.includes(docView)) {
- docView.SELECTED = false;
- manager.SelectedViews.splice(manager.SelectedViews.indexOf(docView), 1);
- docView._props.whenChildContentsActiveChanged(false);
- }
- }
- @action
- DeselectAll(): void {
- LinkManager.currentLink = undefined;
- LinkManager.currentLinkAnchor = undefined;
- manager.SelectedSchemaDocument = undefined;
- manager.SelectedViews.forEach(dv => {
- dv.SELECTED = false;
- dv._props.whenChildContentsActiveChanged(false);
- });
- manager.SelectedViews.length = 0;
- }
+export class SelectionManager {
+ private static _manager: SelectionManager;
+ private static get Instance() {
+ return SelectionManager._manager ?? new SelectionManager();
}
- const manager = new Manager();
+ @observable.shallow SelectedViews: DocumentView[] = [];
+ @observable IsDragging: boolean = false;
+ @observable SelectedSchemaDocument: Doc | undefined = undefined;
- export function DeselectView(docView?: DocumentView): void {
- manager.DeselectView(docView);
- }
- export function SelectView(docView: DocumentView | undefined, ctrlPressed: boolean): void {
- if (!docView) DeselectAll();
- else manager.SelectView(docView, ctrlPressed);
- }
- export function SelectSchemaViewDoc(document: Opt<Doc>, deselectAllFirst?: boolean): void {
- if (deselectAllFirst) manager.DeselectAll();
- manager.SelectSchemaViewDoc(document);
+ private constructor() {
+ SelectionManager._manager = this;
+ makeObservable(this);
}
- export function IsSelected(doc?: Doc): boolean {
- return Array.from(doc?.[DocViews] ?? []).some(dv => dv?.SELECTED);
+ @action
+ public static SelectSchemaViewDoc(doc: Opt<Doc>, deselectAllFirst?: boolean) {
+ if (deselectAllFirst) this.DeselectAll();
+ else this.Instance.SelectedSchemaDocument = doc;
}
- export function DeselectAll(except?: Doc): void {
- const found = manager.SelectedViews.find(dv => dv.Document === except);
- manager.DeselectAll();
- if (found) manager.SelectView(found, false);
+ @action
+ public static SelectView(docView: DocumentView, extendSelection: boolean): void {
+ if (!docView) this.DeselectAll();
+ else if (!docView.SELECTED) {
+ if (!extendSelection) this.DeselectAll();
+ this.Instance.SelectedViews.push(docView);
+ docView.SELECTED = true;
+ docView._props.whenChildContentsActiveChanged(true);
+ }
}
- export function Views(): Array<DocumentView> {
- return manager.SelectedViews;
- }
- export function SelectedSchemaDoc(): Doc | undefined {
- return manager.SelectedSchemaDocument;
+ @action
+ public static DeselectView(docView?: DocumentView): void {
+ if (docView && this.Instance.SelectedViews.includes(docView)) {
+ docView.SELECTED = false;
+ this.Instance.SelectedViews.splice(this.Instance.SelectedViews.indexOf(docView), 1);
+ docView._props.whenChildContentsActiveChanged(false);
+ }
}
- export function Docs(): Doc[] {
- return manager.SelectedViews.map(dv => dv.Document).filter(doc => doc?._type_collection !== CollectionViewType.Docking);
+ @action
+ public static DeselectAll(except?: Doc): void {
+ const found = this.Instance.SelectedViews.find(dv => dv.Document === except);
+ LinkManager.currentLink = undefined;
+ LinkManager.currentLinkAnchor = undefined;
+ this.Instance.SelectedSchemaDocument = undefined;
+ this.Instance.SelectedViews.forEach(dv => {
+ dv.SELECTED = false;
+ dv._props.whenChildContentsActiveChanged(false);
+ });
+ this.Instance.SelectedViews.length = 0;
+ if (found) this.SelectView(found, false);
}
+
+ public static IsSelected = (doc?: Doc) => Array.from(doc?.[DocViews] ?? []).some(dv => dv?.SELECTED);
+ public static get Views() { return this.Instance.SelectedViews; } // prettier-ignore
+ public static get SelectedSchemaDoc() { return this.Instance.SelectedSchemaDocument; } // prettier-ignore
+ public static get Docs() { return this.Instance.SelectedViews.map(dv => dv.Document).filter(doc => doc?._type_collection !== CollectionViewType.Docking); } // prettier-ignore
}
+
ScriptingGlobals.add(function SelectionManager_selectedDocType(type: string, expertMode: boolean, checkContext?: boolean) {
if (Doc.noviceMode && expertMode) return false;
if (type === 'tab') {
- return SelectionManager.Views().lastElement()?._props.renderDepth === 0;
+ return SelectionManager.Views.lastElement()?._props.renderDepth === 0;
}
- let selected = (sel => (checkContext ? DocCast(sel?.embedContainer) : sel))(SelectionManager.SelectedSchemaDoc() ?? SelectionManager.Docs().lastElement());
+ let selected = (sel => (checkContext ? DocCast(sel?.embedContainer) : sel))(SelectionManager.SelectedSchemaDoc ?? SelectionManager.Docs.lastElement());
return selected?.type === type || selected?.type_collection === type || !type;
});
ScriptingGlobals.add(function deselectAll() {
@@ -118,8 +100,8 @@ ScriptingGlobals.add(function redo() {
return UndoManager.Redo();
});
ScriptingGlobals.add(function selectedDocs(container: Doc, excludeCollections: boolean, prevValue: any) {
- const docs = SelectionManager.Views()
- .map(dv => dv.Document)
- .filter(d => !Doc.AreProtosEqual(d, container) && !d.annotationOn && d.type !== DocumentType.KVP && (!excludeCollections || d.type !== DocumentType.COL || !Cast(d.data, listSpec(Doc), null)));
+ const docs = SelectionManager.Views.map(dv => dv.Document).filter(
+ d => !Doc.AreProtosEqual(d, container) && !d.annotationOn && d.type !== DocumentType.KVP && (!excludeCollections || d.type !== DocumentType.COL || !Cast(d.data, listSpec(Doc), null))
+ );
return docs.length ? new List(docs) : prevValue;
});
diff --git a/src/client/util/SharingManager.tsx b/src/client/util/SharingManager.tsx
index a46c6363e..7176b568e 100644
--- a/src/client/util/SharingManager.tsx
+++ b/src/client/util/SharingManager.tsx
@@ -162,7 +162,7 @@ export class SharingManager extends React.Component<{}> {
const { user, sharingDoc } = recipient;
const target = targetDoc || this.targetDoc!;
const acl = `acl-${normalizeEmail(user.email)}`;
- const docs = SelectionManager.Views().length < 2 ? [target] : SelectionManager.Views().map(docView => docView.Document);
+ const docs = SelectionManager.Views.length < 2 ? [target] : SelectionManager.Views.map(docView => docView.Document);
docs.map(doc => (this.layoutDocAcls || doc.dockingConfig ? doc : Doc.GetProto(doc))).forEach(doc => {
distributeAcls(acl, permission as SharingPermissions, doc, undefined, this.upgradeNested ? true : undefined);
if (permission !== SharingPermissions.None) {
@@ -180,7 +180,7 @@ export class SharingManager extends React.Component<{}> {
const target = targetDoc || this.targetDoc!;
const acl = `acl-${normalizeEmail(StrCast(group.title))}`;
- const docs = SelectionManager.Views().length < 2 ? [target] : SelectionManager.Views().map(docView => docView.Document);
+ const docs = SelectionManager.Views.length < 2 ? [target] : SelectionManager.Views.map(docView => docView.Document);
docs.map(doc => (this.layoutDocAcls || doc.dockingConfig ? doc : Doc.GetProto(doc))).forEach(doc => {
distributeAcls(acl, permission as SharingPermissions, doc, undefined, this.upgradeNested ? true : undefined);
@@ -317,7 +317,7 @@ export class SharingManager extends React.Component<{}> {
private focusOn = (contents: string) => {
const title = this.targetDoc ? StrCast(this.targetDoc.title) : '';
- const docs = SelectionManager.Views().length > 1 ? SelectionManager.Views().map(docView => docView.props.Document) : [this.targetDoc];
+ const docs = SelectionManager.Views.length > 1 ? SelectionManager.Views.map(docView => docView.props.Document) : [this.targetDoc];
return (
<span
className="focus-span"
@@ -444,7 +444,7 @@ export class SharingManager extends React.Component<{}> {
const users = this.individualSort === 'ascending' ? this.users.slice().sort(this.sortUsers) : this.individualSort === 'descending' ? this.users.slice().sort(this.sortUsers).reverse() : this.users;
const groups = this.groupSort === 'ascending' ? groupList.slice().sort(this.sortGroups) : this.groupSort === 'descending' ? groupList.slice().sort(this.sortGroups).reverse() : groupList;
- let docs = SelectionManager.Views().length < 2 ? [this.targetDoc] : SelectionManager.Views().map(docView => docView.Document);
+ let docs = SelectionManager.Views.length < 2 ? [this.targetDoc] : SelectionManager.Views.map(docView => docView.Document);
if (this.myDocAcls) {
const newDocs: Doc[] = [];
diff --git a/src/client/util/SnappingManager.ts b/src/client/util/SnappingManager.ts
index 44c6aad52..48ec61f85 100644
--- a/src/client/util/SnappingManager.ts
+++ b/src/client/util/SnappingManager.ts
@@ -2,7 +2,7 @@ import { observable, action, runInAction, reaction, makeObservable } from 'mobx'
import { Doc } from '../../fields/Doc';
export class SnappingManager {
- static _manager: SnappingManager;
+ private static _manager: SnappingManager;
private static get Instance() {
return SnappingManager._manager ?? new SnappingManager();
}
@@ -15,7 +15,7 @@ export class SnappingManager {
@observable _horizSnapLines: number[] = [];
@observable _vertSnapLines: number[] = [];
- constructor() {
+ private constructor() {
SnappingManager._manager = this;
makeObservable(this);
}
@@ -26,16 +26,16 @@ export class SnappingManager {
this.Instance._vertSnapLines.push(...vertLines);
};
- public static get HorizSnapLines() { return SnappingManager.Instance._horizSnapLines; } // prettier-ignore
- public static get VertSnapLines() { return SnappingManager.Instance._vertSnapLines; } // prettier-ignore
- public static get ShiftKey() { return SnappingManager.Instance._shiftKey; } // prettier-ignore
- public static get CtrlKey() { return SnappingManager.Instance._ctrlKey; } // prettier-ignore
- public static get IsDragging() { return SnappingManager.Instance._isDragging; } // prettier-ignore
- public static get IsResizing() { return SnappingManager.Instance._isResizing; } // prettier-ignore
- public static get CanEmbed() { return SnappingManager.Instance._canEmbed; } // prettier-ignore
- public static SetShiftKey = (down: boolean) => runInAction(() => (SnappingManager.Instance._shiftKey = down));
- public static SetCtrlKey = (down: boolean) => runInAction(() => (SnappingManager.Instance._ctrlKey = down));
- public static SetIsDragging = (dragging: boolean) => runInAction(() => (SnappingManager.Instance._isDragging = dragging));
- public static SetIsResizing = (doc: Doc | undefined) => runInAction(() => (SnappingManager.Instance._isResizing = doc));
- public static SetCanEmbed = (canEmbed: boolean) => runInAction(() => (SnappingManager.Instance._canEmbed = canEmbed));
+ 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 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 SetShiftKey = (down: boolean) => runInAction(() => (this.Instance._shiftKey = down));
+ public static SetCtrlKey = (down: boolean) => runInAction(() => (this.Instance._ctrlKey = down));
+ public static SetIsDragging = (dragging: boolean) => runInAction(() => (this.Instance._isDragging = dragging));
+ public static SetIsResizing = (doc: Doc | undefined) => runInAction(() => (this.Instance._isResizing = doc));
+ public static SetCanEmbed = (canEmbed: boolean) => runInAction(() => (this.Instance._canEmbed = canEmbed));
}