From 1d667d19f5402dc9f9069e0a57008dac96f6de2a Mon Sep 17 00:00:00 2001
From: madelinegr <mgriswold99@gmail.com>
Date: Tue, 12 Feb 2019 18:55:11 -0500
Subject: set up web box classes

---
 src/client/views/nodes/WebBox.tsx | 73 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 73 insertions(+)
 create mode 100644 src/client/views/nodes/WebBox.tsx

(limited to 'src/client/views/nodes/WebBox.tsx')

diff --git a/src/client/views/nodes/WebBox.tsx b/src/client/views/nodes/WebBox.tsx
new file mode 100644
index 000000000..f50f8c60e
--- /dev/null
+++ b/src/client/views/nodes/WebBox.tsx
@@ -0,0 +1,73 @@
+
+import Lightbox from 'react-image-lightbox';
+import { SelectionManager } from "../../util/SelectionManager";
+import "./WebBox.scss";
+import React = require("react")
+import { WebField } from '../../../fields/WebField';
+import { FieldViewProps, FieldView } from './FieldView';
+import { CollectionFreeFormDocumentView } from './CollectionFreeFormDocumentView';
+import { FieldWaiting } from '../../../fields/Field';
+import { observer } from "mobx-react"
+import { observable, action, spy } from 'mobx';
+import { KeyStore } from '../../../fields/Key';
+
+@observer
+export class WebBox extends React.Component<FieldViewProps> {
+
+    public static LayoutString() { return FieldView.LayoutString("WebBox"); }
+    private _ref: React.RefObject<HTMLDivElement>;
+    private _downX: number = 0;
+    private _downY: number = 0;
+    private _lastTap: number = 0;
+    @observable private _isOpen: boolean = false;
+
+    constructor(props: FieldViewProps) {
+        super(props);
+
+        this._ref = React.createRef();
+        this.state = {
+            isOpen: false,
+        };
+    }
+
+    componentDidMount() {
+    }
+
+    componentWillUnmount() {
+    }
+
+    onPointerDown = (e: React.PointerEvent): void => {
+        if (Date.now() - this._lastTap < 300) {
+            if (e.buttons === 1 && this.props.DocumentViewForField instanceof CollectionFreeFormDocumentView &&
+                SelectionManager.IsSelected(this.props.DocumentViewForField)) {
+                e.stopPropagation();
+                this._downX = e.clientX;
+                this._downY = e.clientY;
+                document.removeEventListener("pointerup", this.onPointerUp);
+                document.addEventListener("pointerup", this.onPointerUp);
+            }
+        } else {
+            this._lastTap = Date.now();
+        }
+    }
+    @action
+    onPointerUp = (e: PointerEvent): void => {
+        document.removeEventListener("pointerup", this.onPointerUp);
+        if (Math.abs(e.clientX - this._downX) < 2 && Math.abs(e.clientY - this._downY) < 2) {
+            this._isOpen = true;
+        }
+        e.stopPropagation();
+    }
+
+    render() {
+        let field = this.props.doc.Get(this.props.fieldKey);
+        let path = field == FieldWaiting ? "https://image.flaticon.com/icons/svg/66/66163.svg" :
+            field instanceof WebField ? field.Data.href : "https://cs.brown.edu/";
+        let nativeWidth = this.props.doc.GetNumber(KeyStore.NativeWidth, 1);
+
+        return (
+            <div className="webBox-cont" onPointerDown={this.onPointerDown} ref={this._ref}   >
+                <iframe src={path} width={nativeWidth}></iframe>
+            </div>)
+    }
+}
\ No newline at end of file
-- 
cgit v1.2.3-70-g09d2


From 281f6268238c4f9f1640899ce258535ad4fe2401 Mon Sep 17 00:00:00 2001
From: madelinegr <mgriswold99@gmail.com>
Date: Mon, 18 Feb 2019 18:01:47 -0500
Subject: tried to get around cors with crossorigin.me

---
 src/client/views/Main.tsx         | 2 +-
 src/client/views/nodes/WebBox.tsx | 2 +-
 src/fields/WebField.ts            | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

(limited to 'src/client/views/nodes/WebBox.tsx')

