diff options
| author | Sam Wilkins <samwilkins333@gmail.com> | 2020-05-03 15:05:07 -0700 |
|---|---|---|
| committer | Sam Wilkins <samwilkins333@gmail.com> | 2020-05-03 15:05:07 -0700 |
| commit | dd5641a55cbfe4f3acc5ae652948be28a08469d7 (patch) | |
| tree | 06b4f45115b87e2c8eb4900b816c9197494b58d0 /src/new_fields | |
| parent | b8a62e6404a695e57ab1305fd13be23e8d935360 (diff) | |
| parent | a087ea8dc3de156e23cb99f91bc1ea79365c7001 (diff) | |
Merge branch 'master' of https://github.com/browngraphicslab/Dash-Web
Diffstat (limited to 'src/new_fields')
| -rw-r--r-- | src/new_fields/Doc.ts | 28 | ||||
| -rw-r--r-- | src/new_fields/documentSchemas.ts | 2 |
2 files changed, 24 insertions, 6 deletions
diff --git a/src/new_fields/Doc.ts b/src/new_fields/Doc.ts index 9256f82c2..9efb14d03 100644 --- a/src/new_fields/Doc.ts +++ b/src/new_fields/Doc.ts @@ -292,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; @@ -581,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) { @@ -616,6 +633,7 @@ export namespace Doc { }); Doc.SetInPlace(copy, "title", "CLONE: " + doc.title, true); copy.cloneOf = doc; + cloneMap.set(doc, copy); return copy; } diff --git a/src/new_fields/documentSchemas.ts b/src/new_fields/documentSchemas.ts index e71fc27f3..e7d27d81e 100644 --- a/src/new_fields/documentSchemas.ts +++ b/src/new_fields/documentSchemas.ts @@ -78,7 +78,7 @@ export const documentSchema = createSchema({ // drag drop properties dragFactory: Doc, // the document that serves as the "template" for the onDragStart script. ie, to drag out copies of the dragFactory document. dropAction: "string", // override specifying what should happen when this document is dropped (can be "alias", "copy", "move") - targetDropAction: "string", // allows the target of a drop event to specify the dropAction ("alias", "copy", "move") + targetDropAction: "string", // allows the target of a drop event to specify the dropAction ("alias", "copy", "move") NOTE: if the document is dropped within the same collection, the dropAction is coerced to 'move' childDropAction: "string", // specify the override for what should happen when the child of a collection is dragged from it and dropped (can be "alias" or "copy") removeDropProperties: listSpec("string"), // properties that should be removed from the alias/copy/etc of this document when it is dropped }); |
