aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Main.tsx31
-rw-r--r--src/Server.tsx84
-rw-r--r--src/documents/Documents.ts114
-rw-r--r--src/fields/Document.ts134
-rw-r--r--src/fields/DocumentReference.ts2
-rw-r--r--src/fields/Field.ts14
-rw-r--r--src/fields/RichTextField.ts3
-rw-r--r--src/util/Scripting.ts47
-rw-r--r--src/views/collections/CollectionDockingView.tsx20
-rw-r--r--src/views/collections/CollectionFreeFormView.tsx63
-rw-r--r--src/views/collections/CollectionSchemaView.tsx5
-rw-r--r--src/views/collections/CollectionViewBase.tsx8
-rw-r--r--src/views/nodes/CollectionFreeFormDocumentView.tsx25
-rw-r--r--src/views/nodes/DocumentView.tsx46
-rw-r--r--src/views/nodes/FieldView.tsx6
-rw-r--r--src/views/nodes/FormattedTextBox.tsx22
-rw-r--r--src/views/nodes/ImageBox.tsx8
17 files changed, 378 insertions, 254 deletions
diff --git a/src/Main.tsx b/src/Main.tsx
index de4a1de5d..6730cf799 100644
--- a/src/Main.tsx
+++ b/src/Main.tsx
@@ -12,6 +12,8 @@ import { TextField } from './fields/TextField';
import "./Main.scss";
import { ContextMenu } from './views/ContextMenu';
import { DocumentView } from './views/nodes/DocumentView';
+import { CompileScript } from './util/Scripting';
+
configure({
enforceActions: "observed"
@@ -39,25 +41,25 @@ document.addEventListener("pointerdown", action(function (e: PointerEvent) {
{
let doc1 = Documents.TextDocument({ title: "hello" });
let doc2 = doc1.MakeDelegate();
- doc2.SetField(KS.X, new NumberField(150));
- doc2.SetField(KS.Y, new NumberField(20));
+ doc2.Set(KS.X, new NumberField(150));
+ doc2.Set(KS.Y, new NumberField(20));
let doc3 = Documents.ImageDocument("https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Cat03.jpg/1200px-Cat03.jpg", {
x: 450, y: 500, title: "cat 1"
});
- const schemaDocs = Array.from(Array(5).keys()).map(v => Documents.ImageDocument("https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Cat03.jpg/1200px-Cat03.jpg", {
- x: 50 + 100 * v, y: 50, width: 100, height: 100, title: "cat" + v
- }));
- schemaDocs[0].SetFieldValue(KS.Author, "Tyler", TextField);
- schemaDocs[4].SetFieldValue(KS.Author, "Bob", TextField);
- schemaDocs.push(doc2);
- const doc7 = Documents.SchemaDocument(schemaDocs)
+ // const schemaDocs = Array.from(Array(5).keys()).map(v => Documents.ImageDocument("https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Cat03.jpg/1200px-Cat03.jpg", {
+ // x: 50 + 100 * v, y: 50, width: 100, height: 100, title: "cat" + v
+ // }));
+ // schemaDocs[0].SetData(KS.Author, "Tyler", TextField);
+ // schemaDocs[4].SetData(KS.Author, "Bob", TextField);
+ // schemaDocs.push(doc2);
+ // const doc7 = Documents.SchemaDocument(schemaDocs)
const docset = [doc3]; // [doc1, doc2, doc3, doc7];
let doc4 = Documents.CollectionDocument(docset, {
x: 0, y: 400, title: "mini collection"
});
- let doc5 = Documents.ImageDocument("https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Cat03.jpg/1200px-Cat03.jpg", {
- x: 650, y: 500, width: 600, height: 600, title: "cat 2"
- });
+ // let doc5 = Documents.ImageDocument("https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Cat03.jpg/1200px-Cat03.jpg", {
+ // x: 650, y: 500, width: 600, height: 600, title: "cat 2"
+ // });
let docset2 = new Array<Document>(doc4);//, doc1, doc3);
let doc6 = Documents.CollectionDocument(docset2, {
x: 350, y: 100, width: 600, height: 600, title: "docking collection"
@@ -69,13 +71,14 @@ document.addEventListener("pointerdown", action(function (e: PointerEvent) {
// mainNodes.Data.push(doc6);
// mainNodes.Data.push(doc2);
mainNodes.Data.push(doc4);
- // mainNodes.Data.push(doc3);
+ mainNodes.Data.push(doc3);
// mainNodes.Data.push(doc5);
// mainNodes.Data.push(doc1);
//mainNodes.Data.push(doc2);
//mainNodes.Data.push(doc6);
- mainContainer.SetField(KeyStore.Data, mainNodes);
+ mainContainer.Set(KeyStore.Data, mainNodes);
}
+//}
//);
ReactDOM.render((
diff --git a/src/Server.tsx b/src/Server.tsx
new file mode 100644
index 000000000..2f8135ed0
--- /dev/null
+++ b/src/Server.tsx
@@ -0,0 +1,84 @@
+import { Field, FieldWaiting, FIELD_ID, DOC_ID, FIELD_WAITING } from "./fields/Field"
+import { Key, KeyStore } from "./fields/Key"
+import { ObservableMap, computed, action, observable } from "mobx";
+import { Document } from "./fields/Document"
+import { TextField } from "./fields/TextField";
+
+export class Server {
+ static FieldStore: ObservableMap<FIELD_ID, Field> = new ObservableMap();
+ static DocumentStore: ObservableMap<DOC_ID, ObservableMap<Key, FIELD_ID>> = new ObservableMap();
+ public static ClientFieldsWaiting: ObservableMap<FIELD_ID, boolean> = new ObservableMap();
+ public static ClientFieldsCached: ObservableMap<DOC_ID, Field | FIELD_WAITING> = new ObservableMap();
+
+ public static GetDocument(docid: DOC_ID) {
+ if (this.ClientFieldsCached.has(docid))
+ return this.ClientFieldsCached.get(docid) as Document;
+
+ if (this.DocumentStore.has(docid)) {
+ var clientDoc = new Document(docid);
+ this.cacheFieldInstance(clientDoc);
+ return clientDoc; // bcz: careful ... this assumes the document is on the server. if it's not, the client will have a document with no backing store.
+ }
+ }
+
+ public static AddDocument(document: Document) {
+ this.DocumentStore.set(document.Id, new ObservableMap());
+ document.fields.forEach((field, key) => {
+ this.FieldStore.set((field as Field).Id, (field as Field));
+ this.DocumentStore.get(document.Id)!.set(key, (field as Field).Id);
+ });
+ }
+ public static AddDocumentField(doc: Document, key: Key, value: Field) {
+ if (this.DocumentStore.get(doc.Id))
+ this.DocumentStore.get(doc.Id)!.set(key, value.Id);
+ }
+ public static DeleteDocumentField(doc: Document, key: Key) {
+ if (this.DocumentStore.get(doc.Id))
+ this.DocumentStore.get(doc.Id)!.delete(key);
+ }
+ public static SetFieldValue(field: Field, value: any) {
+ if (this.FieldStore.get(field.Id))
+ this.FieldStore.get(field.Id)!.TrySetValue(value);
+ }
+
+ @action
+ public static GetDocumentField(doc: Document, key: Key) {
+ var fieldid = doc._proxies.get(key);
+ if (!this.ClientFieldsCached.has(fieldid)) {
+ this.ClientFieldsCached.set(fieldid, FieldWaiting);
+
+ // replace this block with appropriate callback-style fetch code from actual server
+ setTimeout(action(() => {
+ var fieldfromserver = this.FieldStore.get(fieldid);
+ this.ClientFieldsWaiting.delete(fieldid);
+ doc._proxies.delete(key);
+ fieldfromserver = this.cacheFieldInstance(fieldfromserver!);
+ doc.fields.set(key, fieldfromserver);
+ }),
+ key == KeyStore.Data ? (this.times++ == 0 ? 5000 : 1000) : key == KeyStore.X ? 2500 : 500
+ )
+ }
+ return this.ClientFieldsCached.get(fieldid);
+ }
+ static times = 0; // hack for testing
+
+ @action
+ static cacheFieldInstance(clientField: Field) {
+ var cached = this.ClientFieldsCached.get(clientField.Id);
+ if (!cached || cached == FieldWaiting) {
+ this.ClientFieldsCached.set(clientField.Id, clientField);
+
+ // if the field is a document, then we need to inquire all of its fields from the server...
+ if (clientField instanceof Document) {
+ clientField.Set(KeyStore.Title, new TextField(clientField.Title));
+ setTimeout(action(() => {
+ var clientDocFields = this.DocumentStore.get(clientField.Id);
+ clientDocFields!.forEach((field: FIELD_ID, key: Key) => clientField._proxies.set(key, field));
+ }
+ ),
+ 1500);
+ }
+ }
+ return this.ClientFieldsCached.get(clientField.Id) as Field;
+ }
+}
diff --git a/src/documents/Documents.ts b/src/documents/Documents.ts
index ae6ae9833..2ad6b64c3 100644
--- a/src/documents/Documents.ts
+++ b/src/documents/Documents.ts
@@ -1,4 +1,5 @@
import { Document } from "../fields/Document";
+import { Server } from "../Server";
import { KeyStore } from "../fields/Key";
import { TextField } from "../fields/TextField";
import { NumberField } from "../fields/NumberField";
@@ -7,9 +8,9 @@ import { FormattedTextBox } from "../views/nodes/FormattedTextBox";
import { CollectionDockingView } from "../views/collections/CollectionDockingView";
import { CollectionSchemaView } from "../views/collections/CollectionSchemaView";
import { ImageField } from "../fields/ImageField";
-import { RichTextField } from "../fields/RichTextField";
import { ImageBox } from "../views/nodes/ImageBox";
import { CollectionFreeFormView } from "../views/collections/CollectionFreeFormView";
+import { FIELD_ID } from "../fields/Field";
interface DocumentOptions {
x?: number;
@@ -21,36 +22,36 @@ interface DocumentOptions {
export namespace Documents {
function setupOptions(doc: Document, options: DocumentOptions): void {
- if (options.title) {
- doc.SetField(KeyStore.Title, new TextField(options.title));
- }
if (options.x) {
- doc.SetFieldValue(KeyStore.X, options.x, NumberField);
+ doc.SetData(KeyStore.X, options.x, NumberField);
}
if (options.y) {
- doc.SetFieldValue(KeyStore.Y, options.y, NumberField);
+ doc.SetData(KeyStore.Y, options.y, NumberField);
}
if (options.width) {
- doc.SetFieldValue(KeyStore.Width, options.width, NumberField);
+ doc.SetData(KeyStore.Width, options.width, NumberField);
}
if (options.height) {
- doc.SetFieldValue(KeyStore.Height, options.height, NumberField);
+ doc.SetData(KeyStore.Height, options.height, NumberField);
}
- doc.SetFieldValue(KeyStore.Scale, 1, NumberField);
- doc.SetFieldValue(KeyStore.PanX, 0, NumberField);
- doc.SetFieldValue(KeyStore.PanY, 0, 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.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(FormattedTextBox.LayoutString()));
- textProto.SetField(KeyStore.LayoutKeys, new ListField([KeyStore.Data]));
+ 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;
}
@@ -66,12 +67,12 @@ export namespace Documents {
function GetSchemaPrototype(): Document {
if (!schemaProto) {
schemaProto = new Document();
- schemaProto.SetField(KeyStore.X, new NumberField(0));
- schemaProto.SetField(KeyStore.Y, new NumberField(0));
- schemaProto.SetField(KeyStore.Width, new NumberField(300));
- schemaProto.SetField(KeyStore.Height, new NumberField(150));
- schemaProto.SetField(KeyStore.Layout, new TextField(CollectionSchemaView.LayoutString()));
- schemaProto.SetField(KeyStore.LayoutKeys, new ListField([KeyStore.Data]));
+ 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;
}
@@ -79,7 +80,7 @@ export namespace Documents {
export function SchemaDocument(documents: Array<Document>, options: DocumentOptions = {}): Document {
let doc = GetSchemaPrototype().MakeDelegate();
setupOptions(doc, options);
- doc.SetField(KeyStore.Data, new ListField(documents));
+ doc.Set(KeyStore.Data, new ListField(documents));
return doc;
}
@@ -88,12 +89,12 @@ export namespace Documents {
function GetDockPrototype(): Document {
if (!dockProto) {
dockProto = new Document();
- dockProto.SetField(KeyStore.X, new NumberField(0));
- dockProto.SetField(KeyStore.Y, new NumberField(0));
- dockProto.SetField(KeyStore.Width, new NumberField(300));
- dockProto.SetField(KeyStore.Height, new NumberField(150));
- dockProto.SetField(KeyStore.Layout, new TextField(CollectionDockingView.LayoutString()));
- dockProto.SetField(KeyStore.LayoutKeys, new ListField([KeyStore.Data]));
+ 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;
}
@@ -101,48 +102,51 @@ export namespace Documents {
export function DockDocument(documents: Array<Document>, options: DocumentOptions = {}): Document {
let doc = GetDockPrototype().MakeDelegate();
setupOptions(doc, options);
- doc.SetField(KeyStore.Data, new ListField(documents));
+ doc.Set(KeyStore.Data, new ListField(documents));
return doc;
}
- let imageProto: Document;
+ let imageProtoId: FIELD_ID;
function GetImagePrototype(): Document {
- if (!imageProto) {
- imageProto = new Document();
- imageProto.SetFieldValue(KeyStore.Title, "IMAGE PROTO", TextField);
- imageProto.SetFieldValue(KeyStore.X, 0, NumberField);
- imageProto.SetFieldValue(KeyStore.Y, 0, NumberField);
- imageProto.SetFieldValue(KeyStore.Width, 300, NumberField);
- imageProto.SetFieldValue(KeyStore.Height, 300, NumberField);
- imageProto.SetFieldValue(KeyStore.Layout, ImageBox.LayoutString(), TextField);
+ 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.SetFieldValue(KeyStore.LayoutKeys, [KeyStore.Data], ListField);
- imageProto.SetFieldValue(KeyStore.Data, "", TextField); // bcz: just for testing purposes
+ imageProto.Set(KeyStore.LayoutKeys, new ListField([KeyStore.Data]));
+ Server.AddDocument(imageProto);
+ return imageProto;
}
- return imageProto;
+ return Server.GetDocument(imageProtoId)!;
}
export function ImageDocument(url: string, options: DocumentOptions = {}): Document {
let doc = GetImagePrototype().MakeDelegate();
setupOptions(doc, options);
- doc.SetFieldValue(KeyStore.Data, new URL(url), ImageField);
- return doc;
+ doc.Set(KeyStore.Data, new ImageField(new URL(url)));
+ Server.AddDocument(doc);
+ return Server.GetDocument(doc.Id)!;
}
let collectionProto: Document;
function GetCollectionPrototype(): Document {
if (!collectionProto) {
collectionProto = new Document();
- collectionProto.SetField(KeyStore.X, new NumberField(0));
- collectionProto.SetField(KeyStore.Y, new NumberField(0));
- collectionProto.SetField(KeyStore.Scale, new NumberField(1));
- collectionProto.SetField(KeyStore.PanX, new NumberField(0));
- collectionProto.SetField(KeyStore.PanY, new NumberField(0));
- collectionProto.SetField(KeyStore.Width, new NumberField(300));
- collectionProto.SetField(KeyStore.Height, new NumberField(300));
- collectionProto.SetField(KeyStore.Layout, new TextField(CollectionFreeFormView.LayoutString()));
- collectionProto.SetField(KeyStore.LayoutKeys, new ListField([KeyStore.Data]));
+ 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;
}
@@ -150,7 +154,7 @@ export namespace Documents {
export function CollectionDocument(documents: Array<Document>, options: DocumentOptions = {}): Document {
let doc = GetCollectionPrototype().MakeDelegate();
setupOptions(doc, options);
- doc.SetField(KeyStore.Data, new ListField(documents));
+ doc.Set(KeyStore.Data, new ListField(documents));
return doc;
}
} \ No newline at end of file
diff --git a/src/fields/Document.ts b/src/fields/Document.ts
index 691b0f662..3d74c047c 100644
--- a/src/fields/Document.ts
+++ b/src/fields/Document.ts
@@ -1,49 +1,41 @@
-import { Field, Cast, Opt, Waiting, WAITING } from "./Field"
+import { Field, Cast, Opt, FieldWaiting, FIELD_ID, DOC_ID } from "./Field"
import { Key, KeyStore } from "./Key"
import { NumberField } from "./NumberField";
-import { ObservableMap, computed, action } from "mobx";
+import { ObservableMap, computed, action, observable } from "mobx";
import { TextField } from "./TextField";
import { ListField } from "./ListField";
+import { findDOMNode } from "react-dom";
+import { Server } from "../Server";
export class Document extends Field {
- private fields: ObservableMap<Key, Opt<Field>> = new ObservableMap();
- private _sfields: ObservableMap<Key, Field> = new ObservableMap();
+ public fields: ObservableMap<Key, Opt<Field>> = new ObservableMap();
+ public _proxies: ObservableMap<Key, FIELD_ID> = new ObservableMap();
- static _untitledDocName = "<untitled>";
@computed
- public get Title() { return this.GetFieldValue(KeyStore.Title, TextField, Document._untitledDocName); }
-
- @action
- DeferredSetField(key: Key) {
- var sfield = this._sfields.get(key);
- if (sfield != undefined)
- this.fields.set(key, sfield);
- }
-
- static times = 0;
- GetFieldFromServerDeferred(key: Key) {
- var me = this;
- setTimeout(function () {
- if (me) {
- me.DeferredSetField(key);
- }
- }, key == KeyStore.Data ? (Document.times++ == 0 ? 5000 : 1000) : key == KeyStore.X ? 2500 : 500)
+ public get Title() {
+ return this.GetText(KeyStore.Title, "<untitled>");
}
- GetField(key: Key, ignoreProto: boolean = false): Opt<Field> {
- let field: Opt<Field> = WAITING;
+ Get(key: Key, ignoreProto: boolean = false): Opt<Field> {
+ let field: Opt<Field>;
if (ignoreProto) {
if (this.fields.has(key)) {
field = this.fields.get(key);
- } else {
- this.GetFieldFromServerDeferred(key); // bcz: only want to do this if the field is on the server
+ } else if (this._proxies.has(key)) {
+ field = Server.GetDocumentField(this, key);
}
} else {
let doc: Opt<Document> = this;
- while (doc && doc != WAITING) {
+ while (doc && doc != FieldWaiting && field != FieldWaiting) {
if (!doc.fields.has(key)) {
- doc.GetFieldFromServerDeferred(key); // bcz: only want to do this if the field is on the server
- doc = doc.GetPrototype();
+ if (doc._proxies.has(key)) {
+ field = Server.GetDocumentField(doc, key);
+ break;
+ }
+ if ((doc.fields.has(KeyStore.Prototype) || doc._proxies.has(KeyStore.Prototype))) {
+ doc = doc.GetPrototype();
+ } else
+ break;
} else {
field = doc.fields.get(key);
break;
@@ -54,83 +46,87 @@ export class Document extends Field {
return field;
}
- GetFieldT<T extends Field = Field>(key: Key, ctor: { new(...args: any[]): T }, ignoreProto: boolean = false): Opt<T> {
- var getfield = this.GetField(key, ignoreProto);
- if (getfield != WAITING) {
+ GetT<T extends Field = Field>(key: Key, ctor: { new(...args: any[]): T }, ignoreProto: boolean = false): Opt<T> {
+ var getfield = this.Get(key, ignoreProto);
+ if (getfield != FieldWaiting) {
return Cast(getfield, ctor);
}
- return WAITING;
+ return FieldWaiting;
}
- GetFieldOrCreate<T extends Field>(key: Key, ctor: { new(): T }, ignoreProto: boolean = false): T {
- const field = this.GetFieldT(key, ctor, ignoreProto);
- if (field && field != WAITING) {
+ GetOrCreate<T extends Field>(key: Key, ctor: { new(): T }, ignoreProto: boolean = false): T {
+ const field = this.GetT(key, ctor, ignoreProto);
+ if (field && field != FieldWaiting) {
return field;
}
const newField = new ctor();
- this.SetField(key, newField);
+ this.Set(key, newField);
return newField;
}
- GetFieldValue<T, U extends { Data: T }>(key: Key, ctor: { new(): U }, defaultVal: T): T {
- let val = this.GetField(key);
+ GetData<T, U extends Field & { Data: T }>(key: Key, ctor: { new(): U }, defaultVal: T): T {
+ let val = this.Get(key);
let vval = (val && val instanceof ctor) ? val.Data : defaultVal;
return vval;
}
- GetNumberField(key: Key, defaultVal: number): number {
- return this.GetFieldValue(key, NumberField, defaultVal);
+ GetNumber(key: Key, defaultVal: number): number {
+ return this.GetData(key, NumberField, defaultVal);
}
- GetTextField(key: Key, defaultVal: string): string {
- return this.GetFieldValue(key, TextField, defaultVal);
+ GetText(key: Key, defaultVal: string): string {
+ return this.GetData(key, TextField, defaultVal);
}
- GetListField<T extends Field>(key: Key, defaultVal: T[]): T[] {
- return this.GetFieldValue<T[], ListField<T>>(key, ListField, defaultVal)
+ GetList<T extends Field>(key: Key, defaultVal: T[]): T[] {
+ return this.GetData<T[], ListField<T>>(key, ListField, defaultVal)
}
@action
- SetField(key: Key, field: Field | undefined): void {
+ Set(key: Key, field: Field | undefined): void {
if (field) {
this.fields.set(key, field);
+ Server.AddDocumentField(this, key, field);
} else {
this.fields.delete(key);
+ Server.DeleteDocumentField(this, key);
}
}
@action
- SetFieldValue<T extends Field>(key: Key, value: any, ctor: { new(): T }): boolean {
- let field = new ctor();
- if (field.TrySetValue(value)) {
- this._sfields.set(key, field);
- return true;
+ SetData<T, U extends Field & { Data: T }>(key: Key, value: T, ctor: { new(): U }, replaceWrongType = true) {
+
+ let field = this.Get(key, true);
+ //if (field != WAITING) { // do we want to wait for the field to come back from the server to set it, or do we overwrite?
+ if (field instanceof ctor) {
+ field.Data = value;
+ Server.SetFieldValue(field, value);
+ } else if (!field || replaceWrongType) {
+ let newField = new ctor();
+ newField.Data = value;
+ this.Set(key, newField);
}
- return false;
-
- // let field = this.GetField(key, true);
- // if (field != WAITING) {
- // if (field) {
- // return field.TrySetValue(value);
- // } else {
- // field = new ctor();
- // if (field.TrySetValue(value)) {
- // this.SetField(key, field);
- // return true;
- // }
- // }
- // }
- // return false;
+ //}
+ }
+
+ @action
+ SetText(key: Key, value: string, replaceWrongType = true) {
+ this.SetData(key, value, TextField, replaceWrongType);
+ }
+
+ @action
+ SetNumber(key: Key, value: number, replaceWrongType = true) {
+ this.SetData(key, value, NumberField, replaceWrongType);
}
GetPrototype(): Opt<Document> {
- return this.GetFieldT(KeyStore.Prototype, Document, true);
+ return this.GetT(KeyStore.Prototype, Document, true);
}
GetAllPrototypes(): Document[] {
let protos: Document[] = [];
let doc: Opt<Document> = this;
- while (doc && doc != WAITING) {
+ while (doc && doc != FieldWaiting) {
protos.push(doc);
doc = doc.GetPrototype();
}
@@ -140,7 +136,7 @@ export class Document extends Field {
MakeDelegate(): Document {
let delegate = new Document();
- delegate.SetField(KeyStore.Prototype, this);
+ delegate.Set(KeyStore.Prototype, this);
return delegate;
}
diff --git a/src/fields/DocumentReference.ts b/src/fields/DocumentReference.ts
index f4f933848..10dac9f92 100644
--- a/src/fields/DocumentReference.ts
+++ b/src/fields/DocumentReference.ts
@@ -16,7 +16,7 @@ export class DocumentReference extends Field {
}
Dereference(): Opt<Field> {
- return this.document.GetField(this.key);
+ return this.document.Get(this.key);
}
DereferenceToRoot(): Opt<Field> {
diff --git a/src/fields/Field.ts b/src/fields/Field.ts
index 7f057afa8..9880116c0 100644
--- a/src/fields/Field.ts
+++ b/src/fields/Field.ts
@@ -10,19 +10,21 @@ export function Cast<T extends Field>(field: Opt<Field>, ctor: { new(): T }): Op
return undefined;
}
-export type Waiting = "<Waiting>";
-export type Opt<T> = T | undefined | Waiting;
-export let WAITING: Waiting = "<Waiting>";
+export let 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 abstract class Field {
//FieldUpdated: TypedEvent<Opt<FieldUpdatedArgs>> = new TypedEvent<Opt<FieldUpdatedArgs>>();
- private id: string;
- get Id(): string {
+ private id: FIELD_ID;
+ get Id(): FIELD_ID {
return this.id;
}
- constructor(id: Opt<string> = undefined) {
+ constructor(id: FIELD_ID = undefined) {
this.id = id || Utils.GenerateGuid();
}
diff --git a/src/fields/RichTextField.ts b/src/fields/RichTextField.ts
index 4cf5c99a7..24c7472d8 100644
--- a/src/fields/RichTextField.ts
+++ b/src/fields/RichTextField.ts
@@ -1,12 +1,11 @@
import { BasicField } from "./BasicField";
-import { Field } from "./Field";
export class RichTextField extends BasicField<string> {
constructor(data: string = "") {
super(data);
}
- Copy(): Field {
+ Copy() {
return new RichTextField(this.Data);
}
diff --git a/src/util/Scripting.ts b/src/util/Scripting.ts
new file mode 100644
index 000000000..804c67bc5
--- /dev/null
+++ b/src/util/Scripting.ts
@@ -0,0 +1,47 @@
+// import * as ts from "typescript"
+let ts = (window as any).ts;
+import { Opt, Field, FieldWaiting } from "../fields/Field";
+import { Document as DocumentImport } from "../fields/Document";
+import { NumberField as NumberFieldImport } from "../fields/NumberField";
+import { TextField as TextFieldImport } from "../fields/TextField";
+import { RichTextField as RichTextFieldImport } from "../fields/RichTextField";
+import { KeyStore as KeyStoreImport } from "../fields/Key";
+
+export interface ExecutableScript {
+ (): any;
+
+ compiled: boolean;
+}
+
+function ExecScript(script: string, diagnostics: Opt<any[]>): ExecutableScript {
+ const compiled = !(diagnostics && diagnostics != FieldWaiting && diagnostics.some(diag => diag.category == ts.DiagnosticCategory.Error));
+
+ let func: () => Opt<Field>;
+ if (compiled) {
+ func = function (): Opt<Field> {
+ let KeyStore = KeyStoreImport;
+ let Document = DocumentImport;
+ let NumberField = NumberFieldImport;
+ let TextField = TextFieldImport;
+ let RichTextField = RichTextFieldImport;
+ let window = undefined;
+ let document = undefined;
+ let retVal = eval(script);
+
+ return retVal;
+ };
+ } else {
+ func = () => undefined;
+ }
+
+ return Object.assign(func,
+ {
+ compiled
+ });
+}
+
+export function CompileScript(script: string): ExecutableScript {
+ let result = (window as any).ts.transpileModule(script, {})
+
+ return ExecScript(result.outputText, result.diagnostics);
+} \ No newline at end of file
diff --git a/src/views/collections/CollectionDockingView.tsx b/src/views/collections/CollectionDockingView.tsx
index 4bbbeeecd..e489e319a 100644
--- a/src/views/collections/CollectionDockingView.tsx
+++ b/src/views/collections/CollectionDockingView.tsx
@@ -15,7 +15,7 @@ import * as GoldenLayout from "golden-layout";
import * as ReactDOM from 'react-dom';
import { DragManager } from "../../util/DragManager";
import { CollectionViewBase, CollectionViewProps, COLLECTION_BORDER_WIDTH } from "./CollectionViewBase";
-import { WAITING } from "../../fields/Field";
+import { FieldWaiting } from "../../fields/Field";
@observer
export class CollectionDockingView extends CollectionViewBase {
@@ -26,7 +26,7 @@ export class CollectionDockingView extends CollectionViewBase {
@computed
private get modelForFlexLayout() {
const { CollectionFieldKey: fieldKey, DocumentForCollection: Document } = this.props;
- const value: Document[] = Document.GetFieldValue(fieldKey, ListField, []);
+ const value: Document[] = Document.GetData(fieldKey, ListField, []);
var docs = value.map(doc => {
return { type: 'tabset', weight: 50, selected: 0, children: [{ type: "tab", name: doc.Title, component: doc.Id }] };
});
@@ -42,7 +42,7 @@ export class CollectionDockingView extends CollectionViewBase {
@computed
private get modelForGoldenLayout(): any {
const { CollectionFieldKey: fieldKey, DocumentForCollection: Document } = this.props;
- const value: Document[] = Document.GetFieldValue(fieldKey, ListField, []);
+ const value: Document[] = Document.GetData(fieldKey, ListField, []);
var docs = value.map(doc => {
return { type: 'component', componentName: 'documentViewComponent', componentState: { doc: doc } };
});
@@ -70,7 +70,7 @@ export class CollectionDockingView extends CollectionViewBase {
@action
onResize = (event: any) => {
- if (this.props.ContainingDocumentView == WAITING)
+ if (this.props.ContainingDocumentView == FieldWaiting)
return;
var cur = this.props.ContainingDocumentView!.MainContent.current;
@@ -96,10 +96,9 @@ export class CollectionDockingView extends CollectionViewBase {
return <button>{node.getName()}</button>;
}
const { CollectionFieldKey: fieldKey, DocumentForCollection: Document } = this.props;
- const value: Document[] = Document.GetFieldValue(fieldKey, ListField, []);
+ const value: Document[] = Document.GetData(fieldKey, ListField, []);
for (var i: number = 0; i < value.length; i++) {
if (value[i].Id === component) {
- var data = value[i].GetField(KeyStore.Data);
return (<DocumentView key={value[i].Id} ContainingCollectionView={this} Document={value[i]} DocumentView={undefined} />);
}
}
@@ -240,7 +239,6 @@ export class CollectionDockingView extends CollectionViewBase {
var containingDiv = "component_" + me.nextId();
container.getElement().html("<div id='" + containingDiv + "'></div>");
setTimeout(function () {
- var data = state.doc.GetField(KeyStore.Data);
ReactDOM.render((
<DocumentView key={state.doc.Id} Document={state.doc} ContainingCollectionView={me} DocumentView={undefined} />
),
@@ -257,14 +255,14 @@ export class CollectionDockingView extends CollectionViewBase {
render() {
- if (this.props.ContainingDocumentView == WAITING)
+ if (this.props.ContainingDocumentView == FieldWaiting)
return;
const { CollectionFieldKey: fieldKey, DocumentForCollection: Document } = this.props;
- const value: Document[] = Document.GetFieldValue(fieldKey, ListField, []);
+ const value: Document[] = Document.GetData(fieldKey, ListField, []);
// bcz: not sure why, but I need these to force the flexlayout to update when the collection size changes.
var s = this.props.ContainingDocumentView != undefined ? this.props.ContainingDocumentView!.ScalingToScreenSpace : 1;
- var w = Document.GetFieldValue(KeyStore.Width, NumberField, Number(0)) / s;
- var h = Document.GetFieldValue(KeyStore.Height, NumberField, Number(0)) / s;
+ var w = Document.GetData(KeyStore.Width, NumberField, Number(0)) / s;
+ var h = Document.GetData(KeyStore.Height, NumberField, Number(0)) / s;
var chooseLayout = () => {
if (!CollectionDockingView.UseGoldenLayout)
diff --git a/src/views/collections/CollectionFreeFormView.tsx b/src/views/collections/CollectionFreeFormView.tsx
index d48d096ce..45d37ca4f 100644
--- a/src/views/collections/CollectionFreeFormView.tsx
+++ b/src/views/collections/CollectionFreeFormView.tsx
@@ -13,7 +13,7 @@ import "./CollectionFreeFormView.scss";
import { Utils } from "../../Utils";
import { CollectionViewBase, CollectionViewProps, COLLECTION_BORDER_WIDTH } from "./CollectionViewBase";
import { SelectionManager } from "../../util/SelectionManager";
-import { WAITING } from "../../fields/Field";
+import { FieldWaiting } from "../../fields/Field";
@observer
export class CollectionFreeFormView extends CollectionViewBase {
@@ -33,15 +33,15 @@ export class CollectionFreeFormView extends CollectionViewBase {
const doc = de.data["document"];
var me = this;
if (doc instanceof CollectionFreeFormDocumentView) {
- if (doc.props.ContainingCollectionView && doc.props.ContainingCollectionView !== this && doc.props.ContainingCollectionView != WAITING) {
+ if (doc.props.ContainingCollectionView && doc.props.ContainingCollectionView !== this && doc.props.ContainingCollectionView != FieldWaiting) {
doc.props.ContainingCollectionView.removeDocument(doc.props.Document);
this.addDocument(doc.props.Document);
}
const xOffset = de.data["xOffset"] as number || 0;
const yOffset = de.data["yOffset"] as number || 0;
const { scale, translateX, translateY } = Utils.GetScreenTransform(this._canvasRef.current!);
- if (this.props.ContainingDocumentView != WAITING) {
- let sscale = this.props.ContainingDocumentView!.props.Document.GetFieldValue(KeyStore.Scale, NumberField, Number(1))
+ if (this.props.ContainingDocumentView != FieldWaiting) {
+ let sscale = this.props.ContainingDocumentView!.props.Document.GetData(KeyStore.Scale, NumberField, Number(1))
const screenX = de.x - xOffset;
const screenY = de.y - yOffset;
const docX = (screenX - translateX) / sscale / scale;
@@ -64,12 +64,8 @@ export class CollectionFreeFormView extends CollectionViewBase {
}
}
- downactive: boolean = false;
@action
onPointerDown = (e: React.PointerEvent): void => {
- var me = this;
- me.downactive = this.active;
- var title = this.props.DocumentForCollection.Title;
if ((e.button === 2 && this.active) ||
!e.defaultPrevented) {
document.removeEventListener("pointermove", this.onPointerMove);
@@ -92,16 +88,14 @@ export class CollectionFreeFormView extends CollectionViewBase {
@action
onPointerMove = (e: PointerEvent): void => {
var me = this;
- var act = me.active;
- var title = me.props.DocumentForCollection.Title;
- if (!e.cancelBubble && this.active && this.props.ContainingDocumentView != WAITING) {
+ if (!e.cancelBubble && this.active && this.props.ContainingDocumentView != FieldWaiting) {
e.preventDefault();
e.stopPropagation();
let currScale: number = this.props.ContainingDocumentView!.ScalingToScreenSpace;
- let x = this.props.DocumentForCollection.GetFieldValue(KeyStore.PanX, NumberField, Number(0));
- let y = this.props.DocumentForCollection.GetFieldValue(KeyStore.PanY, NumberField, Number(0));
- this.props.DocumentForCollection.SetFieldValue(KeyStore.PanX, x + (e.pageX - this._lastX) / currScale, NumberField);
- this.props.DocumentForCollection.SetFieldValue(KeyStore.PanY, y + (e.pageY - this._lastY) / currScale, NumberField);
+ let x = this.props.DocumentForCollection.GetData(KeyStore.PanX, NumberField, Number(0));
+ let y = this.props.DocumentForCollection.GetData(KeyStore.PanY, NumberField, Number(0));
+ this.props.DocumentForCollection.SetData(KeyStore.PanX, x + (e.pageX - this._lastX) / currScale, NumberField);
+ this.props.DocumentForCollection.SetData(KeyStore.PanY, y + (e.pageY - this._lastY) / currScale, NumberField);
}
this._lastX = e.pageX;
this._lastY = e.pageY;
@@ -111,7 +105,7 @@ export class CollectionFreeFormView extends CollectionViewBase {
onPointerWheel = (e: React.WheelEvent): void => {
e.stopPropagation();
- if (this.props.ContainingDocumentView == WAITING)
+ if (this.props.ContainingDocumentView == FieldWaiting)
return;
let { LocalX, Ss, Panxx, Xx, LocalY, Panyy, Yy, ContainerX, ContainerY } = this.props.ContainingDocumentView!.TransformToLocalPoint(e.pageX, e.pageY);
@@ -123,9 +117,9 @@ export class CollectionFreeFormView extends CollectionViewBase {
let dx = ContainerX - newContainerX;
let dy = ContainerY - newContainerY;
- this.props.DocumentForCollection.SetField(KeyStore.Scale, new NumberField(deltaScale));
- this.props.DocumentForCollection.SetFieldValue(KeyStore.PanX, Panxx + dx, NumberField);
- this.props.DocumentForCollection.SetFieldValue(KeyStore.PanY, Panyy + dy, NumberField);
+ this.props.DocumentForCollection.Set(KeyStore.Scale, new NumberField(deltaScale));
+ this.props.DocumentForCollection.SetData(KeyStore.PanX, Panxx + dx, NumberField);
+ this.props.DocumentForCollection.SetData(KeyStore.PanY, Panyy + dy, NumberField);
}
@action
@@ -135,8 +129,8 @@ export class CollectionFreeFormView extends CollectionViewBase {
let fReader = new FileReader()
let file = e.dataTransfer.items[0].getAsFile();
let that = this;
- const panx: number = this.props.DocumentForCollection.GetFieldValue(KeyStore.PanX, NumberField, Number(0));
- const pany: number = this.props.DocumentForCollection.GetFieldValue(KeyStore.PanY, NumberField, Number(0));
+ const panx: number = this.props.DocumentForCollection.GetData(KeyStore.PanX, NumberField, Number(0));
+ const pany: number = this.props.DocumentForCollection.GetData(KeyStore.PanY, NumberField, Number(0));
let x = e.pageX - panx
let y = e.pageY - pany
@@ -146,11 +140,11 @@ export class CollectionFreeFormView extends CollectionViewBase {
let doc = Documents.ImageDocument(url, {
x: x, y: y
})
- let docs = that.props.DocumentForCollection.GetFieldT(KeyStore.Data, ListField);
- if (docs != WAITING) {
+ let docs = that.props.DocumentForCollection.GetT(KeyStore.Data, ListField);
+ if (docs != FieldWaiting) {
if (!docs) {
docs = new ListField<Document>();
- that.props.DocumentForCollection.SetField(KeyStore.Data, docs)
+ that.props.DocumentForCollection.Set(KeyStore.Data, docs)
}
docs.Data.push(doc);
}
@@ -169,27 +163,26 @@ export class CollectionFreeFormView extends CollectionViewBase {
bringToFront(doc: CollectionFreeFormDocumentView) {
const { CollectionFieldKey: fieldKey, DocumentForCollection: Document } = this.props;
- const value: Document[] = Document.GetListField<Document>(fieldKey, []);
- var topmost = value.reduce((topmost, d) => Math.max(d.GetNumberField(KeyStore.ZIndex, 0), topmost), -1000);
+ const value: Document[] = Document.GetList<Document>(fieldKey, []);
+ var topmost = value.reduce((topmost, d) => Math.max(d.GetNumber(KeyStore.ZIndex, 0), topmost), -1000);
value.map(d => {
- var zind = d.GetNumberField(KeyStore.ZIndex, 0);
+ var zind = d.GetNumber(KeyStore.ZIndex, 0);
if (zind != topmost - 1 - (topmost - zind) && d != doc.props.Document) {
- d.SetFieldValue(KeyStore.ZIndex, topmost - 1 - (topmost - zind), NumberField);
+ d.SetData(KeyStore.ZIndex, topmost - 1 - (topmost - zind), NumberField);
}
})
- if (doc.props.Document.GetNumberField(KeyStore.ZIndex, 0) != 0) {
- doc.props.Document.SetFieldValue(KeyStore.ZIndex, 0, NumberField);
+ if (doc.props.Document.GetNumber(KeyStore.ZIndex, 0) != 0) {
+ doc.props.Document.SetData(KeyStore.ZIndex, 0, NumberField);
}
}
render() {
const { CollectionFieldKey: fieldKey, DocumentForCollection: Document } = this.props;
- const value: Document[] = Document.GetListField<Document>(fieldKey, []);
- const panx: number = Document.GetNumberField(KeyStore.PanX, 0);
- const pany: number = Document.GetNumberField(KeyStore.PanY, 0);
- const currScale: number = Document.GetNumberField(KeyStore.Scale, 1);
- const data = Document.GetField(KeyStore.Data);
+ const value: Document[] = Document.GetList<Document>(fieldKey, []);
+ const panx: number = Document.GetNumber(KeyStore.PanX, 0);
+ const pany: number = Document.GetNumber(KeyStore.PanY, 0);
+ const currScale: number = Document.GetNumber(KeyStore.Scale, 1);
return (
<div className="border" style={{
diff --git a/src/views/collections/CollectionSchemaView.tsx b/src/views/collections/CollectionSchemaView.tsx
index 59d54e8c4..8817cb496 100644
--- a/src/views/collections/CollectionSchemaView.tsx
+++ b/src/views/collections/CollectionSchemaView.tsx
@@ -69,12 +69,11 @@ export class CollectionSchemaView extends CollectionViewBase {
render() {
const { DocumentForCollection: Document, CollectionFieldKey: fieldKey } = this.props;
- const children = Document.GetListField<Document>(fieldKey, []);
- const columns = Document.GetListField(KS.ColumnsKey,
+ const children = Document.GetList<Document>(fieldKey, []);
+ const columns = Document.GetList(KS.ColumnsKey,
[KS.Title, KS.Data, KS.Author])
let content;
if (this.selectedIndex != -1) {
- var data = this.props.DocumentForCollection.GetField(KS.Data);
content = (<DocumentView Document={children[this.selectedIndex]} DocumentView={undefined} ContainingCollectionView={this} />)
} else {
content = <div />
diff --git a/src/views/collections/CollectionViewBase.tsx b/src/views/collections/CollectionViewBase.tsx
index e00a29978..4fce02ef6 100644
--- a/src/views/collections/CollectionViewBase.tsx
+++ b/src/views/collections/CollectionViewBase.tsx
@@ -1,7 +1,7 @@
import { action, computed } from "mobx";
import { observer } from "mobx-react";
import { Document } from "../../fields/Document";
-import { Opt, WAITING } from "../../fields/Field";
+import { Opt, FieldWaiting } from "../../fields/Field";
import { Key, KeyStore } from "../../fields/Key";
import { ListField } from "../../fields/ListField";
import { SelectionManager } from "../../util/SelectionManager";
@@ -31,7 +31,7 @@ export class CollectionViewBase extends React.Component<CollectionViewProps> {
var isSelected = (this.props.ContainingDocumentView instanceof CollectionFreeFormDocumentView && SelectionManager.IsSelected(this.props.ContainingDocumentView));
var childSelected = SelectionManager.SelectedDocuments().some(view => view.props.ContainingCollectionView == this);
var topMost = this.props.ContainingDocumentView != undefined &&
- this.props.ContainingDocumentView != WAITING && this.props.ContainingDocumentView.props.ContainingCollectionView != WAITING && (
+ this.props.ContainingDocumentView != FieldWaiting && this.props.ContainingDocumentView.props.ContainingCollectionView != FieldWaiting && (
this.props.ContainingDocumentView.props.ContainingCollectionView == undefined ||
this.props.ContainingDocumentView.props.ContainingCollectionView instanceof CollectionDockingView);
return isSelected || childSelected || topMost;
@@ -39,14 +39,14 @@ export class CollectionViewBase extends React.Component<CollectionViewProps> {
@action
addDocument = (doc: Document): void => {
//TODO This won't create the field if it doesn't already exist
- const value = this.props.DocumentForCollection.GetFieldValue(this.props.CollectionFieldKey, ListField, new Array<Document>())
+ const value = this.props.DocumentForCollection.GetData(this.props.CollectionFieldKey, ListField, new Array<Document>())
value.push(doc);
}
@action
removeDocument = (doc: Document): void => {
//TODO This won't create the field if it doesn't already exist
- const value = this.props.DocumentForCollection.GetFieldValue(this.props.CollectionFieldKey, ListField, new Array<Document>())
+ const value = this.props.DocumentForCollection.GetData(this.props.CollectionFieldKey, ListField, new Array<Document>())
if (value.indexOf(doc) !== -1) {
value.splice(value.indexOf(doc), 1)
diff --git a/src/views/nodes/CollectionFreeFormDocumentView.tsx b/src/views/nodes/CollectionFreeFormDocumentView.tsx
index d98c8dcb7..25d67d96a 100644
--- a/src/views/nodes/CollectionFreeFormDocumentView.tsx
+++ b/src/views/nodes/CollectionFreeFormDocumentView.tsx
@@ -10,8 +10,7 @@ import { ContextMenu } from "../ContextMenu";
import "./NodeView.scss";
import React = require("react");
import { DocumentView, DocumentViewProps } from "./DocumentView";
-import { WAITING } from "../../fields/Field";
-import { ImageField } from '../../fields/ImageField';
+import { FieldWaiting } from "../../fields/Field";
@observer
@@ -32,20 +31,20 @@ export class CollectionFreeFormDocumentView extends DocumentView {
@computed
get x(): number {
- return this.props.Document.GetFieldValue(KeyStore.X, NumberField, Number(0));
+ return this.props.Document.GetData(KeyStore.X, NumberField, Number(0));
}
@computed
get y(): number {
- return this.props.Document.GetFieldValue(KeyStore.Y, NumberField, Number(0));
+ return this.props.Document.GetData(KeyStore.Y, NumberField, Number(0));
}
set x(x: number) {
- this.props.Document.SetFieldValue(KeyStore.X, x, NumberField)
+ this.props.Document.SetData(KeyStore.X, x, NumberField)
}
set y(y: number) {
- this.props.Document.SetFieldValue(KeyStore.Y, y, NumberField)
+ this.props.Document.SetData(KeyStore.Y, y, NumberField)
}
@computed
@@ -55,29 +54,29 @@ export class CollectionFreeFormDocumentView extends DocumentView {
@computed
get width(): number {
- return this.props.Document.GetFieldValue(KeyStore.Width, NumberField, Number(0));
+ return this.props.Document.GetData(KeyStore.Width, NumberField, Number(0));
}
set width(w: number) {
- this.props.Document.SetFieldValue(KeyStore.Width, w, NumberField)
+ this.props.Document.SetData(KeyStore.Width, w, NumberField)
}
@computed
get height(): number {
- return this.props.Document.GetFieldValue(KeyStore.Height, NumberField, Number(0));
+ return this.props.Document.GetData(KeyStore.Height, NumberField, Number(0));
}
set height(h: number) {
- this.props.Document.SetFieldValue(KeyStore.Height, h, NumberField)
+ this.props.Document.SetData(KeyStore.Height, h, NumberField)
}
@computed
get zIndex(): number {
- return this.props.Document.GetFieldValue(KeyStore.ZIndex, NumberField, Number(0));
+ return this.props.Document.GetData(KeyStore.ZIndex, NumberField, Number(0));
}
set zIndex(h: number) {
- this.props.Document.SetFieldValue(KeyStore.ZIndex, h, NumberField)
+ this.props.Document.SetData(KeyStore.ZIndex, h, NumberField)
}
@action
@@ -87,7 +86,7 @@ export class CollectionFreeFormDocumentView extends DocumentView {
@computed
get active(): boolean {
return SelectionManager.IsSelected(this) || this.props.ContainingCollectionView === undefined ||
- (this.props.ContainingCollectionView != WAITING && this.props.ContainingCollectionView!.active);
+ (this.props.ContainingCollectionView != FieldWaiting && this.props.ContainingCollectionView!.active);
}
@computed
diff --git a/src/views/nodes/DocumentView.tsx b/src/views/nodes/DocumentView.tsx
index cfd894a38..81353cd60 100644
--- a/src/views/nodes/DocumentView.tsx
+++ b/src/views/nodes/DocumentView.tsx
@@ -1,7 +1,7 @@
import { action, computed } from "mobx";
import { observer } from "mobx-react";
import { Document } from "../../fields/Document";
-import { Opt, WAITING } from "../../fields/Field";
+import { Opt, FieldWaiting } from "../../fields/Field";
import { Key, KeyStore } from "../../fields/Key";
import { ListField } from "../../fields/ListField";
import { NumberField } from "../../fields/NumberField";
@@ -31,17 +31,17 @@ export class DocumentView extends React.Component<DocumentViewProps> {
}
@computed
get layout(): string {
- return this.props.Document.GetFieldValue(KeyStore.Layout, TextField, String("<p>Error loading layout data</p>"));
+ return this.props.Document.GetData(KeyStore.Layout, TextField, String("<p>Error loading layout data</p>"));
}
@computed
get layoutKeys(): Key[] {
- return this.props.Document.GetFieldValue(KeyStore.LayoutKeys, ListField, new Array<Key>());
+ return this.props.Document.GetData(KeyStore.LayoutKeys, ListField, new Array<Key>());
}
@computed
get layoutFields(): Key[] {
- return this.props.Document.GetFieldValue(KeyStore.LayoutFields, ListField, new Array<Key>());
+ return this.props.Document.GetData(KeyStore.LayoutFields, ListField, new Array<Key>());
}
//
@@ -49,9 +49,9 @@ export class DocumentView extends React.Component<DocumentViewProps> {
//
@computed
public get ScalingToScreenSpace(): number {
- if (this.props.ContainingCollectionView != undefined && this.props.ContainingCollectionView != WAITING &&
- this.props.ContainingCollectionView.props.ContainingDocumentView != undefined && this.props.ContainingCollectionView.props.ContainingDocumentView != WAITING) {
- let ss = this.props.ContainingCollectionView.props.DocumentForCollection.GetFieldValue(KeyStore.Scale, NumberField, Number(1));
+ if (this.props.ContainingCollectionView != undefined && this.props.ContainingCollectionView != FieldWaiting &&
+ this.props.ContainingCollectionView.props.ContainingDocumentView != undefined && this.props.ContainingCollectionView.props.ContainingDocumentView != FieldWaiting) {
+ let ss = this.props.ContainingCollectionView.props.DocumentForCollection.GetData(KeyStore.Scale, NumberField, Number(1));
return this.props.ContainingCollectionView.props.ContainingDocumentView.ScalingToScreenSpace * ss;
}
return 1;
@@ -63,15 +63,15 @@ export class DocumentView extends React.Component<DocumentViewProps> {
public TransformToLocalPoint(screenX: number, screenY: number) {
// if this collection view is nested within another collection view, then
// first transform the screen point into the parent collection's coordinate space.
- let { LocalX: parentX, LocalY: parentY } = this.props.ContainingCollectionView != undefined && this.props.ContainingCollectionView != WAITING &&
- this.props.ContainingCollectionView.props.ContainingDocumentView != undefined && this.props.ContainingCollectionView.props.ContainingDocumentView != WAITING ?
+ let { LocalX: parentX, LocalY: parentY } = this.props.ContainingCollectionView != undefined && this.props.ContainingCollectionView != FieldWaiting &&
+ this.props.ContainingCollectionView.props.ContainingDocumentView != undefined && this.props.ContainingCollectionView.props.ContainingDocumentView != FieldWaiting ?
this.props.ContainingCollectionView.props.ContainingDocumentView.TransformToLocalPoint(screenX, screenY) :
{ LocalX: screenX, LocalY: screenY };
let ContainerX: number = parentX - COLLECTION_BORDER_WIDTH;
let ContainerY: number = parentY - COLLECTION_BORDER_WIDTH;
- var Xx = this.props.Document.GetFieldValue(KeyStore.X, NumberField, Number(0));
- var Yy = this.props.Document.GetFieldValue(KeyStore.Y, NumberField, Number(0));
+ var Xx = this.props.Document.GetData(KeyStore.X, NumberField, Number(0));
+ var Yy = this.props.Document.GetData(KeyStore.Y, NumberField, Number(0));
// CollectionDockingViews change the location of their children frames without using a Dash transformation.
// They also ignore any transformation that may have been applied to their content document.
// NOTE: this currently assumes CollectionDockingViews aren't nested.
@@ -81,9 +81,9 @@ export class DocumentView extends React.Component<DocumentViewProps> {
Yy = ry - COLLECTION_BORDER_WIDTH;
}
- let Ss = this.props.Document.GetFieldValue(KeyStore.Scale, NumberField, Number(1));
- let Panxx = this.props.Document.GetFieldValue(KeyStore.PanX, NumberField, Number(0));
- let Panyy = this.props.Document.GetFieldValue(KeyStore.PanY, NumberField, Number(0));
+ let Ss = this.props.Document.GetData(KeyStore.Scale, NumberField, Number(1));
+ let Panxx = this.props.Document.GetData(KeyStore.PanX, NumberField, Number(0));
+ let Panyy = this.props.Document.GetData(KeyStore.PanY, NumberField, Number(0));
let LocalX = (ContainerX - (Xx + Panxx)) / Ss;
let LocalY = (ContainerY - (Yy + Panyy)) / Ss;
@@ -95,8 +95,8 @@ export class DocumentView extends React.Component<DocumentViewProps> {
//
public TransformToScreenPoint(localX: number, localY: number, Ss: number = 1, Panxx: number = 0, Panyy: number = 0): { ScreenX: number, ScreenY: number } {
- var Xx = this.props.Document.GetFieldValue(KeyStore.X, NumberField, Number(0));
- var Yy = this.props.Document.GetFieldValue(KeyStore.Y, NumberField, Number(0));
+ var Xx = this.props.Document.GetData(KeyStore.X, NumberField, Number(0));
+ var Yy = this.props.Document.GetData(KeyStore.Y, NumberField, Number(0));
// CollectionDockingViews change the location of their children frames without using a Dash transformation.
// They also ignore any transformation that may have been applied to their content document.
// NOTE: this currently assumes CollectionDockingViews aren't nested.
@@ -113,11 +113,11 @@ export class DocumentView extends React.Component<DocumentViewProps> {
// if this collection view is nested within another collection view, then
// first transform the local point into the parent collection's coordinate space.
- let containingDocView = this.props.ContainingCollectionView != undefined && this.props.ContainingCollectionView != WAITING ? this.props.ContainingCollectionView.props.ContainingDocumentView : undefined;
- if (containingDocView != undefined && containingDocView != WAITING) {
- let ss = containingDocView.props.Document.GetFieldValue(KeyStore.Scale, NumberField, Number(1));
- let panxx = containingDocView.props.Document.GetFieldValue(KeyStore.PanX, NumberField, Number(0)) + COLLECTION_BORDER_WIDTH * ss;
- let panyy = containingDocView.props.Document.GetFieldValue(KeyStore.PanY, NumberField, Number(0)) + COLLECTION_BORDER_WIDTH * ss;
+ let containingDocView = this.props.ContainingCollectionView != undefined && this.props.ContainingCollectionView != FieldWaiting ? this.props.ContainingCollectionView.props.ContainingDocumentView : undefined;
+ if (containingDocView != undefined && containingDocView != FieldWaiting) {
+ let ss = containingDocView.props.Document.GetData(KeyStore.Scale, NumberField, Number(1));
+ let panxx = containingDocView.props.Document.GetData(KeyStore.PanX, NumberField, Number(0)) + COLLECTION_BORDER_WIDTH * ss;
+ let panyy = containingDocView.props.Document.GetData(KeyStore.PanY, NumberField, Number(0)) + COLLECTION_BORDER_WIDTH * ss;
let { ScreenX, ScreenY } = containingDocView.TransformToScreenPoint(parentX, parentY, ss, panxx, panyy);
parentX = ScreenX;
parentY = ScreenY;
@@ -132,8 +132,8 @@ export class DocumentView extends React.Component<DocumentViewProps> {
bindings[key.Name + "Key"] = key; // this maps string values of the form <keyname>Key to an actual key Kestore.keyname e.g, "DataKey" => KeyStore.Data
}
for (const key of this.layoutFields) {
- let field = this.props.Document.GetField(key);
- bindings[key.Name] = field && field != WAITING ? field.GetValue() : field;
+ let field = this.props.Document.Get(key);
+ bindings[key.Name] = field && field != FieldWaiting ? field.GetValue() : field;
}
if (bindings.DocumentView === undefined) {
bindings.DocumentView = this; // set the DocumentView to this if it hasn't already been set by a sub-class during its render method.
diff --git a/src/views/nodes/FieldView.tsx b/src/views/nodes/FieldView.tsx
index 7c81ac55e..05a7b91b9 100644
--- a/src/views/nodes/FieldView.tsx
+++ b/src/views/nodes/FieldView.tsx
@@ -2,7 +2,7 @@ import React = require("react")
import { Document } from "../../fields/Document";
import { observer } from "mobx-react";
import { computed } from "mobx";
-import { Field, Opt, WAITING } from "../../fields/Field";
+import { Field, Opt, FieldWaiting } from "../../fields/Field";
import { TextField } from "../../fields/TextField";
import { NumberField } from "../../fields/NumberField";
import { RichTextField } from "../../fields/RichTextField";
@@ -29,7 +29,7 @@ export class FieldView extends React.Component<FieldViewProps> {
@computed
get field(): Opt<Field> {
const { doc, fieldKey } = this.props;
- return doc.GetField(fieldKey);
+ return doc.Get(fieldKey);
}
render() {
const field = this.field;
@@ -47,7 +47,7 @@ export class FieldView extends React.Component<FieldViewProps> {
}
else if (field instanceof NumberField) {
return <p>{field.Data}</p>
- } else if (field != WAITING) {
+ } else if (field != FieldWaiting) {
return <p>{field.GetValue}</p>
} else
return <p> {"Waiting for server..."} </p>
diff --git a/src/views/nodes/FormattedTextBox.tsx b/src/views/nodes/FormattedTextBox.tsx
index cf6a1181a..3e3e22e46 100644
--- a/src/views/nodes/FormattedTextBox.tsx
+++ b/src/views/nodes/FormattedTextBox.tsx
@@ -6,7 +6,7 @@ import { keymap } from "prosemirror-keymap";
import { schema } from "prosemirror-schema-basic";
import { EditorState, Transaction } from "prosemirror-state";
import { EditorView } from "prosemirror-view";
-import { Opt, WAITING } from "../../fields/Field";
+import { Opt, FieldWaiting } from "../../fields/Field";
import { SelectionManager } from "../../util/SelectionManager";
import "./FormattedTextBox.scss";
import React = require("react")
@@ -48,11 +48,11 @@ export class FormattedTextBox extends React.Component<FieldViewProps> {
}
dispatchTransaction = (tx: Transaction) => {
- if (this._editorView && this._editorView != WAITING) {
+ if (this._editorView && this._editorView != FieldWaiting) {
const state = this._editorView.state.apply(tx);
this._editorView.updateState(state);
const { doc, fieldKey } = this.props;
- doc.SetFieldValue(fieldKey, JSON.stringify(state.toJSON()), RichTextField);
+ doc.SetData(fieldKey, JSON.stringify(state.toJSON()), RichTextField);
}
}
@@ -68,8 +68,8 @@ export class FormattedTextBox extends React.Component<FieldViewProps> {
]
};
- let field = doc.GetFieldT(fieldKey, RichTextField);
- if (field && field != WAITING) { // bcz: don't think this works
+ let field = doc.GetT(fieldKey, RichTextField);
+ if (field && field != FieldWaiting) { // bcz: don't think this works
state = EditorState.fromJSON(config, JSON.parse(field.Data));
} else {
state = EditorState.create(config);
@@ -82,20 +82,20 @@ export class FormattedTextBox extends React.Component<FieldViewProps> {
}
this._reactionDisposer = reaction(() => {
- const field = this.props.doc.GetFieldT(this.props.fieldKey, RichTextField);
- return field && field != WAITING ? field.Data : undefined;
+ const field = this.props.doc.GetT(this.props.fieldKey, RichTextField);
+ return field && field != FieldWaiting ? field.Data : undefined;
}, (field) => {
- if (field && this._editorView && this._editorView != WAITING) {
+ if (field && this._editorView && this._editorView != FieldWaiting) {
this._editorView.updateState(EditorState.fromJSON(config, JSON.parse(field)));
}
})
}
componentWillUnmount() {
- if (this._editorView && this._editorView != WAITING) {
+ if (this._editorView && this._editorView != FieldWaiting) {
this._editorView.destroy();
}
- if (this._reactionDisposer && this._reactionDisposer != WAITING) {
+ if (this._reactionDisposer && this._reactionDisposer != FieldWaiting) {
this._reactionDisposer();
}
}
@@ -107,7 +107,7 @@ export class FormattedTextBox extends React.Component<FieldViewProps> {
@action
onChange(e: React.ChangeEvent<HTMLInputElement>) {
const { fieldKey, doc } = this.props;
- doc.SetFieldValue(fieldKey, e.target.value, RichTextField);
+ doc.SetData(fieldKey, e.target.value, RichTextField);
}
onPointerDown = (e: React.PointerEvent): void => {
let me = this;
diff --git a/src/views/nodes/ImageBox.tsx b/src/views/nodes/ImageBox.tsx
index 079cca8ab..123c76d19 100644
--- a/src/views/nodes/ImageBox.tsx
+++ b/src/views/nodes/ImageBox.tsx
@@ -7,7 +7,7 @@ import React = require("react")
import { ImageField } from '../../fields/ImageField';
import { FieldViewProps, FieldView } from './FieldView';
import { CollectionFreeFormDocumentView } from './CollectionFreeFormDocumentView';
-import { WAITING } from '../../fields/Field';
+import { FieldWaiting } from '../../fields/Field';
import { observer } from "mobx-react"
import { observable, action } from 'mobx';
@@ -79,9 +79,9 @@ export class ImageBox extends React.Component<FieldViewProps> {
}
render() {
- let field = this.props.doc.GetFieldT(this.props.fieldKey, ImageField);
- let path = field == WAITING ? "https://image.flaticon.com/icons/svg/66/66163.svg" :
- field instanceof ImageField ? field.Data.href : "";
+ let field = this.props.doc.Get(this.props.fieldKey);
+ let path = field == FieldWaiting ? "https://image.flaticon.com/icons/svg/66/66163.svg" :
+ field instanceof ImageField ? field.Data.href : "http://www.cs.brown.edu/~bcz/face.gif";
return (
<div className="imageBox-cont" onPointerDown={this.onPointerDown} ref={this._ref} >