aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/collections
diff options
context:
space:
mode:
authorAubrey Li <Aubrey-Li>2022-04-12 19:21:53 -0400
committerAubrey Li <Aubrey-Li>2022-04-12 19:21:53 -0400
commit98567999b9882ed093bb0d750504a1bd10aa9a94 (patch)
treecff66787e66c93a4b9096c3d6714701f8978fd7d /src/client/views/collections
parent4cb2fc6f0a173939b5ee51ff2d6548058799facd (diff)
revert presbox & treeview onclick focus
Diffstat (limited to 'src/client/views/collections')
-rw-r--r--src/client/views/collections/TreeView.tsx94
1 files changed, 90 insertions, 4 deletions
diff --git a/src/client/views/collections/TreeView.tsx b/src/client/views/collections/TreeView.tsx
index ff5c4bab1..751ae631b 100644
--- a/src/client/views/collections/TreeView.tsx
+++ b/src/client/views/collections/TreeView.tsx
@@ -1,5 +1,5 @@
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
-import { action, computed, IReactionDisposer, observable, reaction } from "mobx";
+import { action, computed, IReactionDisposer, observable, ObservableMap, reaction, runInAction } from "mobx";
import { observer } from "mobx-react";
import { DataSym, Doc, DocListCast, DocListCastOrNull, Field, HeightSym, Opt, WidthSym, StrListCast } from '../../../fields/Doc';
import { Id } from '../../../fields/FieldSymbols';
@@ -13,7 +13,7 @@ import { emptyFunction, returnEmptyDoclist, returnEmptyFilter, returnEmptyString
import { Docs, DocUtils } from '../../documents/Documents';
import { DocumentType } from "../../documents/DocumentTypes";
import { CurrentUserUtils } from '../../util/CurrentUserUtils';
-import { DocumentManager } from '../../util/DocumentManager';
+import { DocumentManager, DocFocusOrOpen } from '../../util/DocumentManager';
import { DragManager, dropActionType } from "../../util/DragManager";
import { SelectionManager } from '../../util/SelectionManager';
import { SnappingManager } from '../../util/SnappingManager';
@@ -31,6 +31,8 @@ import { CollectionTreeView } from './CollectionTreeView';
import { CollectionView, CollectionViewType } from './CollectionView';
import "./TreeView.scss";
import React = require("react");
+import { PresMovement } from '../nodes/trails/PresEnums';
+import { PresBox } from '../nodes/trails';
export interface TreeViewProps {
treeView: CollectionTreeView;
@@ -112,13 +114,24 @@ export class TreeView extends React.Component<TreeViewProps> {
@computed get dataDoc() { return this.doc[DataSym]; }
@computed get layoutDoc() { return Doc.Layout(this.doc); }
@computed get fieldKey() { return Doc.LayoutFieldKey(this.doc); }
- @computed get childDocs() { return this.childDocList(this.fieldKey); }
+ // @computed get childDocs() { return this.childDocList(this.fieldKey); }
+ @computed get childDocs() { return DocListCast(this.dataDoc[this.fieldKey]); }
@computed get childLinks() { return this.childDocList("links"); }
@computed get childAliases() { return this.childDocList("aliases"); }
@computed get childAnnos() { return this.childDocList(this.fieldKey + "-annotations"); }
@computed get selected() { return SelectionManager.IsSelected(this._docRef); }
// SelectionManager.Views().lastElement()?.props.Document === this.props.document; }
+ @observable _presTimer!: NodeJS.Timeout;
+ @observable _presKeyEventsActive: boolean = false;
+
+ @observable _selectedArray: ObservableMap = new ObservableMap<Doc, any>();
+ // the selected item's index
+ @computed get itemIndex() { return NumCast(this.doc._itemIndex); }
+ // the item that's active
+ @computed get activeItem() { return Cast(this.childDocs[NumCast(this.doc._itemIndex)], Doc, null); }
+ @computed get targetDoc() { return Cast(this.activeItem?.presentationTargetDoc, Doc, null); }
+
childDocList(field: string) {
const layout = Cast(Doc.LayoutField(this.doc), Doc, null);
return (this.props.dataDoc ? DocListCastOrNull(this.props.dataDoc[field]) : undefined) || // if there's a data doc for an expanded template, use it's data field
@@ -546,7 +559,80 @@ export class TreeView extends React.Component<TreeViewProps> {
const icons = StrListCast(this.doc.childContextMenuIcons);
return StrListCast(this.doc.childContextMenuLabels).map((label, i) => ({ script: customScripts[i], filter: customFilters[i], icon: icons[i], label }));
}
- onChildClick = () => this.props.onChildClick?.() ?? (this._editTitleScript?.() || ScriptCast(this.doc.treeChildClick));
+
+ // TODO: currently doc focus works, but can't seem to edit title
+ // onChildClick = () => this.props.onChildClick?.() ?? (this._editTitleScript?.() || ScriptCast(this.doc.treeChildClick));
+ onChildClick = () => {
+ return this.props.onChildClick?.() ?? (ScriptField.MakeFunction(`DocFocusOrOpen(self)`)! || this._editTitleScript?.())
+ }
+
+ //Regular click zoom to document on canvas
+ @action
+ selectElement = async (doc: Doc) => {
+ const context = Cast(doc.context, Doc, null);
+ this.gotoDocument(this.childDocs.indexOf(doc), this.activeItem);
+ if (doc.presPinView || doc.presentationTargetDoc === this.layoutDoc.presCollection) setTimeout(() => this.updateCurrentPresentation(context), 0);
+ else this.updateCurrentPresentation(context);
+
+ if (this.activeItem.setPosition &&
+ this.activeItem.y !== undefined &&
+ this.activeItem.x !== undefined &&
+ this.targetDoc.x !== undefined &&
+ this.targetDoc.y !== undefined) {
+ const timer = (ms: number) => new Promise(res => this._presTimer = setTimeout(res, ms));
+ const time = 10;
+ const ydiff = NumCast(this.activeItem.y) - NumCast(this.targetDoc.y);
+ const xdiff = NumCast(this.activeItem.x) - NumCast(this.targetDoc.x);
+
+ for (let i = 0; i < time; i++) {
+ this.targetDoc.x = NumCast(this.targetDoc.x) + xdiff / time;
+ this.targetDoc.y = NumCast(this.targetDoc.y) + ydiff / time;
+ await timer(0.1);
+ }
+ }
+ }
+
+ static keyEventsWrapper = (e: KeyboardEvent) => {
+ PresBox.Instance.keyEvents(e);
+ }
+
+ @action
+ updateCurrentPresentation = (pres?: Doc) => {
+ if (pres) Doc.UserDoc().activePresentation = pres;
+ else Doc.UserDoc().activePresentation = this.doc;
+ document.removeEventListener("keydown", PresBox.keyEventsWrapper, true);
+ document.addEventListener("keydown", PresBox.keyEventsWrapper, true);
+ this._presKeyEventsActive = true;
+ // PresBox.Instance = this;
+ }
+
+ //The function that is called when a document is clicked or reached through next or back.
+ //it'll also execute the necessary actions if presentation is playing.
+ public gotoDocument = action((index: number, from?: Doc, group?: boolean) => {
+ Doc.UnBrushAllDocs();
+ if (index >= 0 && index < this.childDocs.length) {
+ this.doc._itemIndex = index;
+ const activeItem: Doc = this.activeItem;
+ const targetDoc: Doc = this.targetDoc;
+
+ if (targetDoc) {
+ targetDoc && runInAction(() => {
+ if (activeItem.presMovement === PresMovement.Jump) targetDoc.focusSpeed = 0;
+ else targetDoc.focusSpeed = activeItem.presTransition ? activeItem.presTransition : 500;
+ });
+ setTimeout(() => targetDoc.focusSpeed = 500, this.activeItem.presTransition ? NumCast(this.activeItem.presTransition) + 10 : 510);
+ }
+ if (targetDoc?.lastFrame !== undefined) {
+ targetDoc._currentFrame = 0;
+ }
+ if (!group) this._selectedArray.clear();
+ this.childDocs[index] && this._selectedArray.set(this.childDocs[index], undefined); //TODO: needs more work on selected arrayUpdate selected array
+ // if (this.layoutDoc._viewType === "stacking" && !group) this.navigateToElement(this.childDocs[index]); //Handles movement to element only when presTrail is list
+ // this.onHideDocument(); //Handles hide after/before
+ }
+ });
+
+
onChildDoubleClick = () => (!this.props.treeView.outlineMode && this._openScript?.()) || ScriptCast(this.doc.treeChildDoubleClick);