aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/views/DocumentDecorations.tsx8
-rw-r--r--src/client/views/collections/collectionFreeForm/CollectionFreeFormLinksView.tsx4
-rw-r--r--src/new_fields/Doc.ts9
-rw-r--r--src/new_fields/List.ts2
-rw-r--r--src/new_fields/util.ts16
5 files changed, 26 insertions, 13 deletions
diff --git a/src/client/views/DocumentDecorations.tsx b/src/client/views/DocumentDecorations.tsx
index 3ed8ba3b2..2a6d72dbc 100644
--- a/src/client/views/DocumentDecorations.tsx
+++ b/src/client/views/DocumentDecorations.tsx
@@ -57,8 +57,8 @@ export class DocumentDecorations extends React.Component<{}, { value: string }>
reaction(() => SelectionManager.SelectedDocuments().slice(), (docs) => docs.length === 0 && (this._edtingTitle = false));
}
- @action titleChanged = (event: any) => { this._title = event.target.value; }
- @action titleBlur = () => { this._edtingTitle = false; }
+ @action titleChanged = (event: any) => { this._title = event.target.value; };
+ @action titleBlur = () => { this._edtingTitle = false; };
@action titleEntered = (e: any) => {
var key = e.keyCode || e.which;
// enter pressed
@@ -238,7 +238,7 @@ export class DocumentDecorations extends React.Component<{}, { value: string }>
iconDoc.y = NumCast(doc.y) - 24;
iconDoc.maximizedDoc = doc;
doc.minimizedDoc = iconDoc;
- console.log("Layout " + iconDoc.layout)
+ console.log("Layout " + iconDoc.layout);
docView.props.addDocument && docView.props.addDocument(iconDoc, false);
return iconDoc;
}
@@ -274,7 +274,7 @@ export class DocumentDecorations extends React.Component<{}, { value: string }>
minDocs.map(minDoc => {
minDoc.x = NumCast(minDocs[0].x);
minDoc.y = NumCast(minDocs[0].y);
- minDoc.linkTags = new List(minDocs.filter(d => d != minDoc));
+ minDoc.linkTags = new List(minDocs.filter(d => d !== minDoc));
if (this._iconifying && selectedDocs[0].props.removeDocument) {
selectedDocs[0].props.removeDocument(minDoc);
(minDoc.maximizedDoc as Doc).minimizedDoc = undefined;
diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormLinksView.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormLinksView.tsx
index 4a75fccff..b34e0856e 100644
--- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormLinksView.tsx
+++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormLinksView.tsx
@@ -60,11 +60,11 @@ export class CollectionFreeFormLinksView extends React.Component<CollectionViewP
}
let dstBrushDocs = Cast(dstTarg.brushingDocs, listSpec(Doc));
if (dstBrushDocs === undefined) {
- dstTarg.brushingDocs = dstBrushDocs = new List();
+ dstTarg.brushingDocs = dstBrushDocs = new List<Doc>();
}
let srcBrushDocs = Cast(srcTarg.brushingDocs, listSpec(Doc));
if (srcBrushDocs === undefined) {
- srcTarg.brushingDocs = srcBrushDocs = new List();
+ srcTarg.brushingDocs = srcBrushDocs = new List<Doc>();
}
brushAction(dstBrushDocs);
brushAction(srcBrushDocs);
diff --git a/src/new_fields/Doc.ts b/src/new_fields/Doc.ts
index 113380ce8..b2979af11 100644
--- a/src/new_fields/Doc.ts
+++ b/src/new_fields/Doc.ts
@@ -25,6 +25,7 @@ export type FieldResult<T extends Field = Field> = Opt<T> | FieldWaiting<Extract
export const Update = Symbol("Update");
export const Self = Symbol("Self");
+const SelfProxy = Symbol("SelfProxy");
export const WidthSym = Symbol("Width");
export const HeightSym = Symbol("Height");
@@ -48,6 +49,7 @@ export class Doc extends RefField {
deleteProperty: deleteProperty,
defineProperty: () => { throw new Error("Currently properties can't be defined on documents using Object.defineProperty"); },
});
+ this[SelfProxy] = doc;
if (!id || forceSave) {
DocServer.CreateField(SerializationHelper.Serialize(doc));
}
@@ -68,7 +70,7 @@ export class Doc extends RefField {
const field = value[key];
if (!(field instanceof ObjectField)) continue;
field[Parent] = this[Self];
- field[OnUpdate] = updateFunction(this[Self], key, field);
+ field[OnUpdate] = updateFunction(this[Self], key, field, this[SelfProxy]);
}
}
@@ -81,8 +83,9 @@ export class Doc extends RefField {
}
private [Self] = this;
- public [WidthSym] = () => { return NumCast(this.__fields.width); } // bcz: is this the right way to access width/height? it didn't work with : this.width
- public [HeightSym] = () => { return NumCast(this.__fields.height); }
+ private [SelfProxy]: any;
+ public [WidthSym] = () => NumCast(this.__fields.width); // bcz: is this the right way to access width/height? it didn't work with : this.width
+ public [HeightSym] = () => NumCast(this.__fields.height);
}
export namespace Doc {
diff --git a/src/new_fields/List.ts b/src/new_fields/List.ts
index 5852e2c30..ff10a3f73 100644
--- a/src/new_fields/List.ts
+++ b/src/new_fields/List.ts
@@ -218,7 +218,7 @@ class ListImpl<T extends Field> extends ObjectField {
}
[Copy]() {
- let copiedData = this.__fields.map(f => f instanceof ObjectField ? f[Copy]() : f);
+ let copiedData = this[Self].__fields.map(f => f instanceof ObjectField ? f[Copy]() : f);
let deepCopy = new ListImpl<T>(copiedData as any);
return deepCopy;
}
diff --git a/src/new_fields/util.ts b/src/new_fields/util.ts
index 128817ab8..bbd8157f6 100644
--- a/src/new_fields/util.ts
+++ b/src/new_fields/util.ts
@@ -31,7 +31,7 @@ export const setter = action(function (target: any, prop: string | symbol | numb
throw new Error("Can't put the same object in multiple documents at the same time");
}
value[Parent] = target;
- value[OnUpdate] = updateFunction(target, prop, value);
+ value[OnUpdate] = updateFunction(target, prop, value, receiver);
}
if (curValue instanceof ObjectField) {
delete curValue[Parent];
@@ -86,9 +86,19 @@ export function deleteProperty(target: any, prop: string | number | symbol) {
throw new Error("Currently properties can't be deleted from documents, assign to undefined instead");
}
-export function updateFunction(target: any, prop: any, value: any) {
+export function updateFunction(target: any, prop: any, value: any, receiver: any) {
+ let current = ObjectField.MakeCopy(value);
return (diff?: any) => {
- if (!diff) diff = { '$set': { ["fields." + prop]: SerializationHelper.Serialize(value) } };
+ if (true || !diff) {
+ diff = { '$set': { ["fields." + prop]: SerializationHelper.Serialize(value) } };
+ const oldValue = current;
+ const newValue = ObjectField.MakeCopy(value);
+ current = newValue;
+ UndoManager.AddEvent({
+ redo() { receiver[prop] = newValue; },
+ undo() { receiver[prop] = oldValue; }
+ });
+ }
target[Update](diff);
};
} \ No newline at end of file