diff options
author | Tyler Schicke <tyler_schicke@brown.edu> | 2019-01-17 04:27:26 -0500 |
---|---|---|
committer | Tyler Schicke <tyler_schicke@brown.edu> | 2019-01-17 04:27:26 -0500 |
commit | 7943126ce9694af8e53d2997481c18ca0c17754c (patch) | |
tree | 7c3563e9a07345d1a110e8abb5b8563a3aec90fa /src/documents/Documents.ts | |
parent | 89204d74d2a5014b4e241973b1bdb8461ed4f78c (diff) |
Added editable text and image notes
Diffstat (limited to 'src/documents/Documents.ts')
-rw-r--r-- | src/documents/Documents.ts | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/documents/Documents.ts b/src/documents/Documents.ts new file mode 100644 index 000000000..20d4596fd --- /dev/null +++ b/src/documents/Documents.ts @@ -0,0 +1,71 @@ +import { Document } from "../fields/Document"; +import { KeyStore } from "../fields/Key"; +import { TextField } from "../fields/TextField"; +import { NumberField } from "../fields/NumberField"; +import { ListField } from "../fields/ListField"; + +interface DocumentOptions { + x?: number; + y?: number; + width?: number; + height?: number; +} + +export namespace Documents { + function setupOptions(doc: Document, options: DocumentOptions): void { + if(options.x) { + doc.SetFieldValue(KeyStore.X, options.x, NumberField); + } + if(options.y) { + doc.SetFieldValue(KeyStore.Y, options.y, NumberField); + } + if(options.width) { + doc.SetFieldValue(KeyStore.Width, options.width, NumberField); + } + if(options.height) { + doc.SetFieldValue(KeyStore.Height, options.height, NumberField); + } + } + + let textProto:Document; + function GetTextPrototype(): Document { + if(!textProto) { + textProto = new Document(); + textProto.SetField(KeyStore.X, new NumberField(0)); + textProto.SetField(KeyStore.Y, new NumberField(0)); + textProto.SetField(KeyStore.Width, new NumberField(300)); + textProto.SetField(KeyStore.Height, new NumberField(150)); + textProto.SetField(KeyStore.Layout, new TextField("<FieldTextBox doc={doc} fieldKey={DataKey} />")); + textProto.SetField(KeyStore.LayoutKeys, new ListField([KeyStore.Data])); + } + return textProto; + } + + export function TextDocument(text: string, options:DocumentOptions = {}): Document { + let doc = GetTextPrototype().MakeDelegate(); + setupOptions(doc, options); + doc.SetField(KeyStore.Data, new TextField(text)); + return doc; + } + + let imageProto:Document; + function GetImagePrototype(): Document { + if(!imageProto) { + imageProto = new Document(); + imageProto.SetField(KeyStore.X, new NumberField(0)); + imageProto.SetField(KeyStore.Y, new NumberField(0)); + imageProto.SetField(KeyStore.Width, new NumberField(300)); + imageProto.SetField(KeyStore.Height, new NumberField(300)); + imageProto.SetField(KeyStore.Layout, new TextField('<img src={Data} alt="Image not found"/>')); + imageProto.SetField(KeyStore.LayoutFields, new ListField([KeyStore.Data])); + } + return imageProto; + } + + export function ImageDocument(url: string, options:DocumentOptions = {}): Document { + let doc = GetImagePrototype().MakeDelegate(); + setupOptions(doc, options); + doc.SetField(KeyStore.Data, new TextField(url)); + return doc; + } +}
\ No newline at end of file |