diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Main.tsx | 10 | ||||
-rw-r--r-- | src/documents/Documents.ts | 90 | ||||
-rw-r--r-- | src/fields/Document.ts | 67 | ||||
-rw-r--r-- | src/fields/DocumentReference.ts | 2 | ||||
-rw-r--r-- | src/views/collections/CollectionDockingView.tsx | 12 | ||||
-rw-r--r-- | src/views/collections/CollectionFreeFormView.tsx | 44 | ||||
-rw-r--r-- | src/views/collections/CollectionSchemaView.tsx | 4 | ||||
-rw-r--r-- | src/views/collections/CollectionViewBase.tsx | 4 | ||||
-rw-r--r-- | src/views/nodes/CollectionFreeFormDocumentView.tsx | 20 | ||||
-rw-r--r-- | src/views/nodes/DocumentView.tsx | 30 | ||||
-rw-r--r-- | src/views/nodes/FieldView.tsx | 2 | ||||
-rw-r--r-- | src/views/nodes/FormattedTextBox.tsx | 8 | ||||
-rw-r--r-- | src/views/nodes/ImageBox.tsx | 2 |
13 files changed, 159 insertions, 136 deletions
diff --git a/src/Main.tsx b/src/Main.tsx index 1fc0ffe7f..f0e550f24 100644 --- a/src/Main.tsx +++ b/src/Main.tsx @@ -41,16 +41,16 @@ 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[0].SetData(KS.Author, "Tyler", TextField); + schemaDocs[4].SetData(KS.Author, "Bob", TextField); schemaDocs.push(doc2); const doc7 = Documents.SchemaDocument(schemaDocs) const docset = [doc1, doc2, doc3, doc7]; @@ -76,7 +76,7 @@ document.addEventListener("pointerdown", action(function (e: PointerEvent) { // mainNodes.Data.push(doc1); //mainNodes.Data.push(doc2); mainNodes.Data.push(doc6); - mainContainer.SetField(KeyStore.Data, mainNodes); + mainContainer.Set(KeyStore.Data, mainNodes); } //} //); diff --git a/src/documents/Documents.ts b/src/documents/Documents.ts index b69b79dd3..252ee9766 100644 --- a/src/documents/Documents.ts +++ b/src/documents/Documents.ts @@ -22,35 +22,35 @@ interface DocumentOptions { export namespace Documents { function setupOptions(doc: Document, options: DocumentOptions): void { 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); } if (options.title) { - doc.SetFieldValue(KeyStore.Title, options.title, TextField); + doc.SetData(KeyStore.Title, options.title, TextField); } - doc.SetFieldValue(KeyStore.Scale, 1, NumberField); - doc.SetFieldValue(KeyStore.PanX, 0, NumberField); - doc.SetFieldValue(KeyStore.PanY, 0, NumberField); + 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 +66,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 +79,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 +88,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,7 +101,7 @@ 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; } @@ -110,13 +110,13 @@ export namespace Documents { 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(ImageBox.LayoutString())); + 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.SetField(KeyStore.LayoutKeys, new ListField([KeyStore.Data])); + imageProto.Set(KeyStore.LayoutKeys, new ListField([KeyStore.Data])); } return imageProto; } @@ -124,7 +124,7 @@ export namespace Documents { export function ImageDocument(url: string, options: DocumentOptions = {}): Document { let doc = GetImagePrototype().MakeDelegate(); setupOptions(doc, options); - doc.SetField(KeyStore.Data, new ImageField(new URL(url))); + doc.Set(KeyStore.Data, new ImageField(new URL(url))); return doc; } @@ -132,15 +132,15 @@ export namespace Documents { 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; } @@ -148,7 +148,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 ef759615b..742149a03 100644 --- a/src/fields/Document.ts +++ b/src/fields/Document.ts @@ -10,9 +10,11 @@ export class Document extends Field { static _untitledDocName = "<untitled>"; @computed - public get Title() { return this.GetFieldValue(KeyStore.Title, TextField, Document._untitledDocName); } + public get Title() { + return this.GetData(KeyStore.Title, TextField, Document._untitledDocName); + } - GetField(key: Key, ignoreProto: boolean = false): Opt<Field> { + Get(key: Key, ignoreProto: boolean = false): Opt<Field> { let field: Opt<Field>; if (ignoreProto) { if (this.fields.has(key)) { @@ -32,39 +34,39 @@ export class Document extends Field { return field; } - GetFieldT<T extends Field = Field>(key: Key, ctor: { new(...args: any[]): T }, ignoreProto: boolean = false): Opt<T> { - return Cast(this.GetField(key, ignoreProto), ctor); + GetT<T extends Field = Field>(key: Key, ctor: { new(...args: any[]): T }, ignoreProto: boolean = false): Opt<T> { + return Cast(this.Get(key, ignoreProto), ctor); } - GetFieldOrCreate<T extends Field>(key: Key, ctor: { new(): T }, ignoreProto: boolean = false): T { - const field = this.GetFieldT(key, ctor, ignoreProto); + GetOrCreate<T extends Field>(key: Key, ctor: { new(): T }, ignoreProto: boolean = false): T { + const field = this.GetT(key, ctor, ignoreProto); if (field) { 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) } - SetField(key: Key, field: Field | undefined): void { + Set(key: Key, field: Field | undefined): void { if (field) { this.fields.set(key, field); } else { @@ -72,23 +74,44 @@ export class Document extends Field { } } - SetFieldValue<T extends Field>(key: Key, value: any, ctor: { new(): T }): boolean { - let field = this.GetField(key, 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 instanceof ctor) { + field.Data = value; + } else if (!field || replaceWrongType) { + let newField = new ctor(); + newField.Data = value; + this.Set(key, newField); + } + } + + SetVal<T extends Field>(key: Key, value: any, ctor: { new(): T }, replaceWrongType = true): boolean { + let field = this.Get(key, true); if (field != null) { return field.TrySetValue(value); - } else { + } else if (field && replaceWrongType) { field = new ctor(); if (field.TrySetValue(value)) { - this.SetField(key, field); + this.Set(key, field); return true; } else { return false; } + } else { + return false; } } + SetText(key: Key, value: string, replaceWrongType = true) { + this.SetData(key, value, TextField, replaceWrongType); + } + + 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[] { @@ -104,7 +127,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/views/collections/CollectionDockingView.tsx b/src/views/collections/CollectionDockingView.tsx index 92b5e563c..de68cf0d7 100644 --- a/src/views/collections/CollectionDockingView.tsx +++ b/src/views/collections/CollectionDockingView.tsx @@ -25,7 +25,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 }] }; }); @@ -41,7 +41,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 } }; }); @@ -93,7 +93,7 @@ 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) { return (<DocumentView key={value[i].Id} ContainingCollectionView={this} Document={value[i]} DocumentView={undefined} />); @@ -253,11 +253,11 @@ export class CollectionDockingView extends CollectionViewBase { render() { 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 cc907b2cc..c07a7e563 100644 --- a/src/views/collections/CollectionFreeFormView.tsx +++ b/src/views/collections/CollectionFreeFormView.tsx @@ -39,7 +39,7 @@ export class CollectionFreeFormView extends CollectionViewBase { 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!); - let sscale = this.props.ContainingDocumentView!.props.Document.GetFieldValue(KeyStore.Scale, NumberField, Number(1)) + 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; @@ -95,10 +95,10 @@ export class CollectionFreeFormView extends CollectionViewBase { 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; @@ -118,9 +118,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 @@ -130,8 +130,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 @@ -141,10 +141,10 @@ export class CollectionFreeFormView extends CollectionViewBase { let doc = Documents.ImageDocument(url, { x: x, y: y }) - let docs = that.props.DocumentForCollection.GetFieldT(KeyStore.Data, ListField); + let docs = that.props.DocumentForCollection.GetT(KeyStore.Data, ListField); if (!docs) { docs = new ListField<Document>(); - that.props.DocumentForCollection.SetField(KeyStore.Data, docs) + that.props.DocumentForCollection.Set(KeyStore.Data, docs) } docs.Data.push(doc); } @@ -162,26 +162,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 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 8503aaf1e..8817cb496 100644 --- a/src/views/collections/CollectionSchemaView.tsx +++ b/src/views/collections/CollectionSchemaView.tsx @@ -69,8 +69,8 @@ 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) { diff --git a/src/views/collections/CollectionViewBase.tsx b/src/views/collections/CollectionViewBase.tsx index 76145f12b..35d938d43 100644 --- a/src/views/collections/CollectionViewBase.tsx +++ b/src/views/collections/CollectionViewBase.tsx @@ -38,14 +38,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 ebe6d411c..23863ce18 100644 --- a/src/views/nodes/CollectionFreeFormDocumentView.tsx +++ b/src/views/nodes/CollectionFreeFormDocumentView.tsx @@ -30,20 +30,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 @@ -53,29 +53,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 diff --git a/src/views/nodes/DocumentView.tsx b/src/views/nodes/DocumentView.tsx index a1262e2ba..5be17fe54 100644 --- a/src/views/nodes/DocumentView.tsx +++ b/src/views/nodes/DocumentView.tsx @@ -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>()); } // @@ -50,7 +50,7 @@ export class DocumentView extends React.Component<DocumentViewProps> { @computed public get ScalingToScreenSpace(): number { if (this.props.ContainingCollectionView != undefined && this.props.ContainingCollectionView.props.ContainingDocumentView != undefined) { - let ss = this.props.ContainingCollectionView.props.DocumentForCollection.GetFieldValue(KeyStore.Scale, NumberField, Number(1)); + let ss = this.props.ContainingCollectionView.props.DocumentForCollection.GetData(KeyStore.Scale, NumberField, Number(1)); return this.props.ContainingCollectionView.props.ContainingDocumentView.ScalingToScreenSpace * ss; } return 1; @@ -68,8 +68,8 @@ export class DocumentView extends React.Component<DocumentViewProps> { 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. @@ -79,9 +79,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; @@ -93,8 +93,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,9 +113,9 @@ export class DocumentView extends React.Component<DocumentViewProps> { // first transform the local point into the parent collection's coordinate space. let containingDocView = this.props.ContainingCollectionView != undefined ? this.props.ContainingCollectionView.props.ContainingDocumentView : undefined; if (containingDocView != undefined) { - 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 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; @@ -133,7 +133,7 @@ export class DocumentView extends React.Component<DocumentViewProps> { if (bindings.DocumentView === undefined) bindings.DocumentView = this; for (const key of this.layoutFields) { - let field = doc.GetField(key); + let field = doc.Get(key); if (field) { bindings[key.Name] = field.GetValue(); } diff --git a/src/views/nodes/FieldView.tsx b/src/views/nodes/FieldView.tsx index 2a2355a23..71e24986a 100644 --- a/src/views/nodes/FieldView.tsx +++ b/src/views/nodes/FieldView.tsx @@ -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; diff --git a/src/views/nodes/FormattedTextBox.tsx b/src/views/nodes/FormattedTextBox.tsx index 9c4b24226..e00ab6701 100644 --- a/src/views/nodes/FormattedTextBox.tsx +++ b/src/views/nodes/FormattedTextBox.tsx @@ -50,7 +50,7 @@ export class FormattedTextBox extends React.Component<FieldViewProps> { 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); } } @@ -66,7 +66,7 @@ export class FormattedTextBox extends React.Component<FieldViewProps> { ] }; - let field = doc.GetFieldT(fieldKey, RichTextField); + let field = doc.GetT(fieldKey, RichTextField); if (field) { state = EditorState.fromJSON(config, JSON.parse(field.Data)); } else { @@ -80,7 +80,7 @@ export class FormattedTextBox extends React.Component<FieldViewProps> { } this._reactionDisposer = reaction(() => { - const field = this.props.doc.GetFieldT(this.props.fieldKey, RichTextField); + const field = this.props.doc.GetT(this.props.fieldKey, RichTextField); return field ? field.Data : undefined; }, (field) => { if (field && this._editorView) { @@ -105,7 +105,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 dd201f20f..eceb04b07 100644 --- a/src/views/nodes/ImageBox.tsx +++ b/src/views/nodes/ImageBox.tsx @@ -59,7 +59,7 @@ export class ImageBox extends React.Component<FieldViewProps, ImageBoxState> { } render() { - let field = this.props.doc.GetFieldT(this.props.fieldKey, ImageField); + let field = this.props.doc.GetT(this.props.fieldKey, ImageField); let path = ""; if (field) { path = field.Data.href; |