From 7a9c7c74ce364e4b5ee4af35241870fea31c5cca Mon Sep 17 00:00:00 2001 From: Mohammad Amoush Date: Tue, 16 Jul 2019 16:04:23 -0400 Subject: Documentation --- .../views/presentationview/PresentationElement.tsx | 83 +++++++++++++++++----- 1 file changed, 65 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/client/views/presentationview/PresentationElement.tsx b/src/client/views/presentationview/PresentationElement.tsx index a66bf34ce..a3c5a969b 100644 --- a/src/client/views/presentationview/PresentationElement.tsx +++ b/src/client/views/presentationview/PresentationElement.tsx @@ -396,6 +396,9 @@ export default class PresentationElement extends React.Component { this.listdropDisposer && this.listdropDisposer(); if (ele) { @@ -403,11 +406,18 @@ export default class PresentationElement extends React.Component { return [xCord, yCord]; } - + /** + * This method is called when a element is dropped on a already esstablished target. + * It makes sure to do appropirate action depending on if the item is dropped before + * or after the target. + */ listDrop = async (e: Event, de: DragManager.DropEvent) => { let x = this.ScreenToLocalListTransform(de.x, de.y); let rect = this.header!.getBoundingClientRect(); @@ -420,7 +430,7 @@ export default class PresentationElement extends React.Component Doc.AddDocToList(this.props.mainDocument, "data", d, this.props.document, before) || added, false) @@ -433,8 +443,12 @@ export default class PresentationElement extends React.Component { + /** + * This method is called to update groups when the user drags and drops an + * element to a different place. It follows the default behaviour and reconstructs + * the groups in the way they would appear if clicked by user. + */ + updateGroupsOnDrop = async (droppedDoc: Doc, de: DragManager.DropEvent) => { let x = this.ScreenToLocalListTransform(de.x, de.y); let rect = this.header!.getBoundingClientRect(); @@ -482,6 +496,8 @@ export default class PresentationElement extends React.Component 1) { let selectedButtonsOrigBelow: boolean[] = await this.getSelectedButtonsOfDoc(this.props.allListElements[indexOfBelow]); @@ -512,9 +528,8 @@ export default class PresentationElement extends React.Component 0) { let aboveDoc = this.props.allListElements[this.props.index - 1]; @@ -543,7 +558,7 @@ export default class PresentationElement extends React.Component 0) { @@ -610,9 +625,11 @@ export default class PresentationElement extends React.Component { - let p = this.props; - let castedList = Cast(this.props.presButtonBackUp.selectedButtonDocs, listSpec(Doc)); let foundSelectedButtons: boolean[] = new Array(6); @@ -632,6 +649,7 @@ export default class PresentationElement extends React.Component { this.props.document.libraryBrush = true; if (e.buttons === 1 && SelectionManager.GetIsDragging()) { @@ -647,6 +665,8 @@ export default class PresentationElement extends React.Component { this.props.document.libraryBrush = false; //to get currently selected presentation doc @@ -663,6 +683,10 @@ export default class PresentationElement extends React.Component { this.props.document.libraryBrush = false; let x = this.ScreenToLocalListTransform(e.clientX, e.clientY); @@ -679,14 +703,24 @@ export default class PresentationElement extends React.Component { return this.props.document !== target && this.props.removeDocByRef(doc) && addDoc(doc); } - - - private halveGroupArray(targetDoc: Doc, propsGroupArray: Doc[], droppedDoc: Doc, p: Readonly & Readonly<{ children?: React.ReactNode; }>, belowDocGuid: string) { + /** + * Helper method that gets called to divide a group array into two different groups + * including the targetDoc in first part. + * @param targetDoc document that is targeted as slicing point + * @param propsGroupArray the array that gets divided into 2 + * @param droppedDoc the dropped document + * @param belowDocGuid presentId of the belowGroup + */ + private halveGroupArray(targetDoc: Doc, propsGroupArray: Doc[], droppedDoc: Doc, belowDocGuid: string) { let targetIndex = propsGroupArray.indexOf(targetDoc); let firstPart = propsGroupArray.slice(0, targetIndex + 1); let firstPartNewGuid = Utils.GenerateGuid(); @@ -694,18 +728,33 @@ export default class PresentationElement extends React.Component & Readonly<{ children?: React.ReactNode; }>) { + /** + * Helper method that creates a new group, pushing above document first, + * and dropped document second. + * @param aboveDoc the document above dropped document + * @param droppedDoc the dropped document itself + * @param aboveDocGuid above document's presentId + */ + private createNewGroup(aboveDoc: Doc, droppedDoc: Doc, aboveDocGuid: string) { let newGroup: Doc[] = []; newGroup.push(aboveDoc); newGroup.push(droppedDoc); droppedDoc.presentId = aboveDocGuid; - p.groupMappings.set(aboveDocGuid, newGroup); + this.props.groupMappings.set(aboveDocGuid, newGroup); } + /** + * Helper method that finds the above document's group, and pushes the + * dropped document into that group, protecting the visual order of the + * presentation elements. + * @param aboveDoc the document above dropped document + * @param droppedDoc the dropped document itself + * @param aboveDocGuid above document's presentId + */ private protectOrderAndPush(aboveDocGuid: string, aboveDoc: Doc, droppedDoc: Doc) { let groupArray = this.props.groupMappings.get(aboveDocGuid)!; let tempStack: Doc[] = []; @@ -734,8 +783,6 @@ export default class PresentationElement extends React.Component { p.document.libraryBrush = true; }; - let onLeave = (e: React.PointerEvent) => { p.document.libraryBrush = false; }; let dropAction = StrCast(this.props.document.dropAction) as dropActionType; let onItemDown = SetupDrag(this.presElRef, () => p.document, this.move, dropAction, this.props.mainDocument[Id], true); return ( -- cgit v1.2.3-70-g09d2