diff options
author | usodhi <61431818+usodhi@users.noreply.github.com> | 2020-05-04 12:22:04 +0530 |
---|---|---|
committer | usodhi <61431818+usodhi@users.noreply.github.com> | 2020-05-04 12:22:04 +0530 |
commit | 95ec58135f3534640afc0a38d8c4bbbb84bc3434 (patch) | |
tree | 2b04fb11d2f821155668c4ebcec3a86229a01acb /src/new_fields/Doc.ts | |
parent | a2eb8ba283ce4a8fb7f423a9198e2a5778eba886 (diff) | |
parent | 1027f0b2e40df0ca13dfa2db97f278e804dadb68 (diff) |
finishing merge
Diffstat (limited to 'src/new_fields/Doc.ts')
-rw-r--r-- | src/new_fields/Doc.ts | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/src/new_fields/Doc.ts b/src/new_fields/Doc.ts index 337274774..9efb14d03 100644 --- a/src/new_fields/Doc.ts +++ b/src/new_fields/Doc.ts @@ -183,7 +183,7 @@ export class Doc extends RefField { let renderFieldKey: any; const layoutField = templateLayoutDoc[StrCast(templateLayoutDoc.layoutKey, "layout")]; if (typeof layoutField === "string") { - renderFieldKey = layoutField.split("'")[1]; + renderFieldKey = layoutField.split("fieldKey={'")[1].split("'")[0];//layoutField.split("'")[1]; } else { return Cast(layoutField, Doc, null); } @@ -254,6 +254,7 @@ export namespace Doc { // return Cast(field, ctor); // }); // } + export function RunCachedUpdate(doc: Doc, field: string) { const update = doc[CachedUpdates][field]; if (update) { @@ -291,6 +292,9 @@ export namespace Doc { export function IsPrototype(doc: Doc) { return GetT(doc, "isPrototype", "boolean", true); } + export function IsBaseProto(doc: Doc) { + return GetT(doc, "baseProto", "boolean", true); + } export async function SetInPlace(doc: Doc, key: string, value: Field | undefined, defaultProto: boolean) { const hasProto = doc.proto instanceof Doc; const onDeleg = Object.getOwnPropertyNames(doc).indexOf(key) !== -1; @@ -580,30 +584,44 @@ export namespace Doc { return copy; } - export function MakeClone(doc: Doc, cloneProto: boolean = true): Doc { + export function MakeClone(doc: Doc, cloneMap: Map<Doc, Doc> = new Map()): Doc { + if (Doc.IsBaseProto(doc)) return doc; + if (cloneMap.get(doc)) return cloneMap.get(doc)!; const copy = new Doc(undefined, true); + cloneMap.set(doc, copy); const exclude = Cast(doc.excludeFields, listSpec("string"), []); Object.keys(doc).forEach(key => { if (exclude.includes(key)) return; const cfield = ComputedField.WithoutComputed(() => FieldValue(doc[key])); const field = ProxyField.WithoutProxy(() => doc[key]); - if (key === "proto" && cloneProto) { + if (key === "proto") { if (doc[key] instanceof Doc) { - copy[key] = Doc.MakeClone(doc[key]!, false); + copy[key] = Doc.MakeClone(doc[key]!, cloneMap); } } else { if (field instanceof RefField) { copy[key] = field; } else if (cfield instanceof ComputedField) { copy[key] = ComputedField.MakeFunction(cfield.script.originalScript); + if (field instanceof ObjectField) { + const list = Cast(doc[key], listSpec(Doc)); + if (list !== undefined && !(list instanceof Promise)) { + copy[key] = new List<Doc>(list.filter(d => d instanceof Doc).map(d => Doc.MakeClone(d as Doc, cloneMap))); + } else { + copy[key] = doc[key] instanceof Doc ? + key.includes("layout[") ? + undefined : Doc.MakeClone(doc[key] as Doc, cloneMap) : // reference documents except copy documents that are expanded teplate fields + ObjectField.MakeCopy(field); + } + } } else if (field instanceof ObjectField) { const list = Cast(doc[key], listSpec(Doc)); if (list !== undefined && !(list instanceof Promise)) { - copy[key] = new List<Doc>(list.filter(d => d instanceof Doc).map(d => Doc.MakeCopy(d as Doc, false))); + copy[key] = new List<Doc>(list.filter(d => d instanceof Doc).map(d => Doc.MakeClone(d as Doc, cloneMap))); } else { copy[key] = doc[key] instanceof Doc ? key.includes("layout[") ? - Doc.MakeCopy(doc[key] as Doc, false) : doc[key] : // reference documents except copy documents that are expanded teplate fields + undefined : Doc.MakeClone(doc[key] as Doc, cloneMap) : // reference documents except copy documents that are expanded teplate fields ObjectField.MakeCopy(field); } } else if (field instanceof Promise) { @@ -615,6 +633,7 @@ export namespace Doc { }); Doc.SetInPlace(copy, "title", "CLONE: " + doc.title, true); copy.cloneOf = doc; + cloneMap.set(doc, copy); return copy; } @@ -771,7 +790,7 @@ export namespace Doc { export function LinkOtherAnchor(linkDoc: Doc, anchorDoc: Doc) { return Doc.AreProtosEqual(anchorDoc, Cast(linkDoc.anchor1, Doc) as Doc) ? Cast(linkDoc.anchor2, Doc) as Doc : Cast(linkDoc.anchor1, Doc) as Doc; } - export function LinkEndpoint(linkDoc: Doc, anchorDoc: Doc) { return Doc.AreProtosEqual(anchorDoc, Cast(linkDoc.anchor1, Doc) as Doc) ? "layout_key1" : "layout_key2"; } + export function LinkEndpoint(linkDoc: Doc, anchorDoc: Doc) { return Doc.AreProtosEqual(anchorDoc, Cast(linkDoc.anchor1, Doc) as Doc) ? "1" : "2"; } export function linkFollowUnhighlight() { Doc.UnhighlightAll(); @@ -996,7 +1015,7 @@ export namespace Doc { //newCollection.borderRounding = "40px"; newCollection._jitterRotation = 10; newCollection._backgroundColor = "gray"; - newCollection.overflow = "visible"; + newCollection._overflow = "visible"; return newCollection; } |