diff options
author | Tyler Schicke <tyler_schicke@brown.edu> | 2019-02-09 19:13:24 -0500 |
---|---|---|
committer | Tyler Schicke <tyler_schicke@brown.edu> | 2019-02-09 19:13:24 -0500 |
commit | 11134bc5ce01d0a025d311a4f83e67ff6e63ce1c (patch) | |
tree | e401d8004481b3d664c751ae2e668c72b6be7aac /src/client/documents/Documents.ts | |
parent | c06745a99ed85b215d0ae48bfb2af7c955f0b016 (diff) |
Moved client code to client folder
Diffstat (limited to 'src/client/documents/Documents.ts')
-rw-r--r-- | src/client/documents/Documents.ts | 161 |
1 files changed, 161 insertions, 0 deletions
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts new file mode 100644 index 000000000..6925234fe --- /dev/null +++ b/src/client/documents/Documents.ts @@ -0,0 +1,161 @@ +import { Document } from "../../fields/Document"; +import { Server } from "../Server"; +import { KeyStore } from "../../fields/Key"; +import { TextField } from "../../fields/TextField"; +import { NumberField } from "../../fields/NumberField"; +import { ListField } from "../../fields/ListField"; +import { FormattedTextBox } from "../views/nodes/FormattedTextBox"; +import { CollectionDockingView } from "../views/collections/CollectionDockingView"; +import { CollectionSchemaView } from "../views/collections/CollectionSchemaView"; +import { ImageField } from "../../fields/ImageField"; +import { ImageBox } from "../views/nodes/ImageBox"; +import { CollectionFreeFormView } from "../views/collections/CollectionFreeFormView"; +import { FIELD_ID } from "../../fields/Field"; + +interface DocumentOptions { + x?: number; + y?: number; + width?: number; + height?: number; + title?: string; +} + +export namespace Documents { + function setupOptions(doc: Document, options: DocumentOptions): void { + if (options.x) { + doc.SetData(KeyStore.X, options.x, NumberField); + } + if (options.y) { + doc.SetData(KeyStore.Y, options.y, NumberField); + } + if (options.width) { + doc.SetData(KeyStore.Width, options.width, NumberField); + } + if (options.height) { + doc.SetData(KeyStore.Height, options.height, NumberField); + } + if (options.title) { + doc.SetData(KeyStore.Title, options.title, TextField); + } + doc.SetData(KeyStore.Scale, 1, NumberField); + doc.SetData(KeyStore.PanX, 0, NumberField); + doc.SetData(KeyStore.PanY, 0, NumberField); + } + + let textProto: Document; + function GetTextPrototype(): Document { + if (!textProto) { + textProto = new Document(); + textProto.Set(KeyStore.X, new NumberField(0)); + textProto.Set(KeyStore.Y, new NumberField(0)); + textProto.Set(KeyStore.Width, new NumberField(300)); + textProto.Set(KeyStore.Height, new NumberField(150)); + textProto.Set(KeyStore.Layout, new TextField(FormattedTextBox.LayoutString())); + textProto.Set(KeyStore.LayoutKeys, new ListField([KeyStore.Data])); + } + return textProto; + } + + export function TextDocument(options: DocumentOptions = {}): Document { + let doc = GetTextPrototype().MakeDelegate(); + setupOptions(doc, options); + // doc.SetField(KeyStore.Data, new RichTextField()); + return doc; + } + + let schemaProto: Document; + function GetSchemaPrototype(): Document { + if (!schemaProto) { + schemaProto = new Document(); + schemaProto.Set(KeyStore.X, new NumberField(0)); + schemaProto.Set(KeyStore.Y, new NumberField(0)); + schemaProto.Set(KeyStore.Width, new NumberField(300)); + schemaProto.Set(KeyStore.Height, new NumberField(150)); + schemaProto.Set(KeyStore.Layout, new TextField(CollectionSchemaView.LayoutString())); + schemaProto.Set(KeyStore.LayoutKeys, new ListField([KeyStore.Data])); + } + return schemaProto; + } + + export function SchemaDocument(documents: Array<Document>, options: DocumentOptions = {}): Document { + let doc = GetSchemaPrototype().MakeDelegate(); + setupOptions(doc, options); + doc.Set(KeyStore.Data, new ListField(documents)); + return doc; + } + + + let dockProto: Document; + function GetDockPrototype(): Document { + if (!dockProto) { + dockProto = new Document(); + dockProto.Set(KeyStore.X, new NumberField(0)); + dockProto.Set(KeyStore.Y, new NumberField(0)); + dockProto.Set(KeyStore.Width, new NumberField(300)); + dockProto.Set(KeyStore.Height, new NumberField(150)); + dockProto.Set(KeyStore.Layout, new TextField(CollectionDockingView.LayoutString())); + dockProto.Set(KeyStore.LayoutKeys, new ListField([KeyStore.Data])); + } + return dockProto; + } + + export function DockDocument(documents: Array<Document>, options: DocumentOptions = {}): Document { + let doc = GetDockPrototype().MakeDelegate(); + setupOptions(doc, options); + doc.Set(KeyStore.Data, new ListField(documents)); + return doc; + } + + + let imageProtoId: FIELD_ID; + function GetImagePrototype(): Document { + if (imageProtoId === undefined) { + let imageProto = new Document(); + imageProtoId = imageProto.Id; + imageProto.Set(KeyStore.Title, new TextField("IMAGE PROTO")); + imageProto.Set(KeyStore.X, new NumberField(0)); + imageProto.Set(KeyStore.Y, new NumberField(0)); + imageProto.Set(KeyStore.Width, new NumberField(300)); + imageProto.Set(KeyStore.Height, new NumberField(300)); + imageProto.Set(KeyStore.Layout, new TextField(ImageBox.LayoutString())); + // imageProto.SetField(KeyStore.Layout, new TextField('<div style={"background-image: " + {Data}} />')); + imageProto.Set(KeyStore.LayoutKeys, new ListField([KeyStore.Data])); + Server.AddDocument(imageProto); + return imageProto; + } + return Server.GetField(imageProtoId) as Document; + } + + export function ImageDocument(url: string, options: DocumentOptions = {}): Document { + let doc = GetImagePrototype().MakeDelegate(); + setupOptions(doc, options); + doc.Set(KeyStore.Data, new ImageField(new URL(url))); + Server.AddDocument(doc); + var sdoc = Server.GetField(doc.Id) as Document; + return sdoc; + } + + let collectionProto: Document; + function GetCollectionPrototype(): Document { + if (!collectionProto) { + collectionProto = new Document(); + collectionProto.Set(KeyStore.X, new NumberField(0)); + collectionProto.Set(KeyStore.Y, new NumberField(0)); + collectionProto.Set(KeyStore.Scale, new NumberField(1)); + collectionProto.Set(KeyStore.PanX, new NumberField(0)); + collectionProto.Set(KeyStore.PanY, new NumberField(0)); + collectionProto.Set(KeyStore.Width, new NumberField(300)); + collectionProto.Set(KeyStore.Height, new NumberField(300)); + collectionProto.Set(KeyStore.Layout, new TextField(CollectionFreeFormView.LayoutString())); + collectionProto.Set(KeyStore.LayoutKeys, new ListField([KeyStore.Data])); + } + return collectionProto; + } + + export function CollectionDocument(documents: Array<Document>, options: DocumentOptions = {}): Document { + let doc = GetCollectionPrototype().MakeDelegate(); + setupOptions(doc, options); + doc.Set(KeyStore.Data, new ListField(documents)); + return doc; + } +}
\ No newline at end of file |