From 59cc888c8bf0559c50e12fd2774ea5ac4ebb3059 Mon Sep 17 00:00:00 2001
From: yipstanley <stanley_yip@brown.edu>
Date: Tue, 26 Feb 2019 16:33:53 -0500
Subject: basic implementation of prototype/delegate stuff

---
 src/client/views/collections/CollectionViewBase.tsx | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

(limited to 'src/client/views/collections/CollectionViewBase.tsx')

diff --git a/src/client/views/collections/CollectionViewBase.tsx b/src/client/views/collections/CollectionViewBase.tsx
index 7e269caf1..be3cb0d5f 100644
--- a/src/client/views/collections/CollectionViewBase.tsx
+++ b/src/client/views/collections/CollectionViewBase.tsx
@@ -43,11 +43,21 @@ export class CollectionViewBase extends React.Component<SubCollectionViewProps>
     @action
     protected drop(e: Event, de: DragManager.DropEvent) {
         const doc: DocumentView = de.data["document"];
+        if (de.data["alias"]) {
+            let newDoc = doc.props.Document.CreateAlias()
+            const xOffset = de.data["xOffset"] as number || 0
+            const yOffset = de.data["yOffset"] as number || 0
+            newDoc.SetNumber(KeyStore.X, de.x - xOffset)
+            newDoc.SetNumber(KeyStore.Y, de.y - yOffset)
+            newDoc.SetNumber(KeyStore.Width, doc.props.Document.GetNumber(KeyStore.Width, 100))
+            newDoc.SetNumber(KeyStore.Height, doc.props.Document.GetNumber(KeyStore.Height, 100))
+            this.props.addDocument(newDoc)
+        }
         if (doc.props.ContainingCollectionView && doc.props.ContainingCollectionView !== this.props.CollectionView) {
-            if (doc.props.RemoveDocument) {
+            if (!de.data["alias"] && doc.props.RemoveDocument) {
                 doc.props.RemoveDocument(doc.props.Document);
             }
-            this.props.addDocument(doc.props.Document);
+            this.props.addDocument(de.data["alias"] ? doc.props.Document.CreateAlias() : doc.props.Document);
         }
         e.stopPropagation();
     }
-- 
cgit v1.2.3-70-g09d2


From b4dc598ff08c7c684daa4b75508e17213d29d8e5 Mon Sep 17 00:00:00 2001
From: yipstanley <stanley_yip@brown.edu>
Date: Sun, 17 Mar 2019 13:34:10 -0400
Subject: commitment is difficult

---
 src/client/documents/Documents.ts                  | 29 ++++++++++++++--------
 src/client/views/Main.tsx                          |  2 +-
 .../views/collections/CollectionFreeFormView.tsx   | 12 ++++++---
 .../views/collections/CollectionViewBase.tsx       | 16 ++++++++++--
 4 files changed, 42 insertions(+), 17 deletions(-)

(limited to 'src/client/views/collections/CollectionViewBase.tsx')

diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts
index cc8052d44..d7bc2e3b0 100644
--- a/src/client/documents/Documents.ts
+++ b/src/client/documents/Documents.ts
@@ -59,12 +59,6 @@ export namespace Documents {
         });
     }
     function assignOptions(doc: Document, options: DocumentOptions): Document {
-        if (options.x !== undefined) { doc.SetNumber(KeyStore.X, options.x); }
-        if (options.y !== undefined) { doc.SetNumber(KeyStore.Y, options.y); }
-        if (options.width !== undefined) { doc.SetNumber(KeyStore.Width, options.width); }
-        if (options.height !== undefined) { doc.SetNumber(KeyStore.Height, options.height); }
-        if (options.nativeWidth !== undefined) { doc.SetNumber(KeyStore.NativeWidth, options.nativeWidth); }
-        if (options.nativeHeight !== undefined) { doc.SetNumber(KeyStore.NativeHeight, options.nativeHeight); }
         if (options.title !== undefined) { doc.SetText(KeyStore.Title, options.title); }
         if (options.panx !== undefined) { doc.SetNumber(KeyStore.PanX, options.panx); }
         if (options.pany !== undefined) { doc.SetNumber(KeyStore.PanY, options.pany); }
@@ -74,6 +68,15 @@ export namespace Documents {
         if (options.layoutKeys !== undefined) { doc.Set(KeyStore.LayoutKeys, new ListField(options.layoutKeys)); }
         return doc;
     }
+
+    function assignToDelegate(doc: Document, options: DocumentOptions): Document {
+        if (options.x !== undefined) { doc.SetNumber(KeyStore.X, options.x); }
+        if (options.y !== undefined) { doc.SetNumber(KeyStore.Y, options.y); }
+        if (options.width !== undefined) { doc.SetNumber(KeyStore.Width, options.width); }
+        if (options.height !== undefined) { doc.SetNumber(KeyStore.Height, options.height); }
+        return doc
+    }
+
     function setupPrototypeOptions(protoId: string, title: string, layout: string, options: DocumentOptions): Document {
         return assignOptions(new Document(protoId), { ...options, title: title, layout: layout });
     }
@@ -130,8 +133,9 @@ export namespace Documents {
         doc.SetText(KeyStore.OverlayLayout, FixedCaption());
         return doc.MakeDelegate();
     }
+
     export function TextDocument(options: DocumentOptions = {}) {
-        return SetInstanceOptions(GetTextPrototype(), options, "", TextField).MakeDelegate()
+        return assignToDelegate(SetInstanceOptions(GetTextPrototype(), options, "", TextField).MakeDelegate(), options);
     }
     export function PdfDocument(url: string, options: DocumentOptions = {}) {
         return SetInstanceOptions(GetPdfPrototype(), options, new URL(url), PDFField).MakeDelegate();
@@ -142,19 +146,22 @@ export namespace Documents {
     export function HtmlDocument(html: string, options: DocumentOptions = {}) {
         return SetInstanceOptions(GetWebPrototype(), options, html, HtmlField).MakeDelegate();
     }
-    export function FreeformDocument(documents: Array<Document>, options: DocumentOptions, id?: string) {
+    export function FreeformDocument(documents: Array<Document>, options: DocumentOptions, id?: string, makePrototype: boolean = true) {
+        if (!makePrototype) {
+            return SetInstanceOptions(GetCollectionPrototype(), { ...options, viewType: CollectionViewType.Freeform }, documents, ListField, id)
+        }
         return SetInstanceOptions(GetCollectionPrototype(), { ...options, viewType: CollectionViewType.Freeform }, documents, ListField, id).MakeDelegate()
     }
     export function SchemaDocument(documents: Array<Document>, options: DocumentOptions, id?: string) {
-        return SetInstanceOptions(GetCollectionPrototype(), { ...options, viewType: CollectionViewType.Schema }, documents, ListField, id).MakeDelegate()
+        return SetInstanceOptions(GetCollectionPrototype(), { ...options, viewType: CollectionViewType.Schema }, documents, ListField, id)
     }
     export function DockDocument(config: string, options: DocumentOptions, id?: string) {
-        return SetInstanceOptions(GetCollectionPrototype(), { ...options, viewType: CollectionViewType.Docking }, config, TextField, id).MakeDelegate()
+        return SetInstanceOptions(GetCollectionPrototype(), { ...options, viewType: CollectionViewType.Docking }, config, TextField, id)
     }
     export function KVPDocument(document: Document, options: DocumentOptions = {}, id?: string) {
         var deleg = GetKVPPrototype().MakeDelegate(id);
         deleg.Set(KeyStore.Data, document);
-        return assignOptions(deleg, options);
+        return assignToDelegate(assignOptions(deleg, options).MakeDelegate(), options);
     }
 
     // example of custom display string for an image that shows a caption.
diff --git a/src/client/views/Main.tsx b/src/client/views/Main.tsx
index c9bdc24c2..020f49528 100644
--- a/src/client/views/Main.tsx
+++ b/src/client/views/Main.tsx
@@ -43,7 +43,7 @@ Documents.initProtos(mainDocId, (res?: Document) => {
 
         // bcz: strangely, we need a timeout to prevent exceptions/issues initializing GoldenLayout (the rendering engine for Main Container)
         setTimeout(() => {
-            mainfreeform = Documents.FreeformDocument([], { x: 0, y: 400, title: "mini collection" });
+            mainfreeform = Documents.FreeformDocument([], { x: 0, y: 400, title: "mini collection" }, undefined, false);
 
             var dockingLayout = { content: [{ type: 'row', content: [CollectionDockingView.makeDocumentConfig(mainfreeform)] }] };
             mainContainer.SetText(KeyStore.Data, JSON.stringify(dockingLayout));
diff --git a/src/client/views/collections/CollectionFreeFormView.tsx b/src/client/views/collections/CollectionFreeFormView.tsx
index 95b4f6f19..ea00ce751 100644
--- a/src/client/views/collections/CollectionFreeFormView.tsx
+++ b/src/client/views/collections/CollectionFreeFormView.tsx
@@ -59,17 +59,23 @@ export class CollectionFreeFormView extends CollectionViewBase {
     drop = (e: Event, de: DragManager.DropEvent) => {
         super.drop(e, de);
 
+        let screenX = de.x - (de.data["xOffset"] as number || 0);
+        let screenY = de.y - (de.data["yOffset"] as number || 0);
+        const [x, y] = this.getTransform().transformPoint(screenX, screenY);
         if (!de.data["alias"]) {
             const docView: DocumentView = de.data["documentView"];
             const doc = docView ? docView.props.Document : de.data["document"]
             //this should be able to use translate and scale methods on an Identity transform, no?
-            let screenX = de.x - (de.data["xOffset"] as number || 0);
-            let screenY = de.y - (de.data["yOffset"] as number || 0);
-            const [x, y] = this.getTransform().transformPoint(screenX, screenY);
             doc.SetNumber(KeyStore.X, x);
             doc.SetNumber(KeyStore.Y, y);
             this.bringToFront(doc);
         }
+        else {
+            let newDoc: Document = de.data["newDoc"]
+            newDoc.SetNumber(KeyStore.X, x)
+            newDoc.SetNumber(KeyStore.Y, y)
+            this.bringToFront(newDoc)
+        }
     }
 
     @action
diff --git a/src/client/views/collections/CollectionViewBase.tsx b/src/client/views/collections/CollectionViewBase.tsx
index f3770056d..a662447cf 100644
--- a/src/client/views/collections/CollectionViewBase.tsx
+++ b/src/client/views/collections/CollectionViewBase.tsx
@@ -3,7 +3,7 @@ import { Document } from "../../../fields/Document";
 import { ListField } from "../../../fields/ListField";
 import React = require("react");
 import { KeyStore } from "../../../fields/KeyStore";
-import { FieldWaiting } from "../../../fields/Field";
+import { FieldWaiting, Field } from "../../../fields/Field";
 import { undoBatch } from "../../util/UndoManager";
 import { DragManager } from "../../util/DragManager";
 import { DocumentView } from "../nodes/DocumentView";
@@ -47,11 +47,23 @@ export class CollectionViewBase extends React.Component<SubCollectionViewProps>
     protected drop(e: Event, de: DragManager.DropEvent) {
         const docView: DocumentView = de.data["documentView"];
         const doc: Document = de.data["document"]
+        if (de.data["alias"]) {
+            let newDoc = docView ? docView.props.Document.CreateAlias() : doc.CreateAlias()
+            de.data["newDoc"] = newDoc
+            let oldDoc = docView ? docView.props.Document : doc
+            oldDoc.GetAsync(KeyStore.Width, (f: Field) => {
+                newDoc.Set(KeyStore.Width, f)
+            })
+            oldDoc.GetAsync(KeyStore.Height, (f: Field) => {
+                newDoc.Set(KeyStore.Height, f)
+            })
+        }
+
         if (docView && docView.props.ContainingCollectionView && docView.props.ContainingCollectionView !== this.props.CollectionView) {
             if (docView.props.RemoveDocument && !de.data["alias"]) {
                 docView.props.RemoveDocument(docView.props.Document)
             }
-            this.props.addDocument(de.data["alias"] ? docView.props.Document.CreateAlias() : docView.props.Document)
+            this.props.addDocument(de.data["alias"] ? de.data["newDoc"] : docView.props.Document)
         } else if (doc) {
             if (!de.data["alias"]) {
                 this.props.removeDocument(doc)
-- 
cgit v1.2.3-70-g09d2


From 301e7aef724a36926886659991c304da9c4d2b7c Mon Sep 17 00:00:00 2001
From: yipstanley <stanley_yip@brown.edu>
Date: Sun, 17 Mar 2019 15:05:56 -0400
Subject: updates

---
 src/client/documents/Documents.ts                  | 27 +++++++++++-----------
 .../views/collections/CollectionViewBase.tsx       | 17 +++++++++-----
 src/client/views/nodes/DocumentView.tsx            |  4 ++--
 3 files changed, 26 insertions(+), 22 deletions(-)

(limited to 'src/client/views/collections/CollectionViewBase.tsx')

diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts
index 26167fab5..8fa2a7515 100644
--- a/src/client/documents/Documents.ts
+++ b/src/client/documents/Documents.ts
@@ -75,15 +75,15 @@ export namespace Documents {
     }
     function assignOptions(doc: Document, options: DocumentOptions): Document {
         if (options.title !== undefined) { doc.SetText(KeyStore.Title, options.title); }
-        if (options.panx !== undefined) { doc.SetNumber(KeyStore.PanX, options.panx); }
-        if (options.pany !== undefined) { doc.SetNumber(KeyStore.PanY, options.pany); }
         if (options.page !== undefined) { doc.SetNumber(KeyStore.Page, options.page); }
         if (options.scale !== undefined) { doc.SetNumber(KeyStore.Scale, options.scale); }
         if (options.viewType !== undefined) { doc.SetNumber(KeyStore.ViewType, options.viewType); }
         if (options.backgroundColor !== undefined) { doc.SetText(KeyStore.BackgroundColor, options.backgroundColor); }
+        if (options.ink !== undefined) { doc.Set(KeyStore.Ink, new InkField(options.ink)); }
         if (options.layout !== undefined) { doc.SetText(KeyStore.Layout, options.layout); }
         if (options.layoutKeys !== undefined) { doc.Set(KeyStore.LayoutKeys, new ListField(options.layoutKeys)); }
-        if (options.ink !== undefined) { doc.Set(KeyStore.Ink, new InkField(options.ink)); }
+        if (options.panx !== undefined) { doc.SetNumber(KeyStore.PanX, options.panx); }
+        if (options.pany !== undefined) { doc.SetNumber(KeyStore.PanY, options.pany); }
         return doc;
     }
 
@@ -162,8 +162,7 @@ export namespace Documents {
 
 
     export function ImageDocument(url: string, options: DocumentOptions = {}) {
-        return SetInstanceOptions(GetImagePrototype(), { ...options, layoutKeys: [KeyStore.Data, KeyStore.Annotations, KeyStore.Caption] },
-            [new URL(url), ImageField]).MakeDelegate();
+        return assignToDelegate(SetInstanceOptions(GetImagePrototype(), options, [new URL(url), ImageField]).MakeDelegate(), { ...options, layoutKeys: [KeyStore.Data, KeyStore.Annotations, KeyStore.Caption] });
         // let doc = SetInstanceOptions(GetImagePrototype(), { ...options, layoutKeys: [KeyStore.Data, KeyStore.Annotations, KeyStore.Caption] },
         //     [new URL(url), ImageField]);
         // doc.SetText(KeyStore.Caption, "my caption...");
@@ -172,38 +171,38 @@ export namespace Documents {
         // return doc;
     }
     export function VideoDocument(url: string, options: DocumentOptions = {}) {
-        return SetInstanceOptions(GetVideoPrototype(), options, [new URL(url), VideoField]);
+        return assignToDelegate(SetInstanceOptions(GetVideoPrototype(), options, [new URL(url), VideoField]), options);
     }
     export function AudioDocument(url: string, options: DocumentOptions = {}) {
-        return SetInstanceOptions(GetAudioPrototype(), options, [new URL(url), AudioField]);
+        return assignToDelegate(SetInstanceOptions(GetAudioPrototype(), options, [new URL(url), AudioField]), options);
     }
 
     export function TextDocument(options: DocumentOptions = {}) {
         return assignToDelegate(SetInstanceOptions(GetTextPrototype(), options, ["", TextField]).MakeDelegate(), options);
     }
     export function PdfDocument(url: string, options: DocumentOptions = {}) {
-        return SetInstanceOptions(GetPdfPrototype(), options, [new URL(url), PDFField]).MakeDelegate();
+        return assignToDelegate(SetInstanceOptions(GetPdfPrototype(), options, [new URL(url), PDFField]).MakeDelegate(), options);
     }
     export function WebDocument(url: string, options: DocumentOptions = {}) {
-        return SetInstanceOptions(GetWebPrototype(), options, [new URL(url), WebField]).MakeDelegate();
+        return assignToDelegate(SetInstanceOptions(GetWebPrototype(), options, [new URL(url), WebField]).MakeDelegate(), options);
     }
     export function HtmlDocument(html: string, options: DocumentOptions = {}) {
-        return SetInstanceOptions(GetWebPrototype(), options, [html, HtmlField]).MakeDelegate();
+        return assignToDelegate(SetInstanceOptions(GetWebPrototype(), options, [html, HtmlField]).MakeDelegate(), options);
     }
     export function KVPDocument(document: Document, options: DocumentOptions = {}, id?: string) {
-        return SetInstanceOptions(GetKVPPrototype(), options, document, id).MakeDelegate()
+        return assignToDelegate(SetInstanceOptions(GetKVPPrototype(), options, document, id), options)
     }
     export function FreeformDocument(documents: Array<Document>, options: DocumentOptions, id?: string, makePrototype: boolean = true) {
         if (!makePrototype) {
             return SetInstanceOptions(GetCollectionPrototype(), { ...options, viewType: CollectionViewType.Freeform }, [documents, ListField], id)
         }
-        return SetInstanceOptions(GetCollectionPrototype(), { ...options, viewType: CollectionViewType.Freeform }, [documents, ListField], id).MakeDelegate()
+        return assignToDelegate(SetInstanceOptions(GetCollectionPrototype(), { ...options, viewType: CollectionViewType.Freeform }, [documents, ListField], id).MakeDelegate(), options)
     }
     export function SchemaDocument(documents: Array<Document>, options: DocumentOptions, id?: string) {
-        return SetInstanceOptions(GetCollectionPrototype(), { ...options, viewType: CollectionViewType.Schema }, [documents, ListField], id)
+        return assignToDelegate(SetInstanceOptions(GetCollectionPrototype(), { ...options, viewType: CollectionViewType.Schema }, [documents, ListField], id), options)
     }
     export function DockDocument(config: string, options: DocumentOptions, id?: string) {
-        return SetInstanceOptions(GetCollectionPrototype(), { ...options, viewType: CollectionViewType.Docking }, [config, TextField], id)
+        return assignToDelegate(SetInstanceOptions(GetCollectionPrototype(), { ...options, viewType: CollectionViewType.Docking }, [config, TextField], id), options)
     }
 
     // example of custom display string for an image that shows a caption.
diff --git a/src/client/views/collections/CollectionViewBase.tsx b/src/client/views/collections/CollectionViewBase.tsx
index 7cccfaf05..6725fc2d1 100644
--- a/src/client/views/collections/CollectionViewBase.tsx
+++ b/src/client/views/collections/CollectionViewBase.tsx
@@ -3,7 +3,7 @@ import { Document } from "../../../fields/Document";
 import { ListField } from "../../../fields/ListField";
 import React = require("react");
 import { KeyStore } from "../../../fields/KeyStore";
-import { FieldWaiting, Field } from "../../../fields/Field";
+import { FieldWaiting, Field, Opt } from "../../../fields/Field";
 import { undoBatch } from "../../util/UndoManager";
 import { DragManager } from "../../util/DragManager";
 import { DocumentView } from "../nodes/DocumentView";
@@ -11,6 +11,7 @@ import { Documents, DocumentOptions } from "../../documents/Documents";
 import { Key } from "../../../fields/Key";
 import { Transform } from "../../util/Transform";
 import { CollectionView } from "./CollectionView";
+import { NumberField } from "../../../fields/NumberField";
 
 export interface CollectionViewProps {
     fieldKey: Key;
@@ -51,11 +52,15 @@ export class CollectionViewBase extends React.Component<SubCollectionViewProps>
             let newDoc = docView ? docView.props.Document.CreateAlias() : doc.CreateAlias()
             de.data["newDoc"] = newDoc
             let oldDoc = docView ? docView.props.Document : doc
-            oldDoc.GetAsync(KeyStore.Width, (f: Field) => {
-                newDoc.Set(KeyStore.Width, f)
+            oldDoc.GetTAsync(KeyStore.Width, NumberField, (f: Opt<NumberField>) => {
+                if (f) {
+                    newDoc.SetNumber(KeyStore.Width, f.Data)
+                }
             })
-            oldDoc.GetAsync(KeyStore.Height, (f: Field) => {
-                newDoc.Set(KeyStore.Height, f)
+            oldDoc.GetTAsync(KeyStore.Height, NumberField, (f: Opt<NumberField>) => {
+                if (f) {
+                    newDoc.SetNumber(KeyStore.Height, f.Data)
+                }
             })
         }
 
@@ -68,7 +73,7 @@ export class CollectionViewBase extends React.Component<SubCollectionViewProps>
             if (!de.data["alias"]) {
                 this.props.removeDocument(doc)
             }
-            this.props.addDocument(doc)
+            this.props.addDocument(de.data["alias"] ? de.data["newDoc"] : doc)
         }
         e.stopPropagation();
     }
diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx
index 84483ac55..a0ea9d3c2 100644
--- a/src/client/views/nodes/DocumentView.tsx
+++ b/src/client/views/nodes/DocumentView.tsx
@@ -156,7 +156,7 @@ export class DocumentView extends React.Component<DocumentViewProps> {
             const [left, top] = this.props.ScreenToLocalTransform().inverse().transformPoint(0, 0);
             let dragData: { [id: string]: any } = {};
             dragData["documentView"] = this;
-            dragData["document"] = ctrlPressed ? this.props.Document.CreateAlias() : this.props.Document
+            dragData["document"] = this.props.Document
             dragData["xOffset"] = x - left;
             dragData["yOffset"] = y - top;
             dragData["alias"] = ctrlPressed
@@ -203,7 +203,7 @@ export class DocumentView extends React.Component<DocumentViewProps> {
 
     fieldsClicked = (e: React.MouseEvent): void => {
         if (this.props.AddDocument) {
-            this.props.AddDocument(Documents.KVPDocument(this.props.Document));
+            this.props.AddDocument(Documents.KVPDocument(this.props.Document, { width: 300, height: 300 }));
         }
     }
     fullScreenClicked = (e: React.MouseEvent): void => {
-- 
cgit v1.2.3-70-g09d2


From a6ca5db7f43ee31965169ff8d6d0aaffa86dc74e Mon Sep 17 00:00:00 2001
From: Bob Zeleznik <zzzman@gmail.com>
Date: Sun, 17 Mar 2019 23:04:18 -0400
Subject: tweaked drop code

---
 src/client/documents/Documents.ts                  | 39 ++++++++++------------
 src/client/util/DragManager.ts                     |  2 +-
 .../views/collections/CollectionFreeFormView.tsx   | 19 +++--------
 .../views/collections/CollectionViewBase.tsx       | 34 +++++++++----------
 src/client/views/nodes/DocumentView.tsx            |  8 ++---
 5 files changed, 43 insertions(+), 59 deletions(-)

(limited to 'src/client/views/collections/CollectionViewBase.tsx')

diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts
index 20cbcdcb4..3aa575dbb 100644
--- a/src/client/documents/Documents.ts
+++ b/src/client/documents/Documents.ts
@@ -1,30 +1,27 @@
+import { AudioField } from "../../fields/AudioField";
 import { Document } from "../../fields/Document";
-import { Server } from "../Server";
+import { Field } from "../../fields/Field";
+import { HtmlField } from "../../fields/HtmlField";
+import { ImageField } from "../../fields/ImageField";
+import { InkField, StrokeData } from "../../fields/InkField";
+import { Key } from "../../fields/Key";
 import { KeyStore } from "../../fields/KeyStore";
-import { TextField } from "../../fields/TextField";
-import { NumberField } from "../../fields/NumberField";
 import { ListField } from "../../fields/ListField";
-import { FormattedTextBox } from "../views/nodes/FormattedTextBox";
-import { ImageField } from "../../fields/ImageField";
-import { ImageBox } from "../views/nodes/ImageBox";
+import { PDFField } from "../../fields/PDFField";
+import { TextField } from "../../fields/TextField";
+import { VideoField } from "../../fields/VideoField";
 import { WebField } from "../../fields/WebField";
-import { WebBox } from "../views/nodes/WebBox";
+import { Server } from "../Server";
+import { CollectionPDFView } from "../views/collections/CollectionPDFView";
+import { CollectionVideoView } from "../views/collections/CollectionVideoView";
 import { CollectionView, CollectionViewType } from "../views/collections/CollectionView";
-import { HtmlField } from "../../fields/HtmlField";
-import { Key } from "../../fields/Key"
-import { Field } from "../../fields/Field";
-import { KeyValueBox } from "../views/nodes/KeyValueBox"
-import { KVPField } from "../../fields/KVPField";
-import { VideoField } from "../../fields/VideoField"
-import { VideoBox } from "../views/nodes/VideoBox";
-import { AudioField } from "../../fields/AudioField";
 import { AudioBox } from "../views/nodes/AudioBox";
-import { PDFField } from "../../fields/PDFField";
+import { FormattedTextBox } from "../views/nodes/FormattedTextBox";
+import { ImageBox } from "../views/nodes/ImageBox";
+import { KeyValueBox } from "../views/nodes/KeyValueBox";
 import { PDFBox } from "../views/nodes/PDFBox";
-import { CollectionPDFView } from "../views/collections/CollectionPDFView";
-import { RichTextField } from "../../fields/RichTextField";
-import { CollectionVideoView } from "../views/collections/CollectionVideoView";
-import { StrokeData, InkField } from "../../fields/InkField";
+import { VideoBox } from "../views/nodes/VideoBox";
+import { WebBox } from "../views/nodes/WebBox";
 
 export interface DocumentOptions {
     x?: number;
@@ -137,7 +134,7 @@ export namespace Documents {
                 { x: 0, y: 0, width: 300, height: 300, layoutKeys: [KeyStore.Data] });
     }
     function GetCollectionPrototype(): Document {
-        return collProto ? collProto.MakeDelegate() :
+        return collProto ? collProto :
             collProto = setupPrototypeOptions(collProtoId, "COLLECTION_PROTO", CollectionView.LayoutString("DataKey"),
                 { panx: 0, pany: 0, scale: 1, width: 500, height: 500, layoutKeys: [KeyStore.Data] });
     }
diff --git a/src/client/util/DragManager.ts b/src/client/util/DragManager.ts
index 4a61220a5..c0abec407 100644
--- a/src/client/util/DragManager.ts
+++ b/src/client/util/DragManager.ts
@@ -123,7 +123,7 @@ export namespace DragManager {
         //      however, PDF's have a thumbnail field that contains an image of their canvas.
         //      So we replace the pdf's canvas with the image thumbnail
         const docView: DocumentView = dragData["documentView"];
-        const doc: Document = docView ? docView.props.Document : dragData["document"];
+        const doc: Document = dragData["document"];
 
         if (doc) {
             var pdfBox = dragElement.getElementsByClassName("pdfBox-cont")[0] as HTMLElement;
diff --git a/src/client/views/collections/CollectionFreeFormView.tsx b/src/client/views/collections/CollectionFreeFormView.tsx
index cf9bf9b92..808a22a5d 100644
--- a/src/client/views/collections/CollectionFreeFormView.tsx
+++ b/src/client/views/collections/CollectionFreeFormView.tsx
@@ -79,20 +79,11 @@ export class CollectionFreeFormView extends CollectionViewBase {
         let screenX = de.x - (de.data["xOffset"] as number || 0);
         let screenY = de.y - (de.data["yOffset"] as number || 0);
         const [x, y] = this.getTransform().transformPoint(screenX, screenY);
-        if (!de.data["alias"]) {
-            const docView: DocumentView = de.data["documentView"];
-            let doc: Document = docView ? docView.props.Document : de.data["document"];
-            if (doc) {
-                doc.SetNumber(KeyStore.X, x);
-                doc.SetNumber(KeyStore.Y, y);
-                this.bringToFront(doc);
-            }
-        }
-        else {
-            let newDoc: Document = de.data["newDoc"]
-            newDoc.SetNumber(KeyStore.X, x)
-            newDoc.SetNumber(KeyStore.Y, y)
-            this.bringToFront(newDoc)
+        let doc: Document = de.data["document"];
+        if (doc) {
+            doc.SetNumber(KeyStore.X, x);
+            doc.SetNumber(KeyStore.Y, y);
+            this.bringToFront(doc);
         }
     }
 
diff --git a/src/client/views/collections/CollectionViewBase.tsx b/src/client/views/collections/CollectionViewBase.tsx
index 6725fc2d1..304c44788 100644
--- a/src/client/views/collections/CollectionViewBase.tsx
+++ b/src/client/views/collections/CollectionViewBase.tsx
@@ -46,34 +46,30 @@ export class CollectionViewBase extends React.Component<SubCollectionViewProps>
     @undoBatch
     @action
     protected drop(e: Event, de: DragManager.DropEvent) {
-        const docView: DocumentView = de.data["documentView"]
-        const doc: Document = de.data["document"]
-        if (de.data["alias"]) {
-            let newDoc = docView ? docView.props.Document.CreateAlias() : doc.CreateAlias()
-            de.data["newDoc"] = newDoc
-            let oldDoc = docView ? docView.props.Document : doc
+        let dropDoc: Document = de.data["document"];
+        if (de.data["alias"] && dropDoc) {
+            let oldDoc = dropDoc;
+            de.data["document"] = dropDoc = oldDoc.CreateAlias();
             oldDoc.GetTAsync(KeyStore.Width, NumberField, (f: Opt<NumberField>) => {
                 if (f) {
-                    newDoc.SetNumber(KeyStore.Width, f.Data)
+                    dropDoc.SetNumber(KeyStore.Width, f.Data)
                 }
             })
             oldDoc.GetTAsync(KeyStore.Height, NumberField, (f: Opt<NumberField>) => {
                 if (f) {
-                    newDoc.SetNumber(KeyStore.Height, f.Data)
+                    dropDoc.SetNumber(KeyStore.Height, f.Data)
                 }
             })
-        }
-
-        if (docView && docView.props.ContainingCollectionView && docView.props.ContainingCollectionView !== this.props.CollectionView) {
-            if (docView.props.RemoveDocument && !de.data["alias"]) {
-                docView.props.RemoveDocument(docView.props.Document)
+        } else {
+            const docView: DocumentView = de.data["documentView"];
+            if (docView && docView.props.RemoveDocument && docView.props.ContainingCollectionView !== this.props.CollectionView) {
+                docView.props.RemoveDocument(dropDoc);
+            } else if (dropDoc) {
+                this.props.removeDocument(dropDoc);
             }
-            this.props.addDocument(de.data["alias"] ? de.data["newDoc"] : docView.props.Document)
-        } else if (doc) {
-            if (!de.data["alias"]) {
-                this.props.removeDocument(doc)
-            }
-            this.props.addDocument(de.data["alias"] ? de.data["newDoc"] : doc)
+        }
+        if (dropDoc) {
+            this.props.addDocument(dropDoc);
         }
         e.stopPropagation();
     }
diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx
index ec9db765a..981cabe71 100644
--- a/src/client/views/nodes/DocumentView.tsx
+++ b/src/client/views/nodes/DocumentView.tsx
@@ -160,20 +160,20 @@ export class DocumentView extends React.Component<DocumentViewProps> {
         }
     }
 
-    startDragging(x: number, y: number, ctrlPressed: boolean) {
+    startDragging(x: number, y: number, dropAliasOfDraggedDoc: boolean) {
         if (this._mainCont.current) {
             const [left, top] = this.props.ScreenToLocalTransform().inverse().transformPoint(0, 0);
             let dragData: { [id: string]: any } = {};
             dragData["documentView"] = this;
-            dragData["document"] = this.props.Document
+            dragData["document"] = this.props.Document;
             dragData["xOffset"] = x - left;
             dragData["yOffset"] = y - top;
-            dragData["alias"] = ctrlPressed
+            dragData["alias"] = dropAliasOfDraggedDoc;
             DragManager.StartDrag(this._mainCont.current, dragData, {
                 handlers: {
                     dragComplete: action(() => { }),
                 },
-                hideSource: !ctrlPressed
+                hideSource: !dropAliasOfDraggedDoc
             })
         }
     }
-- 
cgit v1.2.3-70-g09d2


From 54371ab69c87eb6b802f83cc311e3ef7900c4d65 Mon Sep 17 00:00:00 2001
From: Bob Zeleznik <zzzman@gmail.com>
Date: Sun, 17 Mar 2019 23:09:50 -0400
Subject: from last

---
 src/client/views/collections/CollectionViewBase.tsx | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

(limited to 'src/client/views/collections/CollectionViewBase.tsx')

diff --git a/src/client/views/collections/CollectionViewBase.tsx b/src/client/views/collections/CollectionViewBase.tsx
index 304c44788..37ec203b5 100644
--- a/src/client/views/collections/CollectionViewBase.tsx
+++ b/src/client/views/collections/CollectionViewBase.tsx
@@ -50,16 +50,13 @@ export class CollectionViewBase extends React.Component<SubCollectionViewProps>
         if (de.data["alias"] && dropDoc) {
             let oldDoc = dropDoc;
             de.data["document"] = dropDoc = oldDoc.CreateAlias();
-            oldDoc.GetTAsync(KeyStore.Width, NumberField, (f: Opt<NumberField>) => {
-                if (f) {
-                    dropDoc.SetNumber(KeyStore.Width, f.Data)
-                }
-            })
-            oldDoc.GetTAsync(KeyStore.Height, NumberField, (f: Opt<NumberField>) => {
-                if (f) {
-                    dropDoc.SetNumber(KeyStore.Height, f.Data)
-                }
-            })
+            [KeyStore.Width, KeyStore.Height].map(key =>
+                oldDoc.GetTAsync(key, NumberField, (f: Opt<NumberField>) => {
+                    if (f) {
+                        dropDoc.SetNumber(key, f.Data)
+                    }
+                })
+            );
         } else {
             const docView: DocumentView = de.data["documentView"];
             if (docView && docView.props.RemoveDocument && docView.props.ContainingCollectionView !== this.props.CollectionView) {
-- 
cgit v1.2.3-70-g09d2

