aboutsummaryrefslogtreecommitdiff
path: root/src/fields/Doc.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/fields/Doc.ts')
-rw-r--r--src/fields/Doc.ts15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/fields/Doc.ts b/src/fields/Doc.ts
index 0ceaff968..70cb10970 100644
--- a/src/fields/Doc.ts
+++ b/src/fields/Doc.ts
@@ -238,6 +238,9 @@ export class Doc extends RefField {
Doc.UserDoc().activePage = val;
DocServer.UPDATE_SERVER_CACHE();
}
+ public static IsComicStyle(doc?: Doc) {
+ return doc && Doc.ActiveDashboard && !Doc.IsSystem(doc) && Doc.UserDoc().renderStyle === 'comic';
+ }
public static get ActiveDashboard() {
return DocCast(Doc.UserDoc().activeDashboard);
}
@@ -491,6 +494,9 @@ export namespace Doc {
export function IsSystem(doc: Doc) {
return GetT(doc, 'system', 'boolean', true);
}
+ export function IsDelegateField(doc: Doc, fieldKey: string) {
+ return doc && Get(doc, fieldKey, true) !== undefined;
+ }
export async function SetInPlace(doc: Doc, key: string, value: Field | undefined, defaultProto: boolean) {
if (key.startsWith('_')) key = key.substring(1);
const hasProto = doc.proto instanceof Doc;
@@ -680,6 +686,11 @@ export namespace Doc {
return alias;
}
+ export function BestAlias(doc: Doc) {
+ const bestAlias = Doc.GetProto(doc) ? DocListCast(doc.aliases).find(doc => !doc.context && doc.author === Doc.CurrentUserEmail) : doc;
+ return bestAlias ?? Doc.MakeAlias(doc);
+ }
+
export async function makeClone(doc: Doc, cloneMap: Map<string, Doc>, linkMap: Map<Doc, Doc>, rtfs: { copy: Doc; key: string; field: RichTextField }[], exclusions: string[], dontCreate: boolean, asBranch: boolean): Promise<Doc> {
if (Doc.IsBaseProto(doc)) return doc;
if (cloneMap.get(doc[Id])) return cloneMap.get(doc[Id])!;
@@ -745,12 +756,13 @@ export namespace Doc {
}
cloneMap.set(doc[Id], copy);
}
+ Doc.IsPrototype(copy) && Doc.AddDocToList(Doc.MyFileOrphans, undefined, copy);
return copy;
}
export async function MakeClone(doc: Doc, dontCreate: boolean = false, asBranch = false, cloneMap: Map<string, Doc> = new Map()) {
const linkMap = new Map<Doc, Doc>();
const rtfMap: { copy: Doc; key: string; field: RichTextField }[] = [];
- const copy = await Doc.makeClone(doc, cloneMap, linkMap, rtfMap, ['cloneOf', 'branches', 'branchOf'], dontCreate, asBranch);
+ const copy = await Doc.makeClone(doc, cloneMap, linkMap, rtfMap, ['cloneOf', 'branches', 'branchOf', 'context'], dontCreate, asBranch);
Array.from(linkMap.entries()).map((links: Doc[]) => LinkManager.Instance.addLink(links[1], true));
rtfMap.map(({ copy, key, field }) => {
const replacer = (match: any, attr: string, id: string, offset: any, string: any) => {
@@ -963,6 +975,7 @@ export namespace Doc {
if (retitle) {
copy.title = incrementTitleCopy(StrCast(copy.title));
}
+ Doc.IsPrototype(copy) && Doc.AddDocToList(Doc.MyFileOrphans, undefined, copy);
return copy;
}