diff options
Diffstat (limited to 'src/fields')
| -rw-r--r-- | src/fields/Document.ts | 25 | ||||
| -rw-r--r-- | src/fields/DocumentReference.ts | 11 | ||||
| -rw-r--r-- | src/fields/Field.ts | 26 | ||||
| -rw-r--r-- | src/fields/ImageField.ts | 6 | ||||
| -rw-r--r-- | src/fields/Key.ts | 7 | ||||
| -rw-r--r-- | src/fields/ListField.ts | 4 | ||||
| -rw-r--r-- | src/fields/NumberField.ts | 4 | ||||
| -rw-r--r-- | src/fields/RichTextField.ts | 4 | ||||
| -rw-r--r-- | src/fields/TextField.ts | 4 |
9 files changed, 63 insertions, 28 deletions
diff --git a/src/fields/Document.ts b/src/fields/Document.ts index 3d74c047c..c682d8e94 100644 --- a/src/fields/Document.ts +++ b/src/fields/Document.ts @@ -1,23 +1,22 @@ -import { Field, Cast, Opt, FieldWaiting, FIELD_ID, DOC_ID } from "./Field" +import { Field, Cast, Opt, FieldWaiting, FieldId, FieldValue } from "./Field" import { Key, KeyStore } from "./Key" import { NumberField } from "./NumberField"; import { ObservableMap, computed, action, observable } from "mobx"; import { TextField } from "./TextField"; import { ListField } from "./ListField"; -import { findDOMNode } from "react-dom"; -import { Server } from "../Server"; +import { Server } from "../client/Server"; export class Document extends Field { - public fields: ObservableMap<Key, Opt<Field>> = new ObservableMap(); - public _proxies: ObservableMap<Key, FIELD_ID> = new ObservableMap(); + public fields: ObservableMap<Key, Field> = new ObservableMap(); + public _proxies: ObservableMap<Key, FieldId> = new ObservableMap(); @computed public get Title() { return this.GetText(KeyStore.Title, "<untitled>"); } - Get(key: Key, ignoreProto: boolean = false): Opt<Field> { - let field: Opt<Field>; + Get(key: Key, ignoreProto: boolean = false): FieldValue<Field> { + let field: FieldValue<Field>; if (ignoreProto) { if (this.fields.has(key)) { field = this.fields.get(key); @@ -25,7 +24,7 @@ export class Document extends Field { field = Server.GetDocumentField(this, key); } } else { - let doc: Opt<Document> = this; + let doc: FieldValue<Document> = this; while (doc && doc != FieldWaiting && field != FieldWaiting) { if (!doc.fields.has(key)) { if (doc._proxies.has(key)) { @@ -46,7 +45,7 @@ export class Document extends Field { return field; } - GetT<T extends Field = Field>(key: Key, ctor: { new(...args: any[]): T }, ignoreProto: boolean = false): Opt<T> { + GetT<T extends Field = Field>(key: Key, ctor: { new(...args: any[]): T }, ignoreProto: boolean = false): FieldValue<T> { var getfield = this.Get(key, ignoreProto); if (getfield != FieldWaiting) { return Cast(getfield, ctor); @@ -119,13 +118,13 @@ export class Document extends Field { this.SetData(key, value, NumberField, replaceWrongType); } - GetPrototype(): Opt<Document> { + GetPrototype(): FieldValue<Document> { return this.GetT(KeyStore.Prototype, Document, true); } GetAllPrototypes(): Document[] { let protos: Document[] = []; - let doc: Opt<Document> = this; + let doc: FieldValue<Document> = this; while (doc && doc != FieldWaiting) { protos.push(doc); doc = doc.GetPrototype(); @@ -141,6 +140,10 @@ export class Document extends Field { return delegate; } + ToScriptString(): string { + return ""; + } + TrySetValue(value: any): boolean { throw new Error("Method not implemented."); } diff --git a/src/fields/DocumentReference.ts b/src/fields/DocumentReference.ts index 10dac9f92..983b162a3 100644 --- a/src/fields/DocumentReference.ts +++ b/src/fields/DocumentReference.ts @@ -1,4 +1,4 @@ -import { Field, Opt } from "./Field"; +import { Field, Opt, FieldValue } from "./Field"; import { Document } from "./Document"; import { Key } from "./Key"; @@ -15,12 +15,12 @@ export class DocumentReference extends Field { super(); } - Dereference(): Opt<Field> { + Dereference(): FieldValue<Field> { return this.document.Get(this.key); } - DereferenceToRoot(): Opt<Field> { - let field: Opt<Field> = this; + DereferenceToRoot(): FieldValue<Field> { + let field: FieldValue<Field> = this; while (field instanceof DocumentReference) { field = field.Dereference(); } @@ -37,5 +37,8 @@ export class DocumentReference extends Field { throw new Error("Method not implemented."); } + ToScriptString(): string { + return ""; + } }
\ No newline at end of file diff --git a/src/fields/Field.ts b/src/fields/Field.ts index 9880116c0..4a3968699 100644 --- a/src/fields/Field.ts +++ b/src/fields/Field.ts @@ -1,7 +1,7 @@ import { Utils } from "../Utils"; -export function Cast<T extends Field>(field: Opt<Field>, ctor: { new(): T }): Opt<T> { +export function Cast<T extends Field>(field: FieldValue<Field>, ctor: { new(): T }): Opt<T> { if (field) { if (ctor && field instanceof ctor) { return field; @@ -10,36 +10,36 @@ export function Cast<T extends Field>(field: Opt<Field>, ctor: { new(): T }): Op return undefined; } -export let FieldWaiting: FIELD_WAITING = "<Waiting>"; +export const FieldWaiting: FIELD_WAITING = "<Waiting>"; export type FIELD_WAITING = "<Waiting>"; -export type FIELD_ID = string | undefined; -export type DOC_ID = FIELD_ID; -export type Opt<T> = T | undefined | FIELD_WAITING; +export type FieldId = string; +export type Opt<T> = T | undefined; +export type FieldValue<T> = Opt<T> | FIELD_WAITING; export abstract class Field { //FieldUpdated: TypedEvent<Opt<FieldUpdatedArgs>> = new TypedEvent<Opt<FieldUpdatedArgs>>(); - private id: FIELD_ID; - get Id(): FIELD_ID { + private id: FieldId; + get Id(): FieldId { return this.id; } - constructor(id: FIELD_ID = undefined) { + constructor(id: Opt<FieldId> = undefined) { this.id = id || Utils.GenerateGuid(); } - Dereference(): Opt<Field> { + Dereference(): FieldValue<Field> { return this; } - DereferenceToRoot(): Opt<Field> { + DereferenceToRoot(): FieldValue<Field> { return this; } - DereferenceT<T extends Field = Field>(ctor: { new(): T }): Opt<T> { + DereferenceT<T extends Field = Field>(ctor: { new(): T }): FieldValue<T> { return Cast(this.Dereference(), ctor); } - DereferenceToRootT<T extends Field = Field>(ctor: { new(): T }): Opt<T> { + DereferenceToRootT<T extends Field = Field>(ctor: { new(): T }): FieldValue<T> { return Cast(this.DereferenceToRoot(), ctor); } @@ -47,6 +47,8 @@ export abstract class Field { return this.id === other.id; } + abstract ToScriptString(): string; + abstract TrySetValue(value: any): boolean; abstract GetValue(): any; diff --git a/src/fields/ImageField.ts b/src/fields/ImageField.ts index bc2e7cdf4..d82260f54 100644 --- a/src/fields/ImageField.ts +++ b/src/fields/ImageField.ts @@ -3,13 +3,17 @@ import { Field } from "./Field"; export class ImageField extends BasicField<URL> { constructor(data: URL | undefined = undefined) { - super(data == undefined ? new URL("http://cs.brown.edu/~bcz/face.gif") : data); + super(data == undefined ? new URL("http://cs.brown.edu/~bcz/bob_fettucine.jpg") : data); } toString(): string { return this.Data.href; } + ToScriptString(): string { + return `new ImageField("${this.Data}")`; + } + Copy(): Field { return new ImageField(this.Data); } diff --git a/src/fields/Key.ts b/src/fields/Key.ts index 5cd43f55e..8d92b89b6 100644 --- a/src/fields/Key.ts +++ b/src/fields/Key.ts @@ -27,6 +27,9 @@ export class Key extends Field { return this; } + ToScriptString(): string { + return name; + } } @@ -39,11 +42,15 @@ export namespace KeyStore { export const PanX = new Key("PanX"); export const PanY = new Key("PanY"); export const Scale = new Key("Scale"); + export const NativeWidth = new Key("NativeWidth"); + export const NativeHeight = new Key("NativeHeight"); export const Width = new Key("Width"); export const Height = new Key("Height"); export const ZIndex = new Key("ZIndex"); export const Data = new Key("Data"); + export const Annotations = new Key("Annotations"); export const Layout = new Key("Layout"); + export const BackgroundLayout = new Key("BackgroundLayout"); export const LayoutKeys = new Key("LayoutKeys"); export const LayoutFields = new Key("LayoutFields"); export const ColumnsKey = new Key("SchemaColumns"); diff --git a/src/fields/ListField.ts b/src/fields/ListField.ts index 8607ebe43..8843338c1 100644 --- a/src/fields/ListField.ts +++ b/src/fields/ListField.ts @@ -6,6 +6,10 @@ export class ListField<T extends Field> extends BasicField<T[]> { super(data.slice()); } + ToScriptString(): string { + return "new ListField([" + this.Data.map(field => field.ToScriptString()).join(", ") + "])"; + } + Copy(): Field { return new ListField<T>(this.Data); } diff --git a/src/fields/NumberField.ts b/src/fields/NumberField.ts index c3444f644..03926d696 100644 --- a/src/fields/NumberField.ts +++ b/src/fields/NumberField.ts @@ -5,6 +5,10 @@ export class NumberField extends BasicField<number> { super(data); } + ToScriptString(): string { + return "new NumberField(this.Data)"; + } + Copy() { return new NumberField(this.Data); } diff --git a/src/fields/RichTextField.ts b/src/fields/RichTextField.ts index 24c7472d8..4a77c669c 100644 --- a/src/fields/RichTextField.ts +++ b/src/fields/RichTextField.ts @@ -5,6 +5,10 @@ export class RichTextField extends BasicField<string> { super(data); } + ToScriptString(): string { + return `new RichTextField(${this.Data})`; + } + Copy() { return new RichTextField(this.Data); } diff --git a/src/fields/TextField.ts b/src/fields/TextField.ts index 95825d2ae..11d2ed7cd 100644 --- a/src/fields/TextField.ts +++ b/src/fields/TextField.ts @@ -5,6 +5,10 @@ export class TextField extends BasicField<string> { super(data); } + ToScriptString(): string { + return `new TextField("${this.Data}")`; + } + Copy() { return new TextField(this.Data); } |
