aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/presentationview/PresElementBox.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views/presentationview/PresElementBox.tsx')
-rw-r--r--src/client/views/presentationview/PresElementBox.tsx43
1 files changed, 22 insertions, 21 deletions
diff --git a/src/client/views/presentationview/PresElementBox.tsx b/src/client/views/presentationview/PresElementBox.tsx
index 9052967e5..1d6721bca 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";
@@ -45,6 +43,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
@@ -159,9 +159,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();
}
@@ -172,12 +172,12 @@ 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);
});
if (activeItem) {
DragManager.StartDocumentDrag(dragItem.map(ele => ele), dragData, e.clientX, e.clientY);
- activeItem.dragging = true;
+ runInAction(() => this._dragging = true);
return true;
}
return false;
@@ -189,18 +189,20 @@ export class PresElementBox extends ViewBoxBaseComponent<FieldViewProps, PresDoc
}
onPointerMove = (e: PointerEvent) => {
- const slide = this._itemRef.current!;
- const rect = slide?.getBoundingClientRect();
- let y = e.clientY - rect.top; //y position within the element.
- let height = slide.clientHeight;
- let halfLine = height / 2;
- if (DragManager.docsBeingDragged.length > 1) {
- if (y <= halfLine) {
- slide.style.borderTop = "solid 2px #5B9FDD";
- slide.style.borderBottom = "0px";
- } else if (y > halfLine) {
- slide.style.borderTop = "0px";
- slide.style.borderBottom = "solid 2px #5B9FDD";
+ const slide = this._itemRef.current;
+ if (slide) {
+ const rect = slide.getBoundingClientRect();
+ const y = e.clientY - rect.top; //y position within the element.
+ const height = slide.clientHeight;
+ const halfLine = height / 2;
+ if (DragManager.docsBeingDragged.length) {
+ if (y <= halfLine) {
+ slide.style.borderTop = "solid 2px #5B9FDD";
+ slide.style.borderBottom = "0px";
+ } else if (y > halfLine) {
+ slide.style.borderTop = "0px";
+ slide.style.borderBottom = "solid 2px #5B9FDD";
+ }
}
}
document.removeEventListener("pointermove", this.onPointerMove);
@@ -244,7 +246,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);
@@ -252,7 +253,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();