aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/documents/Documents.ts3
-rw-r--r--src/fields/Document.ts15
-rw-r--r--src/views/nodes/CollectionFreeFormDocumentView.tsx1
-rw-r--r--src/views/nodes/DocumentView.tsx6
-rw-r--r--src/views/nodes/FormattedTextBox.tsx4
-rw-r--r--src/views/nodes/ImageBox.tsx46
6 files changed, 28 insertions, 47 deletions
diff --git a/src/documents/Documents.ts b/src/documents/Documents.ts
index c51feedf5..ae6ae9833 100644
--- a/src/documents/Documents.ts
+++ b/src/documents/Documents.ts
@@ -117,9 +117,8 @@ export namespace Documents {
imageProto.SetFieldValue(KeyStore.Height, 300, NumberField);
imageProto.SetFieldValue(KeyStore.Layout, ImageBox.LayoutString(), TextField);
// imageProto.SetField(KeyStore.Layout, new TextField('<div style={"background-image: " + {Data}} />'));
- // bcz: use LayoutKeys or LayoutFields?
imageProto.SetFieldValue(KeyStore.LayoutKeys, [KeyStore.Data], ListField);
- //imageProto.SetFieldValue(KeyStore.LayoutFields, [KeyStore.Data], ListField);
+ imageProto.SetFieldValue(KeyStore.Data, "", TextField); // bcz: just for testing purposes
}
return imageProto;
}
diff --git a/src/fields/Document.ts b/src/fields/Document.ts
index 5e9c3a707..691b0f662 100644
--- a/src/fields/Document.ts
+++ b/src/fields/Document.ts
@@ -1,7 +1,7 @@
import { Field, Cast, Opt, Waiting, WAITING } from "./Field"
import { Key, KeyStore } from "./Key"
import { NumberField } from "./NumberField";
-import { ObservableMap, computed, action, observable } from "mobx";
+import { ObservableMap, computed, action } from "mobx";
import { TextField } from "./TextField";
import { ListField } from "./ListField";
@@ -20,17 +20,16 @@ export class Document extends Field {
this.fields.set(key, sfield);
}
- @observable
+ static times = 0;
GetFieldFromServerDeferred(key: Key) {
var me = this;
setTimeout(function () {
if (me) {
me.DeferredSetField(key);
}
- }, key == KeyStore.Data ? 5000 : key == KeyStore.X ? 2500 : 500)
+ }, key == KeyStore.Data ? (Document.times++ == 0 ? 5000 : 1000) : key == KeyStore.X ? 2500 : 500)
}
- @observable
GetField(key: Key, ignoreProto: boolean = false): Opt<Field> {
let field: Opt<Field> = WAITING;
if (ignoreProto) {
@@ -55,7 +54,6 @@ export class Document extends Field {
return field;
}
- @observable
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) {
@@ -64,7 +62,6 @@ export class Document extends Field {
return WAITING;
}
- @observable
GetFieldOrCreate<T extends Field>(key: Key, ctor: { new(): T }, ignoreProto: boolean = false): T {
const field = this.GetFieldT(key, ctor, ignoreProto);
if (field && field != WAITING) {
@@ -75,24 +72,20 @@ export class Document extends Field {
return newField;
}
- @observable
GetFieldValue<T, U extends { Data: T }>(key: Key, ctor: { new(): U }, defaultVal: T): T {
let val = this.GetField(key);
let vval = (val && val instanceof ctor) ? val.Data : defaultVal;
return vval;
}
- @observable
GetNumberField(key: Key, defaultVal: number): number {
return this.GetFieldValue(key, NumberField, defaultVal);
}
- @observable
GetTextField(key: Key, defaultVal: string): string {
return this.GetFieldValue(key, TextField, defaultVal);
}
- @observable
GetListField<T extends Field>(key: Key, defaultVal: T[]): T[] {
return this.GetFieldValue<T[], ListField<T>>(key, ListField, defaultVal)
}
@@ -130,12 +123,10 @@ export class Document extends Field {
// return false;
}
- @observable
GetPrototype(): Opt<Document> {
return this.GetFieldT(KeyStore.Prototype, Document, true);
}
- @observable
GetAllPrototypes(): Document[] {
let protos: Document[] = [];
let doc: Opt<Document> = this;
diff --git a/src/views/nodes/CollectionFreeFormDocumentView.tsx b/src/views/nodes/CollectionFreeFormDocumentView.tsx
index 06ea0c64b..d98c8dcb7 100644
--- a/src/views/nodes/CollectionFreeFormDocumentView.tsx
+++ b/src/views/nodes/CollectionFreeFormDocumentView.tsx
@@ -207,7 +207,6 @@ export class CollectionFreeFormDocumentView extends DocumentView {
render() {
var freestyling = this.props.ContainingCollectionView instanceof CollectionFreeFormView;
- console.log("CollectionFFDocView " + this.props.Document.Title);
return (
<div className="node" ref={this._mainCont} style={{
transform: freestyling ? this.transform : "",
diff --git a/src/views/nodes/DocumentView.tsx b/src/views/nodes/DocumentView.tsx
index 69184cf16..cfd894a38 100644
--- a/src/views/nodes/DocumentView.tsx
+++ b/src/views/nodes/DocumentView.tsx
@@ -129,17 +129,15 @@ export class DocumentView extends React.Component<DocumentViewProps> {
render() {
let bindings = { ...this.props } as any;
for (const key of this.layoutKeys) {
- //let val = this.props.Document.GetField(key); // bcz: ARGH! Why do I need to call this here? (e.g., it's needed and used in ImageBox- shouldn't that trigger a re-render?)
- bindings[key.Name + "Key"] = key;
+ 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;
}
if (bindings.DocumentView === undefined) {
- bindings.DocumentView = this;
+ bindings.DocumentView = this; // set the DocumentView to this if it hasn't already been set by a sub-class during its render method.
}
- console.log("DocumentView Rendering " + this.props.Document.Title);
return (
<div className="node" ref={this._mainCont} style={{ width: "100%", height: "100%", }}>
<JsxParser
diff --git a/src/views/nodes/FormattedTextBox.tsx b/src/views/nodes/FormattedTextBox.tsx
index f0385c096..cf6a1181a 100644
--- a/src/views/nodes/FormattedTextBox.tsx
+++ b/src/views/nodes/FormattedTextBox.tsx
@@ -1,4 +1,5 @@
import { action, IReactionDisposer, reaction } from "mobx";
+import { observer } from "mobx-react"
import { baseKeymap } from "prosemirror-commands";
import { history, redo, undo } from "prosemirror-history";
import { keymap } from "prosemirror-keymap";
@@ -29,7 +30,8 @@ import { CollectionFreeFormDocumentView } from "./CollectionFreeFormDocumentView
// When rendered() by React, this extracts the TextController from the Document stored at the
// specified Key and assigns it to an HTML input node. When changes are made tot his node,
// this will edit the document and assign the new value to that field.
-//
+//]
+@observer
export class FormattedTextBox extends React.Component<FieldViewProps> {
public static LayoutString() { return FieldView.LayoutString("FormattedTextBox"); }
diff --git a/src/views/nodes/ImageBox.tsx b/src/views/nodes/ImageBox.tsx
index 9b086d373..079cca8ab 100644
--- a/src/views/nodes/ImageBox.tsx
+++ b/src/views/nodes/ImageBox.tsx
@@ -8,20 +8,19 @@ import { ImageField } from '../../fields/ImageField';
import { FieldViewProps, FieldView } from './FieldView';
import { CollectionFreeFormDocumentView } from './CollectionFreeFormDocumentView';
import { WAITING } from '../../fields/Field';
-import { Key, KeyStore } from '../../fields/Key';
+import { observer } from "mobx-react"
+import { observable, action } from 'mobx';
-interface ImageBoxState {
- photoIndex: number,
- isOpen: boolean,
-};
+@observer
+export class ImageBox extends React.Component<FieldViewProps> {
-export class ImageBox extends React.Component<FieldViewProps, ImageBoxState> {
-
- public static LayoutString() { return FieldView.LayoutString("ImageBox DataVal={Data} "); }
+ public static LayoutString() { return FieldView.LayoutString("ImageBox"); }
private _ref: React.RefObject<HTMLDivElement>;
private _downX: number = 0;
private _downY: number = 0;
private _lastTap: number = 0;
+ @observable private _photoIndex: number = 0;
+ @observable private _isOpen: boolean = false;
constructor(props: FieldViewProps) {
super(props);
@@ -52,44 +51,37 @@ export class ImageBox extends React.Component<FieldViewProps, ImageBoxState> {
this._lastTap = Date.now();
}
}
+ @action
onPointerUp = (e: PointerEvent): void => {
document.removeEventListener("pointerup", this.onPointerUp);
if (Math.abs(e.clientX - this._downX) < 2 && Math.abs(e.clientY - this._downY) < 2) {
- this.setState({ isOpen: true })
+ this._isOpen = true;
}
e.stopPropagation();
}
lightbox = (path: string) => {
const images = [path, "http://www.cs.brown.edu/~bcz/face.gif"];
- const { photoIndex } = this.state;
- if (this.state.isOpen && this.props.DocumentViewForField instanceof CollectionFreeFormDocumentView && SelectionManager.IsSelected(this.props.DocumentViewForField)) {
+ if (this._isOpen && this.props.DocumentViewForField instanceof CollectionFreeFormDocumentView && SelectionManager.IsSelected(this.props.DocumentViewForField)) {
return (<Lightbox
- mainSrc={images[photoIndex]}
- nextSrc={images[(photoIndex + 1) % images.length]}
- prevSrc={images[(photoIndex + images.length - 1) % images.length]}
+ mainSrc={images[this._photoIndex]}
+ nextSrc={images[(this._photoIndex + 1) % images.length]}
+ prevSrc={images[(this._photoIndex + images.length - 1) % images.length]}
onCloseRequest={() => this.setState({ isOpen: false })}
- onMovePrevRequest={() =>
- this.setState({ photoIndex: (photoIndex + images.length - 1) % images.length, })
- }
- onMoveNextRequest={() =>
- this.setState({ photoIndex: (photoIndex + 1) % images.length, })
- }
+ onMovePrevRequest={action(() =>
+ this._photoIndex = (this._photoIndex + images.length - 1) % images.length
+ )}
+ onMoveNextRequest={action(() =>
+ this._photoIndex = (this._photoIndex + 1) % images.length
+ )}
/>)
}
}
render() {
-
- // bcz: use LayoutFields (here) or LayoutKeys (below)?
- // let field = (this.props as any).DataVal;//this.props.doc.GetFieldT(this.props.fieldKey, ImageField);
- // let path = field == WAITING ? "https://image.flaticon.com/icons/svg/66/66163.svg" :
- // field instanceof URL ? field.href : "";
-
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 : "";
- console.log("ImageBox Rendering " + this.props.doc.Title);
return (
<div className="imageBox-cont" onPointerDown={this.onPointerDown} ref={this._ref} >