aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/documents/Documents.ts18
-rw-r--r--src/client/views/collections/CollectionFreeFormView.tsx20
-rw-r--r--src/client/views/collections/CollectionView.tsx2
-rw-r--r--src/client/views/collections/CollectionViewBase.tsx14
-rw-r--r--src/client/views/nodes/DocumentView.tsx8
-rw-r--r--src/client/views/nodes/FormattedTextBox.tsx8
-rw-r--r--src/client/views/nodes/ImageBox.tsx1
-rw-r--r--src/fields/Document.ts49
8 files changed, 79 insertions, 41 deletions
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts
index fc210e9a2..cc8052d44 100644
--- a/src/client/documents/Documents.ts
+++ b/src/client/documents/Documents.ts
@@ -111,7 +111,7 @@ export namespace Documents {
{ x: 0, y: 0, width: 300, height: 300, layoutKeys: [KeyStore.Data] });
}
function GetCollectionPrototype(): Document {
- return collProto ? collProto :
+ return collProto ? collProto.MakeDelegate() :
collProto = setupPrototypeOptions(collProtoId, "COLLECTION_PROTO", CollectionView.LayoutString("DataKey"),
{ panx: 0, pany: 0, scale: 1, layoutKeys: [KeyStore.Data] });
}
@@ -128,28 +128,28 @@ export namespace Documents {
doc.SetText(KeyStore.Caption, "my caption...");
doc.SetText(KeyStore.BackgroundLayout, EmbeddedCaption());
doc.SetText(KeyStore.OverlayLayout, FixedCaption());
- return doc;
+ return doc.MakeDelegate();
}
export function TextDocument(options: DocumentOptions = {}) {
- return SetInstanceOptions(GetTextPrototype(), options, "", TextField);
+ return SetInstanceOptions(GetTextPrototype(), options, "", TextField).MakeDelegate()
}
export function PdfDocument(url: string, options: DocumentOptions = {}) {
- return SetInstanceOptions(GetPdfPrototype(), options, new URL(url), PDFField);
+ return SetInstanceOptions(GetPdfPrototype(), options, new URL(url), PDFField).MakeDelegate();
}
export function WebDocument(url: string, options: DocumentOptions = {}) {
- return SetInstanceOptions(GetWebPrototype(), options, new URL(url), WebField);
+ return SetInstanceOptions(GetWebPrototype(), options, new URL(url), WebField).MakeDelegate();
}
export function HtmlDocument(html: string, options: DocumentOptions = {}) {
- return SetInstanceOptions(GetWebPrototype(), options, html, HtmlField);
+ return SetInstanceOptions(GetWebPrototype(), options, html, HtmlField).MakeDelegate();
}
export function FreeformDocument(documents: Array<Document>, options: DocumentOptions, id?: string) {
- return SetInstanceOptions(GetCollectionPrototype(), { ...options, viewType: CollectionViewType.Freeform }, documents, ListField, id)
+ return SetInstanceOptions(GetCollectionPrototype(), { ...options, viewType: CollectionViewType.Freeform }, documents, ListField, id).MakeDelegate()
}
export function SchemaDocument(documents: Array<Document>, options: DocumentOptions, id?: string) {
- return SetInstanceOptions(GetCollectionPrototype(), { ...options, viewType: CollectionViewType.Schema }, documents, ListField, id)
+ return SetInstanceOptions(GetCollectionPrototype(), { ...options, viewType: CollectionViewType.Schema }, documents, ListField, id).MakeDelegate()
}
export function DockDocument(config: string, options: DocumentOptions, id?: string) {
- return SetInstanceOptions(GetCollectionPrototype(), { ...options, viewType: CollectionViewType.Docking }, config, TextField, id)
+ return SetInstanceOptions(GetCollectionPrototype(), { ...options, viewType: CollectionViewType.Docking }, config, TextField, id).MakeDelegate()
}
export function KVPDocument(document: Document, options: DocumentOptions = {}, id?: string) {
var deleg = GetKVPPrototype().MakeDelegate(id);
diff --git a/src/client/views/collections/CollectionFreeFormView.tsx b/src/client/views/collections/CollectionFreeFormView.tsx
index 16002ad9f..95b4f6f19 100644
--- a/src/client/views/collections/CollectionFreeFormView.tsx
+++ b/src/client/views/collections/CollectionFreeFormView.tsx
@@ -58,14 +58,18 @@ export class CollectionFreeFormView extends CollectionViewBase {
@action
drop = (e: Event, de: DragManager.DropEvent) => {
super.drop(e, de);
- const docView: DocumentView = de.data["documentView"];
- let doc: Document = docView ? docView.props.Document : de.data["document"];
- let screenX = de.x - (de.data["xOffset"] as number || 0);
- let screenY = de.y - (de.data["yOffset"] as number || 0);
- const [x, y] = this.getTransform().transformPoint(screenX, screenY);
- doc.SetNumber(KeyStore.X, x);
- doc.SetNumber(KeyStore.Y, y);
- this.bringToFront(doc);
+
+ if (!de.data["alias"]) {
+ const docView: DocumentView = de.data["documentView"];
+ const doc = docView ? docView.props.Document : de.data["document"]
+ //this should be able to use translate and scale methods on an Identity transform, no?
+ let screenX = de.x - (de.data["xOffset"] as number || 0);
+ let screenY = de.y - (de.data["yOffset"] as number || 0);
+ const [x, y] = this.getTransform().transformPoint(screenX, screenY);
+ doc.SetNumber(KeyStore.X, x);
+ doc.SetNumber(KeyStore.Y, y);
+ this.bringToFront(doc);
+ }
}
@action
diff --git a/src/client/views/collections/CollectionView.tsx b/src/client/views/collections/CollectionView.tsx
index 49df04163..47807116b 100644
--- a/src/client/views/collections/CollectionView.tsx
+++ b/src/client/views/collections/CollectionView.tsx
@@ -53,7 +53,7 @@ export class CollectionView extends React.Component<CollectionViewProps> {
const value = props.Document.GetData(props.fieldKey, ListField, new Array<Document>())
value.push(doc);
} else {
- props.Document.SetData(props.fieldKey, [doc], ListField);
+ props.Document.SetOnPrototype(props.fieldKey, new ListField([doc]));
}
}
diff --git a/src/client/views/collections/CollectionViewBase.tsx b/src/client/views/collections/CollectionViewBase.tsx
index 0a3b965f2..f3770056d 100644
--- a/src/client/views/collections/CollectionViewBase.tsx
+++ b/src/client/views/collections/CollectionViewBase.tsx
@@ -46,15 +46,17 @@ export class CollectionViewBase extends React.Component<SubCollectionViewProps>
@action
protected drop(e: Event, de: DragManager.DropEvent) {
const docView: DocumentView = de.data["documentView"];
- const doc: Document = de.data["document"];
+ const doc: Document = de.data["document"]
if (docView && docView.props.ContainingCollectionView && docView.props.ContainingCollectionView !== this.props.CollectionView) {
- if (docView.props.RemoveDocument) {
- docView.props.RemoveDocument(docView.props.Document);
+ if (docView.props.RemoveDocument && !de.data["alias"]) {
+ docView.props.RemoveDocument(docView.props.Document)
}
- this.props.addDocument(docView.props.Document);
+ this.props.addDocument(de.data["alias"] ? docView.props.Document.CreateAlias() : docView.props.Document)
} else if (doc) {
- this.props.removeDocument(doc);
- this.props.addDocument(doc);
+ if (!de.data["alias"]) {
+ this.props.removeDocument(doc)
+ }
+ this.props.addDocument(doc)
}
e.stopPropagation();
}
diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx
index 41e93df35..e109f2a38 100644
--- a/src/client/views/nodes/DocumentView.tsx
+++ b/src/client/views/nodes/DocumentView.tsx
@@ -22,6 +22,7 @@ import { WebBox } from "../nodes/WebBox";
import { PDFBox } from "../nodes/PDFBox";
import "./DocumentView.scss";
import React = require("react");
+import { props } from "bluebird";
const JsxParser = require('react-jsx-parser').default; //TODO Why does this need to be imported like this?
@@ -96,7 +97,8 @@ export class DocumentView extends React.Component<DocumentViewProps> {
this._downX = e.clientX;
this._downY = e.clientY;
if (e.shiftKey && e.buttons === 1) {
- CollectionDockingView.Instance.StartOtherDrag(this.props.Document, e);
+ let document = e.ctrlKey ? this.props.Document.CreateAlias() : this.props.Document
+ CollectionDockingView.Instance.StartOtherDrag(document, e);
e.stopPropagation();
} else {
if (this.active && !e.isDefaultPrevented()) {
@@ -122,13 +124,15 @@ export class DocumentView extends React.Component<DocumentViewProps> {
const [left, top] = this.props.ScreenToLocalTransform().inverse().transformPoint(0, 0);
let dragData: { [id: string]: any } = {};
dragData["documentView"] = this;
+ dragData["document"] = e.ctrlKey ? this.props.Document.CreateAlias() : this.props.Document
dragData["xOffset"] = e.x - left;
dragData["yOffset"] = e.y - top;
+ dragData["alias"] = e.ctrlKey
DragManager.StartDrag(this._mainCont.current, dragData, {
handlers: {
dragComplete: action(() => { }),
},
- hideSource: true
+ hideSource: !e.ctrlKey
})
}
}
diff --git a/src/client/views/nodes/FormattedTextBox.tsx b/src/client/views/nodes/FormattedTextBox.tsx
index a6cee9957..3c78e21e0 100644
--- a/src/client/views/nodes/FormattedTextBox.tsx
+++ b/src/client/views/nodes/FormattedTextBox.tsx
@@ -52,7 +52,9 @@ export class FormattedTextBox extends React.Component<FieldViewProps> {
if (this._editorView) {
const state = this._editorView.state.apply(tx);
this._editorView.updateState(state);
- this.props.doc.SetData(this.props.fieldKey, JSON.stringify(state.toJSON()), RichTextField);
+ const { doc, fieldKey } = this.props;
+ doc.SetOnPrototype(fieldKey, new RichTextField(JSON.stringify(state.toJSON())))
+ // doc.SetData(fieldKey, JSON.stringify(state.toJSON()), RichTextField);
}
}
@@ -110,7 +112,9 @@ export class FormattedTextBox extends React.Component<FieldViewProps> {
@action
onChange(e: React.ChangeEvent<HTMLInputElement>) {
- this.props.doc.SetData(this.props.fieldKey, e.target.value, RichTextField);
+ const { fieldKey, doc } = this.props;
+ doc.SetOnPrototype(fieldKey, new RichTextField(e.target.value))
+ // doc.SetData(fieldKey, e.target.value, RichTextField);
}
onPointerDown = (e: React.PointerEvent): void => {
if (e.buttons === 1 && this.props.isSelected()) {
diff --git a/src/client/views/nodes/ImageBox.tsx b/src/client/views/nodes/ImageBox.tsx
index 30910fb1f..195c66cc0 100644
--- a/src/client/views/nodes/ImageBox.tsx
+++ b/src/client/views/nodes/ImageBox.tsx
@@ -99,6 +99,7 @@ export class ImageBox extends React.Component<FieldViewProps> {
render() {
let field = this.props.doc.Get(this.props.fieldKey);
+ console.log(field)
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";
let nativeWidth = this.props.doc.GetNumber(KeyStore.NativeWidth, 1);
diff --git a/src/fields/Document.ts b/src/fields/Document.ts
index 2e873439c..d5ff32c6f 100644
--- a/src/fields/Document.ts
+++ b/src/fields/Document.ts
@@ -2,7 +2,7 @@ import { Key } from "./Key"
import { KeyStore } from "./KeyStore";
import { Field, Cast, FieldWaiting, FieldValue, FieldId } from "./Field"
import { NumberField } from "./NumberField";
-import { ObservableMap, computed, action } from "mobx";
+import { ObservableMap, computed, action, runInAction } from "mobx";
import { TextField } from "./TextField";
import { ListField } from "./ListField";
import { Server } from "../client/Server";
@@ -201,25 +201,37 @@ export class Document extends Field {
}
@action
- Set(key: Key, field: Field | undefined): void {
+ SetOnPrototype(key: Key, field: Field | undefined): void {
+ this.GetAsync(KeyStore.Prototype, (f: Field) => {
+ (f as Document).Set(key, field)
+ })
+ }
+
+ @action
+ Set(key: Key, field: Field | undefined, setOnPrototype = false): void {
let old = this.fields.get(key.Id);
let oldField = old ? old.field : undefined;
- if (field) {
- this.fields.set(key.Id, { key, field });
- this._proxies.set(key.Id, field.Id)
- // Server.AddDocumentField(this, key, field);
- } else {
- this.fields.delete(key.Id);
- this._proxies.delete(key.Id)
- // Server.DeleteDocumentField(this, key);
+ if (setOnPrototype) {
+ this.SetOnPrototype(key, field)
+ }
+ else {
+ if (field) {
+ this.fields.set(key.Id, { key, field });
+ this._proxies.set(key.Id, field.Id)
+ // Server.AddDocumentField(this, key, field);
+ } else {
+ this.fields.delete(key.Id);
+ this._proxies.delete(key.Id)
+ // Server.DeleteDocumentField(this, key);
+ }
+ Server.UpdateField(this);
}
if (oldField || field) {
UndoManager.AddEvent({
- undo: () => this.Set(key, oldField),
- redo: () => this.Set(key, field)
+ undo: () => this.Set(key, oldField, setOnPrototype),
+ redo: () => this.Set(key, field, setOnPrototype)
})
}
- Server.UpdateField(this);
}
@action
@@ -259,6 +271,17 @@ export class Document extends Field {
return protos;
}
+ CreateAlias(id?: string): Document {
+ let alias = new Document(id)
+ this.GetAsync(KeyStore.Prototype, (f: Field) => {
+ alias.Set(KeyStore.Prototype, f)
+ })
+ alias.SetNumber(KeyStore.Width, 300)
+ alias.SetNumber(KeyStore.Height, 300)
+
+ return alias
+ }
+
MakeDelegate(id?: string): Document {
let delegate = new Document(id);