diff options
Diffstat (limited to 'src/new_fields')
-rw-r--r-- | src/new_fields/Doc.ts | 17 | ||||
-rw-r--r-- | src/new_fields/List.ts | 8 |
2 files changed, 17 insertions, 8 deletions
diff --git a/src/new_fields/Doc.ts b/src/new_fields/Doc.ts index 0e5105761..c4ad5ae95 100644 --- a/src/new_fields/Doc.ts +++ b/src/new_fields/Doc.ts @@ -1,7 +1,6 @@ import { observable, action } from "mobx"; import { serializable, primitive, map, alias, list } from "serializr"; import { autoObject, SerializationHelper, Deserializable } from "../client/util/SerializationHelper"; -import { Utils } from "../Utils"; import { DocServer } from "../client/DocServer"; import { setter, getter, getField, updateFunction, deleteProperty } from "./util"; import { Cast, ToConstructor, PromiseValue, FieldValue, NumCast } from "./Types"; @@ -10,6 +9,7 @@ import { listSpec } from "./Schema"; import { List } from "./List"; import { ObjectField, Parent, OnUpdate } from "./ObjectField"; import { RefField, FieldId, Id } from "./RefField"; +import { Docs } from "../client/documents/Documents"; export function IsField(field: any): field is Field { return (typeof field === "string") @@ -36,6 +36,15 @@ export class Doc extends RefField { set: setter, get: getter, ownKeys: target => Object.keys(target.__fields), + getOwnPropertyDescriptor: (target, prop) => { + if (prop in target.__fields) { + return { + configurable: true,//TODO Should configurable be true? + enumerable: true, + }; + } + return Reflect.getOwnPropertyDescriptor(target, prop); + }, deleteProperty: deleteProperty, defineProperty: () => { throw new Error("Currently properties can't be defined on documents using Object.defineProperty"); }, }); @@ -154,9 +163,9 @@ export namespace Doc { return copy; } - export function MakeLink(source: Doc, target: Doc): Doc { - return UndoManager.RunInBatch(() => { - let linkDoc = new Doc; + export function MakeLink(source: Doc, target: Doc) { + UndoManager.RunInBatch(() => { + let linkDoc = Docs.TextDocument({ width: 100, height: 30, borderRounding: -1 }); linkDoc.title = "New Link"; linkDoc.linkDescription = ""; linkDoc.linkTags = "Default"; diff --git a/src/new_fields/List.ts b/src/new_fields/List.ts index c1bd15cd1..3325302aa 100644 --- a/src/new_fields/List.ts +++ b/src/new_fields/List.ts @@ -1,5 +1,5 @@ import { Deserializable, autoObject } from "../client/util/SerializationHelper"; -import { Field, Update, Self } from "./Doc"; +import { Field, Update, Self, FieldResult } from "./Doc"; import { setter, getter, deleteProperty } from "./util"; import { serializable, alias, list } from "serializr"; import { observable, observe, IArrayChange, IArraySplice, IObservableArray, Lambda, reaction } from "mobx"; @@ -194,17 +194,17 @@ type ListUpdate<T> = ListSpliceUpdate<T> | ListIndexUpdate<T>; class ListImpl<T extends Field> extends ObjectField { constructor(fields: T[] = []) { super(); - this.___fields = fields; const list = new Proxy<this>(this, { set: setter, get: listGetter, deleteProperty: deleteProperty, defineProperty: () => { throw new Error("Currently properties can't be defined on documents using Object.defineProperty"); }, }); + (list as any).push(...fields); return list; } - [key: number]: T | null | undefined; + [key: number]: FieldResult<T>; @serializable(alias("fields", list(autoObject()))) private get __fields() { @@ -221,7 +221,7 @@ class ListImpl<T extends Field> extends ObjectField { // @serializable(alias("fields", list(autoObject()))) @observable - private ___fields: (T | null | undefined)[]; + private ___fields: (T extends RefField ? ProxyField<T> : T)[] = []; private [Update] = (diff: any) => { // console.log(diff); |