diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/.DS_Store | bin | 0 -> 6148 bytes | |||
-rw-r--r-- | src/client/documents/Documents.ts | 42 | ||||
-rw-r--r-- | src/client/views/Main.tsx | 6 | ||||
-rw-r--r-- | src/client/views/nodes/DocumentView.tsx | 3 | ||||
-rw-r--r-- | src/client/views/nodes/FieldView.tsx | 9 | ||||
-rw-r--r-- | src/client/views/nodes/WebBox.scss | 13 | ||||
-rw-r--r-- | src/client/views/nodes/WebBox.tsx | 73 | ||||
-rw-r--r-- | src/fields/BasicField 2.ts | 38 | ||||
-rw-r--r-- | src/fields/WebField.ts | 21 |
9 files changed, 202 insertions, 3 deletions
diff --git a/src/.DS_Store b/src/.DS_Store Binary files differnew file mode 100644 index 000000000..4d6acb95a --- /dev/null +++ b/src/.DS_Store diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts index 15ecfbfe6..398c6f1a2 100644 --- a/src/client/documents/Documents.ts +++ b/src/client/documents/Documents.ts @@ -7,10 +7,17 @@ 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; @@ -77,7 +84,7 @@ export namespace Documents { export function TextDocument(options: DocumentOptions = {}): Document { let doc = GetTextPrototype().MakeDelegate(); setupOptions(doc, options); - // doc.SetField(KeyStore.Data, new RichTextField()); + // doc.Set(KeyStore.Data, new RichTextField()); return doc; } @@ -116,7 +123,7 @@ export namespace Documents { imageProto.Set(KeyStore.Layout, new TextField(CollectionView.LayoutString("AnnotationsKey"))); imageProto.SetNumber(KeyStore.ViewType, CollectionViewType.Freeform) imageProto.Set(KeyStore.BackgroundLayout, new TextField(ImageBox.LayoutString())); - // imageProto.SetField(KeyStore.Layout, new TextField('<div style={"background-image: " + {Data}} />')); + // imageProto.Set(KeyStore.Layout, new TextField('<div style={"background-image: " + {Data}} />')); imageProto.Set(KeyStore.LayoutKeys, new ListField([KeyStore.Data, KeyStore.Annotations])); return imageProto; } @@ -153,6 +160,37 @@ export namespace Documents { return doc; } + let webProtoId: FieldId; + function GetWebPrototype(): Document { + if (webProtoId === undefined) { + let webProto = new Document(); + webProtoId = webProto.Id; + webProto.Set(KeyStore.Title, new TextField("WEB PROTO")); + webProto.Set(KeyStore.X, new NumberField(0)); + webProto.Set(KeyStore.Y, new NumberField(0)); + webProto.Set(KeyStore.NativeWidth, new NumberField(300)); + webProto.Set(KeyStore.NativeHeight, new NumberField(300)); + webProto.Set(KeyStore.Width, new NumberField(300)); + webProto.Set(KeyStore.Height, new NumberField(300)); + webProto.Set(KeyStore.Layout, new TextField(CollectionFreeFormView.LayoutString("AnnotationsKey"))); + webProto.Set(KeyStore.BackgroundLayout, new TextField(WebBox.LayoutString())); + webProto.Set(KeyStore.LayoutKeys, new ListField([KeyStore.Data, KeyStore.Annotations])); + Server.AddDocument(webProto); + return webProto; + } + return Server.GetField(webProtoId) as Document; + } + + export function WebDocument(url: string, options: DocumentOptions = {}): Document { + let doc = GetWebPrototype().MakeDelegate(); + setupOptions(doc, options); + doc.Set(KeyStore.Data, new WebField(new URL(url))); + Server.AddDocument(doc); + var sdoc = Server.GetField(doc.Id) as Document; + console.log(sdoc); + return sdoc; + } + let collectionProto: Document; const collectionProtoId = "collectionProto"; function GetCollectionPrototype(): Document { diff --git a/src/client/views/Main.tsx b/src/client/views/Main.tsx index 61ad66c72..69ded8fa7 100644 --- a/src/client/views/Main.tsx +++ b/src/client/views/Main.tsx @@ -85,6 +85,9 @@ Documents.initProtos(() => { let addImageNode = action(() => Documents.ImageDocument("https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Cat03.jpg/1200px-Cat03.jpg", { width: 200, height: 200, title: "an image of a cat" })); + let addWebNode = action(() => Documents.WebDocument("https://cs.brown.edu/courses/cs166/", { + width: 200, height: 200, title: "an image of a cat" + })); let addClick = (creator: any) => action(() => { var img = creator(); @@ -94,6 +97,7 @@ Documents.initProtos(() => { }); let imgRef = React.createRef<HTMLDivElement>(); + let webRef = React.createRef<HTMLDivElement>(); let textRef = React.createRef<HTMLDivElement>(); let schemaRef = React.createRef<HTMLDivElement>(); let colRef = React.createRef<HTMLDivElement>(); @@ -132,6 +136,8 @@ Documents.initProtos(() => { <ContextMenu /> <div style={{ position: 'absolute', bottom: '0px', left: '0px', width: '150px' }} ref={imgRef} > <button onPointerDown={onRowDown(addImageNode, imgRef)} onClick={addClick(addImageNode)}>Add Image</button></div> + <div style={{ position: 'absolute', bottom: '0px', left: '0px', width: '150px' }} ref={webRef} > + <button onPointerDown={onRowDown(addWebNode, webRef)} onClick={addClick(addWebNode)}>Add Web</button></div> <div style={{ position: 'absolute', bottom: '25px', left: '0px', width: '150px' }} ref={textRef}> <button onPointerDown={onRowDown(addTextNode, textRef)} onClick={addClick(addTextNode)}>Add Text</button></div> <div style={{ position: 'absolute', bottom: '50px', left: '0px', width: '150px' }} ref={colRef}> diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx index 6fe78daee..f4ebfb4d8 100644 --- a/src/client/views/nodes/DocumentView.tsx +++ b/src/client/views/nodes/DocumentView.tsx @@ -16,6 +16,7 @@ import { WebView } from "./WebView"; import { ContextMenu } from "../ContextMenu"; import { FormattedTextBox } from "../nodes/FormattedTextBox"; import { ImageBox } from "../nodes/ImageBox"; +import { WebBox } from "../nodes/WebBox"; import "./DocumentView.scss"; import React = require("react"); const JsxParser = require('react-jsx-parser').default;//TODO Why does this need to be imported like this? @@ -198,7 +199,7 @@ export class DocumentView extends React.Component<DocumentViewProps> { @computed get mainContent() { var val = this.props.Document.Id; return <JsxParser - components={{ FormattedTextBox, ImageBox, CollectionFreeFormView, CollectionDockingView, CollectionSchemaView, CollectionView, WebView }} + components={{ FormattedTextBox, ImageBox, WebBox, CollectionFreeFormView, CollectionDockingView, CollectionSchemaView, CollectionView, WebView }} bindings={this._documentBindings} jsx={this.layout} showWarnings={true} diff --git a/src/client/views/nodes/FieldView.tsx b/src/client/views/nodes/FieldView.tsx index 1a9d325db..368ad049d 100644 --- a/src/client/views/nodes/FieldView.tsx +++ b/src/client/views/nodes/FieldView.tsx @@ -7,11 +7,17 @@ import { TextField } from "../../../fields/TextField"; import { NumberField } from "../../../fields/NumberField"; import { RichTextField } from "../../../fields/RichTextField"; import { ImageField } from "../../../fields/ImageField"; +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. @@ -50,6 +56,9 @@ export class FieldView extends React.Component<FieldViewProps> { else if (field instanceof ImageField) { return <ImageBox {...this.props} /> } + else if (field instanceof WebField) { + return <WebBox {...this.props} /> + } else if (field instanceof NumberField) { return <p>{field.Data}</p> } else if (field instanceof HtmlField) { diff --git a/src/client/views/nodes/WebBox.scss b/src/client/views/nodes/WebBox.scss new file mode 100644 index 000000000..9df984d68 --- /dev/null +++ b/src/client/views/nodes/WebBox.scss @@ -0,0 +1,13 @@ + +.webBox-cont { + padding: 0vw; + position: absolute; + width: 100% +} + +.webBox-button { + padding : 0vw; + border: none; + width : 100%; + height: 100%; +}
\ No newline at end of file diff --git a/src/client/views/nodes/WebBox.tsx b/src/client/views/nodes/WebBox.tsx new file mode 100644 index 000000000..b9d0853b9 --- /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://crossorigin.me/" + "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 diff --git a/src/fields/BasicField 2.ts b/src/fields/BasicField 2.ts new file mode 100644 index 000000000..437024d07 --- /dev/null +++ b/src/fields/BasicField 2.ts @@ -0,0 +1,38 @@ +import { Field } from "./Field" +import { observable, computed, action } from "mobx"; + +export abstract class BasicField<T> extends Field { + constructor(data: T) { + super(); + + this.data = data; + } + + @observable + private data:T; + + @computed + get Data(): T { + return this.data; + } + + set Data(value: T) { + if(this.data === value) { + return; + } + this.data = value; + } + + @action + TrySetValue(value: any): boolean { + if (typeof value == typeof this.data) { + this.Data = value; + return true; + } + return false; + } + + GetValue(): any { + return this.Data; + } +} diff --git a/src/fields/WebField.ts b/src/fields/WebField.ts new file mode 100644 index 000000000..cd3519128 --- /dev/null +++ b/src/fields/WebField.ts @@ -0,0 +1,21 @@ +import { BasicField } from "./BasicField"; +import { Field } from "./Field"; + +export class WebField extends BasicField<URL> { + constructor(data: URL | undefined = undefined) { + super(data == undefined ? new URL("https://crossorigin.me/" + "https://cs.brown.edu/") : data); + } + + toString(): string { + return this.Data.href; + } + + ToScriptString(): string { + return `new WebField("${this.Data}")`; + } + + Copy(): Field { + return new WebField(this.Data); + } + +}
\ No newline at end of file |