aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/presentationview/PresElementBox.tsx
diff options
context:
space:
mode:
authorGeireann Lindfield Roberts <60007097+geireann@users.noreply.github.com>2020-10-18 00:56:36 +0800
committerGeireann Lindfield Roberts <60007097+geireann@users.noreply.github.com>2020-10-18 00:56:36 +0800
commitdc58a9b7962c7a2e7916345980fe17a745244231 (patch)
treec2ace02f53ba182c7da1e02a4a3a08f26020d402 /src/client/views/presentationview/PresElementBox.tsx
parent3f5fb2e5dc258312e10698f3223239815959d7b6 (diff)
parent5816840af60f97a34318a52a5276482cab392496 (diff)
Merge branch 'presentation_v1' of https://github.com/browngraphicslab/Dash-Web into presentation_v1
Diffstat (limited to 'src/client/views/presentationview/PresElementBox.tsx')
-rw-r--r--src/client/views/presentationview/PresElementBox.tsx25
1 files changed, 12 insertions, 13 deletions
diff --git a/src/client/views/presentationview/PresElementBox.tsx b/src/client/views/presentationview/PresElementBox.tsx
index 41a8f899c..41a1b5a93 100644
--- a/src/client/views/presentationview/PresElementBox.tsx
+++ b/src/client/views/presentationview/PresElementBox.tsx
@@ -1,5 +1,5 @@
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
-import { action, computed, IReactionDisposer, reaction, runInAction } from "mobx";
+import { action, computed, IReactionDisposer, reaction, runInAction, observable } from "mobx";
import { observer } from "mobx-react";
import { Doc, DataSym, DocListCast } from "../../../fields/Doc";
import { documentSchema } from '../../../fields/documentSchemas';
@@ -8,13 +8,11 @@ import { createSchema, makeInterface, listSpec } from '../../../fields/Schema';
import { Cast, NumCast, BoolCast, ScriptCast, StrCast } from "../../../fields/Types";
import { emptyFunction, emptyPath, returnFalse, returnTrue, returnOne, returnZero, numberRange, setupMoveUpEvents } from "../../../Utils";
import { Transform } from "../../util/Transform";
-import { CollectionViewType } from '../collections/CollectionView';
import { ViewBoxBaseComponent } from '../DocComponent';
import { ContentFittingDocumentView } from '../nodes/ContentFittingDocumentView';
import { FieldView, FieldViewProps } from '../nodes/FieldView';
import "./PresElementBox.scss";
import React = require("react");
-import { CollectionFreeFormDocumentView } from "../nodes/CollectionFreeFormDocumentView";
import { PresBox, PresMovement } from "../nodes/PresBox";
import { DocumentType } from "../../documents/DocumentTypes";
import { Tooltip } from "@material-ui/core";
@@ -47,6 +45,8 @@ const PresDocument = makeInterface(presSchema, documentSchema);
export class PresElementBox extends ViewBoxBaseComponent<FieldViewProps, PresDocument>(PresDocument) {
public static LayoutString(fieldKey: string) { return FieldView.LayoutString(PresElementBox, fieldKey); }
_heightDisposer: IReactionDisposer | undefined;
+
+ @observable _dragging = false;
// these fields are conditionally computed fields on the layout document that take this document as a parameter
@computed get indexInPres() { return Number(this.lookupField("indexInPres")); } // the index field is where this document is in the presBox display list (since this value is different for each presentation element, the value can't be stored on the layout template which is used by all display elements)
@computed get collapsedHeight() { return Number(this.lookupField("presCollapsedHeight")); } // the collapsed height changes depending on the state of the presBox. We could store this on the presentation element template if it's used by only one presentation - but if it's shared by multiple, then this value must be looked up
@@ -161,9 +161,9 @@ export class PresElementBox extends ViewBoxBaseComponent<FieldViewProps, PresDoc
e.preventDefault();
}
+ @action
stopDrag = (e: PointerEvent) => {
- const activeItem = this.rootDoc;
- activeItem.dragging = false;
+ this._dragging = false;
e.stopPropagation();
e.preventDefault();
}
@@ -174,7 +174,7 @@ export class PresElementBox extends ViewBoxBaseComponent<FieldViewProps, PresDoc
const dragItem: HTMLElement[] = [];
PresBox.Instance._dragArray.map(ele => {
const doc = ele;
- doc.className = "presItem-slide"
+ doc.className = "presItem-slide";
dragItem.push(doc);
});
const addAudioTag = (dropDoc: any) => {
@@ -201,7 +201,7 @@ export class PresElementBox extends ViewBoxBaseComponent<FieldViewProps, PresDoc
};
if (activeItem) {
DragManager.StartDrag(dragItem.map(ele => ele), dragData, e.clientX, e.clientY, undefined, finishDrag);
- activeItem.dragging = true;
+ runInAction(() => this._dragging = true);
return true;
}
return false;
@@ -214,11 +214,11 @@ export class PresElementBox extends ViewBoxBaseComponent<FieldViewProps, PresDoc
onPointerMove = (e: PointerEvent) => {
const slide = this._itemRef.current!;
- if (slide && DragManager.docsBeingDragged.length > 1) {
+ if (slide && DragManager.docsBeingDragged.length > 0) {
const rect = slide.getBoundingClientRect();
- let y = e.clientY - rect.top; //y position within the element.
- let height = slide.clientHeight;
- let halfLine = height / 2;
+ const y = e.clientY - rect.top; //y position within the element.
+ const height = slide.clientHeight;
+ const halfLine = height / 2;
if (y <= halfLine) {
slide.style.borderTop = "solid 2px #5B9FDD";
slide.style.borderBottom = "0px";
@@ -285,7 +285,6 @@ export class PresElementBox extends ViewBoxBaseComponent<FieldViewProps, PresDoc
@computed get mainItem() {
const isSelected: boolean = PresBox.Instance._selectedArray.includes(this.rootDoc);
- const isDragging: boolean = BoolCast(this.rootDoc.dragging);
const toolbarWidth: number = PresBox.Instance.toolbarWidth;
const showMore: boolean = PresBox.Instance.toolbarWidth >= 300;
const targetDoc: Doc = Cast(this.rootDoc.presentationTargetDoc, Doc, null);
@@ -293,7 +292,7 @@ export class PresElementBox extends ViewBoxBaseComponent<FieldViewProps, PresDoc
return (
<div className={`presItem-container`} key={this.props.Document[Id] + this.indexInPres}
ref={this._itemRef}
- style={{ backgroundColor: isSelected ? "#AEDDF8" : "rgba(0,0,0,0)", opacity: isDragging ? 0.3 : 1 }}
+ style={{ backgroundColor: isSelected ? "#AEDDF8" : "rgba(0,0,0,0)", opacity: this._dragging ? 0.3 : 1 }}
onClick={e => {
e.stopPropagation();
e.preventDefault();