diff options
author | Monika Hedman <monika_hedman@brown.edu> | 2019-02-24 17:03:19 -0500 |
---|---|---|
committer | Monika Hedman <monika_hedman@brown.edu> | 2019-02-24 17:03:19 -0500 |
commit | 93c5e7c323113bf8beeb6207ba22fbbb4ab71796 (patch) | |
tree | bc92f0b418a5f3e650eeeab1f0e971e318879418 /src | |
parent | b119b7d4b38c3eada66e4ac49f1d65dfae6b22c0 (diff) |
Fixed stuff from the merge
Diffstat (limited to 'src')
-rw-r--r-- | src/client/views/DocumentManager.tsx | 37 | ||||
-rw-r--r-- | src/client/views/collections/CollectionView.tsx | 2 | ||||
-rw-r--r-- | src/client/views/collections/CollectionViewBase.tsx | 6 | ||||
-rw-r--r-- | src/client/views/nodes/DocumentView.tsx | 6 |
4 files changed, 27 insertions, 24 deletions
diff --git a/src/client/views/DocumentManager.tsx b/src/client/views/DocumentManager.tsx index ab54a7955..35064d830 100644 --- a/src/client/views/DocumentManager.tsx +++ b/src/client/views/DocumentManager.tsx @@ -4,8 +4,9 @@ import { observable, action } from 'mobx'; import { DocumentView } from './nodes/DocumentView'; import { Document } from "../../fields/Document" import { CollectionFreeFormView } from './collections/CollectionFreeFormView'; -import { KeyStore } from '../../fields/Key'; +import { KeyStore } from '../../fields/KeyStore'; import { CollectionViewBase } from './collections/CollectionViewBase'; +import { CollectionViewType, CollectionView } from './collections/CollectionView'; export class DocumentManager { @@ -60,7 +61,7 @@ export class DocumentManager { //gets document view that is in a freeform canvas collection DocumentManager.Instance.DocumentViews.map(view => { let doc = view.props.Document; - if (view.props.ContainingCollectionView instanceof CollectionFreeFormView) { + if (view.props.ContainingCollectionView && view.props.ContainingCollectionView.collectionViewType == CollectionViewType.Freeform) { if (Object.is(doc, toFind)) { toReturn = view; return; @@ -88,16 +89,13 @@ export class DocumentManager { let scale: number; let XView: number; let YView: number; - let width: number; - let height: number; //if the view exists in a freeform collection - if (docView && docView.MainContent.current) { - width = docView.MainContent.current.clientWidth - height = docView.MainContent.current.clientHeight + if (docView) { + let { width, height } = docView.size(); //base case: parent of parent does not exist - if (docView.props.ContainingCollectionView == null) { + if (!docView.props.ContainingCollectionView) { scale = docView.props.ScreenToLocalTransform().Scale let doc = docView.props.Document; @@ -105,34 +103,32 @@ export class DocumentManager { XView = (-doc.GetNumber(KeyStore.X, 0) * scale) + (window.innerWidth / 2) - (width * scale / 2) YView = (-doc.GetNumber(KeyStore.Y, 0) * scale) + (window.innerHeight / 2) - (height * scale / 2) //set x and y view of parent - if (docView instanceof CollectionFreeFormView) { + if (docView instanceof CollectionView) { DocumentManager.Instance.setViewportXY(docView, XView, YView) } } //parent is not main, parent is centered and calls itself else { - if (docView.props.ContainingCollectionView.props.ContainingDocumentView && docView.props.ContainingCollectionView.props.ContainingDocumentView.MainContent.current) { + if (true) { //view of parent - let tempCollectionView = docView.props.ContainingCollectionView.props.ContainingDocumentView + let { width: parentWidth, height: parentHeight } = docView.props.ContainingCollectionView.props.documentSize(); + let scale = docView.props.ContainingCollectionView.props.ScreenToLocalTransform().Scale; let doc = docView.props.Document - let parentWidth = docView.props.ContainingCollectionView.props.ContainingDocumentView.MainContent.current.clientWidth - let parentHeight = docView.props.ContainingCollectionView.props.ContainingDocumentView.MainContent.current.clientHeight //TODO: make sure to test if the parent view is a freeform view. if not, just skip to the next level - if (docView.props.ContainingCollectionView instanceof CollectionFreeFormView) { + if (docView.props.ContainingCollectionView.collectionViewType == CollectionViewType.Freeform) { //scale of parent - scale = tempCollectionView.props.ScreenToLocalTransform().Scale XView = (-doc.GetNumber(KeyStore.X, 0) * scale) + (parentWidth / 2) - (width * scale / 2); YView = (-doc.GetNumber(KeyStore.Y, 0) * scale) + (parentHeight / 2) - (height * scale / 2); // //node.Parent.setViewportXY(XView, YView); DocumentManager.Instance.setViewportXY(docView.props.ContainingCollectionView, XView, YView) - return DocumentManager.Instance.centerNode(docView.props.ContainingCollectionView.props.DocumentForCollection); + return DocumentManager.Instance.centerNode(docView.props.ContainingCollectionView.props.Document); } } else { - return DocumentManager.Instance.centerNode(docView.props.ContainingCollectionView.props.DocumentForCollection) + // return DocumentManager.Instance.centerNode(docView.props.ContainingCollectionView.props.Document) } } } @@ -143,9 +139,12 @@ export class DocumentManager { } @action - private setViewportXY(collection: CollectionFreeFormView, x: number, y: number) { + private setViewportXY(collection: CollectionView, x: number, y: number) { + if (collection.collectionViewType !== CollectionViewType.Freeform) { + return; + } console.log("viewport is setting") - let doc = collection.props.DocumentForCollection; + let doc = collection.props.Document; doc.SetNumber(KeyStore.PanX, x); doc.SetNumber(KeyStore.PanY, y); } diff --git a/src/client/views/collections/CollectionView.tsx b/src/client/views/collections/CollectionView.tsx index 90080ab43..7f1390ae2 100644 --- a/src/client/views/collections/CollectionView.tsx +++ b/src/client/views/collections/CollectionView.tsx @@ -28,7 +28,7 @@ export class CollectionView extends React.Component<CollectionViewProps> { public static LayoutString(fieldKey: string = "DataKey") { return `<CollectionView Document={Document} - ScreenToLocalTransform={ScreenToLocalTransform} fieldKey={${fieldKey}} isSelected={isSelected} select={select} bindings={bindings} + ScreenToLocalTransform={ScreenToLocalTransform} fieldKey={${fieldKey}} isSelected={isSelected} select={select} bindings={bindings} documentSize={documentSize} isTopMost={isTopMost} BackgroundView={BackgroundView} />`; } public active = () => { diff --git a/src/client/views/collections/CollectionViewBase.tsx b/src/client/views/collections/CollectionViewBase.tsx index 0658c8af0..948472275 100644 --- a/src/client/views/collections/CollectionViewBase.tsx +++ b/src/client/views/collections/CollectionViewBase.tsx @@ -6,10 +6,11 @@ import { KeyStore } from "../../../fields/KeyStore"; import { Opt, FieldWaiting } from "../../../fields/Field"; import { undoBatch } from "../../util/UndoManager"; import { DragManager } from "../../util/DragManager"; -import { DocumentView } from "../nodes/DocumentView"; +import { DocumentView, JsxArgs } from "../nodes/DocumentView"; import { Documents, DocumentOptions } from "../../documents/Documents"; import { Key } from "../../../fields/Key"; import { Transform } from "../../util/Transform"; +import { CollectionView } from "./CollectionView"; export interface CollectionViewProps { fieldKey: Key; @@ -18,13 +19,14 @@ export interface CollectionViewProps { isSelected: () => boolean; isTopMost: boolean; select: (ctrlPressed: boolean) => void; + documentSize: () => { width: number, height: number }; bindings: any; } export interface SubCollectionViewProps extends CollectionViewProps { active: () => boolean; addDocument: (doc: Document) => void; removeDocument: (doc: Document) => boolean; - CollectionView: any; + CollectionView: CollectionView; } export class CollectionViewBase extends React.Component<SubCollectionViewProps> { diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx index d8e2f3401..40cf8d9e2 100644 --- a/src/client/views/nodes/DocumentView.tsx +++ b/src/client/views/nodes/DocumentView.tsx @@ -21,6 +21,7 @@ import "./DocumentView.scss"; import React = require("react"); import { DocumentManager } from "../DocumentManager"; import { TextField } from "../../../fields/TextField"; +import { Utils } from "../../../Utils"; const JsxParser = require('react-jsx-parser').default;//TODO Why does this need to be imported like this? export interface DocumentViewProps { @@ -104,6 +105,7 @@ export class DocumentView extends React.Component<DocumentViewProps> { @computed get layoutFields(): Key[] { return this.props.Document.GetData(KeyStore.LayoutFields, ListField, new Array<Key>()); } screenRect = (): ClientRect | DOMRect => this._mainCont.current ? this._mainCont.current.getBoundingClientRect() : new DOMRect(); + size = (): { width: number, height: number } => this._mainCont.current ? { width: this._mainCont.current.clientWidth, height: this._mainCont.current.clientHeight } : { width: 0, height: 0 }; onPointerDown = (e: React.PointerEvent): void => { this._downX = e.clientX; @@ -182,7 +184,6 @@ export class DocumentView extends React.Component<DocumentViewProps> { //TODO Monika @action Center = (e: React.MouseEvent): void => { - DocumentManager.Instance.centerNode(this.props.Document) DocumentManager.Instance.centerNode(this) } @@ -261,7 +262,8 @@ export class DocumentView extends React.Component<DocumentViewProps> { this._documentBindings = { ...this.props, isSelected: this.isSelected, - select: this.select + select: this.select, + documentSize: this.size }; for (const key of this.layoutKeys) { this._documentBindings[key.Name + "Key"] = key; // this maps string values of the form <keyname>Key to an actual key Kestore.keyname e.g, "DataKey" => KeyStore.Data |