diff --git a/src/client/views/Main.tsx b/src/client/views/Main.tsx
index 3e5118379..f310be950 100644
--- a/src/client/views/Main.tsx
+++ b/src/client/views/Main.tsx
@@ -79,7 +79,7 @@ document.addEventListener("pointerdown", action(function (e: PointerEvent) {
     // mainNodes.Data.push(doc2);
     mainNodes.Data.push(doc6);
 
-    let doc9 = Documents.WebDocument("https://cs.brown.edu/", {
+    let doc9 = Documents.WebDocument("https://crossorigin.me/https://google.com", {
         x: 450, y: 100, title: "cat 1", width: 606, height: 386, nativeWidth: 606, nativeHeight: 386
     });
     mainNodes.Data.push(doc9);
diff --git a/src/client/views/nodes/WebBox.tsx b/src/client/views/nodes/WebBox.tsx
index f50f8c60e..b9d0853b9 100644
--- a/src/client/views/nodes/WebBox.tsx
+++ b/src/client/views/nodes/WebBox.tsx
@@ -62,7 +62,7 @@ export class WebBox extends React.Component<FieldViewProps> {
     render() {
         let field = this.props.doc.Get(this.props.fieldKey);
         let path = field == FieldWaiting ? "https://image.flaticon.com/icons/svg/66/66163.svg" :
-            field instanceof WebField ? field.Data.href : "https://cs.brown.edu/";
+            field instanceof WebField ? field.Data.href : "https://crossorigin.me/" + "https://cs.brown.edu";
         let nativeWidth = this.props.doc.GetNumber(KeyStore.NativeWidth, 1);
 
         return (
diff --git a/src/fields/WebField.ts b/src/fields/WebField.ts
index 88e6130e0..cd3519128 100644
--- a/src/fields/WebField.ts
+++ b/src/fields/WebField.ts
@@ -3,7 +3,7 @@ import { Field } from "./Field";
 
 export class WebField extends BasicField<URL> {
     constructor(data: URL | undefined = undefined) {
-        super(data == undefined ? new URL("https://cs.brown.edu/") : data);
+        super(data == undefined ? new URL("https://crossorigin.me/" + "https://cs.brown.edu/") : data);
     }
 
     toString(): string {
-- 
cgit v1.2.3-70-g09d2


From efe5d9515c88f6e0963ae1c04545b7bbbd8beb55 Mon Sep 17 00:00:00 2001
From: madelinegr <mgriswold99@gmail.com>
Date: Mon, 25 Feb 2019 17:51:40 -0500
Subject: fixed some of bugs caused by pulling from master

---
 src/client/documents/Documents.ts    | 27 ---------------------------
 src/client/views/nodes/FieldView.tsx |  5 -----
 src/client/views/nodes/WebBox.tsx    |  8 ++++----
 src/fields/WebField.ts               | 15 ++++++++++++---
 src/server/Message.ts                |  2 +-
 5 files changed, 17 insertions(+), 40 deletions(-)

(limited to 'src/client/views/nodes/WebBox.tsx')

diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts
index 398c6f1a2..5c73c6b87 100644
--- a/src/client/documents/Documents.ts
+++ b/src/client/documents/Documents.ts
@@ -7,17 +7,12 @@ import { ListField } from "../../fields/ListField";
 import { FormattedTextBox } from "../views/nodes/FormattedTextBox";
 import { ImageField } from "../../fields/ImageField";
 import { ImageBox } from "../views/nodes/ImageBox";
-<<<<<<< HEAD
 import { WebField } from "../../fields/WebField";
 import { WebBox } from "../views/nodes/WebBox";
 import { CollectionFreeFormView } from "../views/collections/CollectionFreeFormView";
 import { FieldId } from "../../fields/Field";
-=======
 import { CollectionView, CollectionViewType } from "../views/collections/CollectionView";
 import { FieldView } from "../views/nodes/FieldView";
-import { HtmlField } from "../../fields/HtmlField";
-import { WebView } from "../views/nodes/WebView";
->>>>>>> bb418216efa9cc2e191b970e4cbe5080f4fd2b87
 
 export interface DocumentOptions {
     x?: number;
@@ -88,28 +83,6 @@ export namespace Documents {
         return doc;
     }
 
-    let htmlProto: Document;
-    const htmlProtoId = "htmlProto";
-    function GetHtmlPrototype(): Document {
-        if (!htmlProto) {
-            htmlProto = new Document(htmlProtoId);
-            htmlProto.Set(KeyStore.X, new NumberField(0));
-            htmlProto.Set(KeyStore.Y, new NumberField(0));
-            htmlProto.Set(KeyStore.Width, new NumberField(300));
-            htmlProto.Set(KeyStore.Height, new NumberField(150));
-            htmlProto.Set(KeyStore.Layout, new TextField(WebView.LayoutString()));
-            htmlProto.Set(KeyStore.LayoutKeys, new ListField([KeyStore.Data]));
-        }
-        return htmlProto;
-    }
-
-    export function HtmlDocument(html: string, options: DocumentOptions = {}): Document {
-        let doc = GetHtmlPrototype().MakeDelegate();
-        setupOptions(doc, options);
-        doc.Set(KeyStore.Data, new HtmlField(html));
-        return doc;
-    }
-
     let imageProto: Document;
     const imageProtoId = "imageProto";
     function GetImagePrototype(): Document {
diff --git a/src/client/views/nodes/FieldView.tsx b/src/client/views/nodes/FieldView.tsx
index 368ad049d..978cfe196 100644
--- a/src/client/views/nodes/FieldView.tsx
+++ b/src/client/views/nodes/FieldView.tsx
@@ -11,13 +11,10 @@ import { WebField } from "../../../fields/WebField";
 import { Key } from "../../../fields/Key";
 import { FormattedTextBox } from "./FormattedTextBox";
 import { ImageBox } from "./ImageBox";
-<<<<<<< HEAD
 import { WebBox } from "./WebBox";
 import { DocumentView } from "./DocumentView";
-=======
 import { HtmlField } from "../../../fields/HtmlField";
 import { WebView } from "./WebView";
->>>>>>> bb418216efa9cc2e191b970e4cbe5080f4fd2b87
 
 //
 // these properties get assigned through the render() method of the DocumentView when it creates this node.
@@ -61,8 +58,6 @@ export class FieldView extends React.Component<FieldViewProps> {
         }
         else if (field instanceof NumberField) {
             return <p>{field.Data}</p>
-        } else if (field instanceof HtmlField) {
-            return <WebView {...this.props} />
         } else if (field != FieldWaiting) {
             return <p>{field.GetValue}</p>
         } else
diff --git a/src/client/views/nodes/WebBox.tsx b/src/client/views/nodes/WebBox.tsx
index b9d0853b9..4f774bae2 100644
--- a/src/client/views/nodes/WebBox.tsx
+++ b/src/client/views/nodes/WebBox.tsx
@@ -9,12 +9,12 @@ import { CollectionFreeFormDocumentView } from './CollectionFreeFormDocumentView
 import { FieldWaiting } from '../../../fields/Field';
 import { observer } from "mobx-react"
 import { observable, action, spy } from 'mobx';
-import { KeyStore } from '../../../fields/Key';
+import { KeyStore } from '../../../fields/KeyStore';
 
 @observer
 export class WebBox extends React.Component<FieldViewProps> {
 
-    public static LayoutString() { return FieldView.LayoutString("WebBox"); }
+    public static LayoutString() { return FieldView.LayoutString(WebBox); }
     private _ref: React.RefObject<HTMLDivElement>;
     private _downX: number = 0;
     private _downY: number = 0;
@@ -38,8 +38,7 @@ export class WebBox extends React.Component<FieldViewProps> {
 
     onPointerDown = (e: React.PointerEvent): void => {
         if (Date.now() - this._lastTap < 300) {
-            if (e.buttons === 1 && this.props.DocumentViewForField instanceof CollectionFreeFormDocumentView &&
-                SelectionManager.IsSelected(this.props.DocumentViewForField)) {
+            if (e.buttons === 1 && this.props.isSelected()) {
                 e.stopPropagation();
                 this._downX = e.clientX;
                 this._downY = e.clientY;
@@ -50,6 +49,7 @@ export class WebBox extends React.Component<FieldViewProps> {
             this._lastTap = Date.now();
         }
     }
+
     @action
     onPointerUp = (e: PointerEvent): void => {
         document.removeEventListener("pointerup", this.onPointerUp);
diff --git a/src/fields/WebField.ts b/src/fields/WebField.ts
index cd3519128..8f945d686 100644
--- a/src/fields/WebField.ts
+++ b/src/fields/WebField.ts
@@ -1,9 +1,10 @@
 import { BasicField } from "./BasicField";
-import { Field } from "./Field";
+import { Field, FieldId } from "./Field";
+import { Types } from "../server/Message";
 
 export class WebField extends BasicField<URL> {
-    constructor(data: URL | undefined = undefined) {
-        super(data == undefined ? new URL("https://crossorigin.me/" + "https://cs.brown.edu/") : data);
+    constructor(data: URL | undefined = undefined, id?: FieldId, save: boolean = true) {
+        super(data == undefined ? new URL("https://crossorigin.me/" + "https://cs.brown.edu/") : data, save, id);
     }
 
     toString(): string {
@@ -18,4 +19,12 @@ export class WebField extends BasicField<URL> {
         return new WebField(this.Data);
     }
 
+    ToJson(): { type: Types, data: URL, _id: string } {
+        return {
+            type: Types.Web,
+            data: this.Data,
+            _id: this.Id
+        }
+    }
+
 }
\ No newline at end of file
diff --git a/src/server/Message.ts b/src/server/Message.ts
index 80fc9a80d..148e6e723 100644
--- a/src/server/Message.ts
+++ b/src/server/Message.ts
@@ -45,7 +45,7 @@ export class GetFieldArgs {
 }
 
 export enum Types {
-    Number, List, Key, Image, Document, Text, RichText, DocumentReference, Html
+    Number, List, Key, Image, Web, Document, Text, RichText, DocumentReference, Html
 }
 
 export class DocumentTransfer implements Transferable {
-- 
cgit v1.2.3-70-g09d2


From 2d4e1ac97f87c3e5a7be58291542829d68a19669 Mon Sep 17 00:00:00 2001
From: Bob Zeleznik <zzzman@gmail.com>
Date: Tue, 26 Feb 2019 19:35:26 -0500
Subject: simplified WebBox.

---
 src/client/views/nodes/WebBox.tsx | 50 +++------------------------------------
 src/fields/Document.ts            |  5 ++++
 2 files changed, 8 insertions(+), 47 deletions(-)

(limited to 'src/client/views/nodes/WebBox.tsx')

diff --git a/src/client/views/nodes/WebBox.tsx b/src/client/views/nodes/WebBox.tsx
index 0a198f059..2ca8d49ce 100644
--- a/src/client/views/nodes/WebBox.tsx
+++ b/src/client/views/nodes/WebBox.tsx
@@ -4,63 +4,19 @@ import { WebField } from '../../../fields/WebField';
 import { FieldViewProps, FieldView } from './FieldView';
 import { FieldWaiting } from '../../../fields/Field';
 import { observer } from "mobx-react"
-import { observable, action, spy, computed } from 'mobx';
+import { computed } from 'mobx';
 import { KeyStore } from '../../../fields/KeyStore';
-import { HtmlField } from "../../../fields/HtmlField";
 
 @observer
 export class WebBox extends React.Component<FieldViewProps> {
 
     public static LayoutString() { return FieldView.LayoutString(WebBox); }
-    private _ref: React.RefObject<HTMLDivElement>;
-    private _downX: number = 0;
-    private _downY: number = 0;
-    private _lastTap: number = 0;
-    @observable private _isOpen: boolean = false;
 
     constructor(props: FieldViewProps) {
         super(props);
-
-        this._ref = React.createRef();
-        this.state = {
-            isOpen: false,
-        };
-    }
-
-    componentDidMount() {
-    }
-
-    componentWillUnmount() {
-    }
-
-    onPointerDown = (e: React.PointerEvent): void => {
-        if (Date.now() - this._lastTap < 300) {
-            if (e.buttons === 1 && this.props.isSelected()) {
-                e.stopPropagation();
-                this._downX = e.clientX;
-                this._downY = e.clientY;
-                document.removeEventListener("pointerup", this.onPointerUp);
-                document.addEventListener("pointerup", this.onPointerUp);
-            }
-        } else {
-            this._lastTap = Date.now();
-        }
-    }
-
-    @action
-    onPointerUp = (e: PointerEvent): void => {
-        document.removeEventListener("pointerup", this.onPointerUp);
-        if (Math.abs(e.clientX - this._downX) < 2 && Math.abs(e.clientY - this._downY) < 2) {
-            this._isOpen = true;
-        }
-        e.stopPropagation();
-    }
-
-    @computed
-    get html(): string {
-        return this.props.doc.GetData(KeyStore.Data, HtmlField, "" as string);
     }
 
+    @computed get html(): string { return this.props.doc.GetHtml(KeyStore.Data, ""); }
 
     render() {
         let field = this.props.doc.Get(this.props.fieldKey);
@@ -75,7 +31,7 @@ export class WebBox extends React.Component<FieldViewProps> {
             </div>;
 
         return (
-            <div className="webBox-cont" onPointerDown={this.onPointerDown} ref={this._ref}   >
+            <div className="webBox-cont"  >
                 {content}
             </div>)
     }
diff --git a/src/fields/Document.ts b/src/fields/Document.ts
index 6193ea56c..5b91de6ed 100644
--- a/src/fields/Document.ts
+++ b/src/fields/Document.ts
@@ -8,6 +8,7 @@ import { ListField } from "./ListField";
 import { Server } from "../client/Server";
 import { Types } from "../server/Message";
 import { UndoManager } from "../client/util/UndoManager";
+import { HtmlField } from "./HtmlField";
 
 export class Document extends Field {
     public fields: ObservableMap<string, { key: Key, field: Field }> = new ObservableMap();
@@ -125,6 +126,10 @@ export class Document extends Field {
         return vval;
     }
 
+    GetHtml(key: Key, defaultVal: string): string {
+        return this.GetData(key, HtmlField, defaultVal);
+    }
+
     GetNumber(key: Key, defaultVal: number): number {
         return this.GetData(key, NumberField, defaultVal);
     }
-- 
cgit v1.2.3-70-g09d2

