aboutsummaryrefslogtreecommitdiff
path: root/src/fields
diff options
context:
space:
mode:
Diffstat (limited to 'src/fields')
-rw-r--r--src/fields/Doc.ts56
-rw-r--r--src/fields/ScriptField.ts2
-rw-r--r--src/fields/util.ts11
3 files changed, 63 insertions, 6 deletions
diff --git a/src/fields/Doc.ts b/src/fields/Doc.ts
index 3ce22bacb..fc43325fe 100644
--- a/src/fields/Doc.ts
+++ b/src/fields/Doc.ts
@@ -33,7 +33,10 @@ export namespace Field {
return !Field.IsField(field) ? '' : (onDelegate ? '=' : '') + (field instanceof ComputedField ? `:=${field.script.originalScript}` : Field.toScriptString(field));
}
export function toScriptString(field: Field): string {
- if (typeof field === 'string') return `"${field}"`;
+ if (typeof field === 'string') {
+ if (field.startsWith('{"')) return `'${field}'`; // bcz: hack ... want to quote the string the right way. if there are nested "'s, then use ' instead of ". In this case, test for the start of a JSON string of the format {"property": ... } and use outer 's instead of "s
+ return `"${field}"`;
+ }
if (typeof field === 'number' || typeof field === 'boolean') return String(field);
if (field === undefined || field === null) return 'null';
return field[ToScriptString]();
@@ -149,6 +152,28 @@ export class Doc extends RefField {
public static set MainDocId(id: string | undefined) {
this.mainDocId = id;
}
+
+ @observable public static CurrentlyLoading: Doc[];
+ // removes from currently loading display
+ @action
+ public static removeCurrentlyLoading(doc: Doc) {
+ if (Doc.CurrentlyLoading) {
+ const index = Doc.CurrentlyLoading.indexOf(doc);
+ index !== -1 && Doc.CurrentlyLoading.splice(index, 1);
+ }
+ }
+
+ // adds doc to currently loading display
+ @action
+ public static addCurrentlyLoading(doc: Doc) {
+ if (!Doc.CurrentlyLoading) {
+ Doc.CurrentlyLoading = [];
+ }
+ if (Doc.CurrentlyLoading.indexOf(doc) === -1) {
+ Doc.CurrentlyLoading.push(doc);
+ }
+ }
+
@observable public static GuestDashboard: Doc | undefined;
@observable public static GuestTarget: Doc | undefined;
@observable public static GuestMobile: Doc | undefined;
@@ -180,7 +205,7 @@ export class Doc extends RefField {
return DocCast(Doc.UserDoc().myRecentlyClosed);
}
public static get MyTrails() {
- return DocCast(Doc.UserDoc().myTrails);
+ return DocCast(Doc.ActiveDashboard?.myTrails);
}
public static get MyOverlayDocs() {
return DocCast(Doc.UserDoc().myOverlayDocs);
@@ -213,10 +238,15 @@ 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);
}
public static set ActiveDashboard(val: Doc | undefined) {
+ const overlays = Cast(Doc.MyOverlayDocs.data, listSpec(Doc), null);
+ overlays && (overlays.length = 0);
Doc.UserDoc().activeDashboard = val;
}
public static set ActiveTool(tool: InkTool) {
@@ -225,11 +255,13 @@ export class Doc extends RefField {
public static get ActiveTool(): InkTool {
return StrCast(Doc.UserDoc().activeTool, InkTool.None) as InkTool;
}
- public static get ActivePresentation() {
- return DocCast(Doc.UserDoc().activePresentation);
+ public static get ActivePresentation(): Opt<Doc> {
+ return DocCast(Doc.ActiveDashboard?.activePresentation);
}
public static set ActivePresentation(val) {
- Doc.UserDoc().activePresentation = new PrefetchProxy(val);
+ if (Doc.ActiveDashboard) {
+ Doc.ActiveDashboard.activePresentation = val;
+ }
}
constructor(id?: FieldId, forceSave?: boolean) {
super(id);
@@ -462,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;
@@ -651,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])!;
@@ -1373,11 +1413,17 @@ export namespace Doc {
layoutDoc._viewScale = NumCast(layoutDoc._viewScale, 1) * contentScale;
layoutDoc._nativeWidth = undefined;
layoutDoc._nativeHeight = undefined;
+ layoutDoc._forceReflow = undefined;
+ layoutDoc._nativeHeightUnfrozen = undefined;
+ layoutDoc._nativeDimModifiable = undefined;
} else {
layoutDoc._autoHeight = false;
if (!Doc.NativeWidth(layoutDoc)) {
layoutDoc._nativeWidth = NumCast(layoutDoc._width, panelWidth);
layoutDoc._nativeHeight = NumCast(layoutDoc._height, panelHeight);
+ layoutDoc._forceReflow = true;
+ layoutDoc._nativeHeightUnfrozen = true;
+ layoutDoc._nativeDimModifiable = true;
}
}
});
diff --git a/src/fields/ScriptField.ts b/src/fields/ScriptField.ts
index 3cb50a4c0..4896c027d 100644
--- a/src/fields/ScriptField.ts
+++ b/src/fields/ScriptField.ts
@@ -104,7 +104,7 @@ export class ScriptField extends ObjectField {
}
this.rawscript = rawscript;
this.setterscript = setterscript;
- this.script = script ?? (CompileScript('false') as CompiledScript);
+ this.script = script ?? (CompileScript('false', { addReturn: true }) as CompiledScript);
}
// init(callback: (res: Field) => any) {
diff --git a/src/fields/util.ts b/src/fields/util.ts
index b3cbbe241..4a62a6a1f 100644
--- a/src/fields/util.ts
+++ b/src/fields/util.ts
@@ -1,8 +1,10 @@
import { action, observable, runInAction, trace } from 'mobx';
import { computedFn } from 'mobx-utils';
import { DocServer } from '../client/DocServer';
+import { CollectionViewType } from '../client/documents/DocumentTypes';
import { SerializationHelper } from '../client/util/SerializationHelper';
import { UndoManager } from '../client/util/UndoManager';
+import { CollectionDockingView } from '../client/views/collections/CollectionDockingView';
import { returnZero } from '../Utils';
import CursorField from './CursorField';
import {
@@ -278,6 +280,15 @@ function getEffectiveAcl(target: any, user?: string): symbol {
export function distributeAcls(key: string, acl: SharingPermissions, target: Doc, inheritingFromCollection?: boolean, visited?: Doc[], isDashboard?: boolean) {
if (!visited) visited = [] as Doc[];
if (visited.includes(target)) return;
+
+ if ((target._viewType === CollectionViewType.Docking && visited.length > 1) || Doc.GetProto(visited[0]) !== Doc.GetProto(target)) {
+ target[key] = acl;
+ if (target !== Doc.GetProto(target)) {
+ //apparently we can't call updateCachedAcls twice (once for the main dashboard, and again for the nested dashboard...???)
+ updateCachedAcls(target);
+ }
+ return;
+ }
visited.push(target);
const HierarchyMapping = new Map<string, number>([