aboutsummaryrefslogtreecommitdiff
path: root/src/fields
diff options
context:
space:
mode:
Diffstat (limited to 'src/fields')
-rw-r--r--src/fields/Doc.ts12
-rw-r--r--src/fields/ScriptField.ts2
-rw-r--r--src/fields/documentSchemas.ts2
-rw-r--r--src/fields/util.ts21
4 files changed, 21 insertions, 16 deletions
diff --git a/src/fields/Doc.ts b/src/fields/Doc.ts
index 1c9ab0e7e..31043f5be 100644
--- a/src/fields/Doc.ts
+++ b/src/fields/Doc.ts
@@ -12,7 +12,6 @@ import { UndoManager } from "../client/util/UndoManager";
import { intersectRect, Utils } from "../Utils";
import { DateField } from "./DateField";
import { Copy, HandleUpdate, Id, OnUpdate, Parent, Self, SelfProxy, ToScriptString, ToString, Update } from "./FieldSymbols";
-import { InkTool } from "./InkField";
import { List } from "./List";
import { ObjectField } from "./ObjectField";
import { PrefetchProxy, ProxyField } from "./Proxy";
@@ -85,6 +84,7 @@ export const DataSym = Symbol("Data");
export const LayoutSym = Symbol("Layout");
export const FieldsSym = Symbol("Fields");
export const AclSym = Symbol("Acl");
+export const DirectLinksSym = Symbol("DirectLinks");
export const AclUnset = Symbol("AclUnset");
export const AclPrivate = Symbol("AclOwnerOnly");
export const AclReadonly = Symbol("AclReadOnly");
@@ -92,6 +92,7 @@ export const AclAddonly = Symbol("AclAddonly");
export const AclEdit = Symbol("AclEdit");
export const AclAdmin = Symbol("AclAdmin");
export const UpdatingFromServer = Symbol("UpdatingFromServer");
+export const Initializing = Symbol("Initializing");
export const ForceServerWrite = Symbol("ForceServerWrite");
export const CachedUpdates = Symbol("Cached updates");
@@ -184,9 +185,11 @@ export class Doc extends RefField {
@observable private ___fields: any = {};
@observable private ___fieldKeys: any = {};
@observable public [AclSym]: { [key: string]: symbol };
+ @observable public [DirectLinksSym]: Set<Doc> = new Set();
private [UpdatingFromServer]: boolean = false;
private [ForceServerWrite]: boolean = false;
+ public [Initializing]: boolean = false;
private [Update] = (diff: any) => {
(!this[UpdatingFromServer] || this[ForceServerWrite]) && DocServer.UpdateField(this[Id], diff);
@@ -369,7 +372,8 @@ export namespace Doc {
* @param fields the fields to project onto the target. Its type signature defines a mapping from some string key
* to a potentially undefined field, where each entry in this mapping is optional.
*/
- export function assign<K extends string>(doc: Doc, fields: Partial<Record<K, Opt<Field>>>, skipUndefineds: boolean = false) {
+ export function assign<K extends string>(doc: Doc, fields: Partial<Record<K, Opt<Field>>>, skipUndefineds: boolean = false, isInitializing = false) {
+ isInitializing && (doc[Initializing] = true);
for (const key in fields) {
if (fields.hasOwnProperty(key)) {
const value = fields[key];
@@ -378,6 +382,7 @@ export namespace Doc {
}
}
}
+ isInitializing && (doc[Initializing] = false);
return doc;
}
@@ -777,10 +782,12 @@ export namespace Doc {
export function MakeDelegate(doc: Opt<Doc>, id?: string, title?: string): Opt<Doc> {
if (doc) {
const delegate = new Doc(id, true);
+ delegate[Initializing] = true;
delegate.proto = doc;
delegate.author = Doc.CurrentUserEmail;
if (!Doc.IsSystem(doc)) Doc.AddDocToList(doc[DataSym], "aliases", delegate);
title && (delegate.title = title);
+ delegate[Initializing] = false;
return delegate;
}
return undefined;
@@ -1080,6 +1087,7 @@ export namespace Doc {
if (!docFilters.length && modifiers === "match" && value === undefined) {
container[filterField] = undefined;
} else if (modifiers !== "remove") {
+ !append && (docFilters.length = 0);
docFilters.push(key + ":" + value + ":" + modifiers);
container[filterField] = new List<string>(docFilters);
}
diff --git a/src/fields/ScriptField.ts b/src/fields/ScriptField.ts
index 9345ecde5..bd93bf5fb 100644
--- a/src/fields/ScriptField.ts
+++ b/src/fields/ScriptField.ts
@@ -150,7 +150,7 @@ export class ScriptField extends ObjectField {
}
public static CompileScript(script: string, params: object = {}, addReturn = false, capturedVariables?: { [name: string]: Field }) {
const compiled = CompileScript(script, {
- params: { this: Doc.name, self: Doc.name, _last_: "any", ...params },
+ params: { this: Doc?.name || "Doc", self: Doc?.name || "Doc", _last_: "any", ...params },
typecheck: false,
editable: true,
addReturn: addReturn,
diff --git a/src/fields/documentSchemas.ts b/src/fields/documentSchemas.ts
index 0bf942474..275249840 100644
--- a/src/fields/documentSchemas.ts
+++ b/src/fields/documentSchemas.ts
@@ -45,8 +45,6 @@ export const documentSchema = createSchema({
_showAudio: "boolean", // whether to show the audio record icon on documents
_freeformLOD: "boolean", // whether to enable LOD switching for CollectionFreeFormViews
_pivotField: "string", // specifies which field key should be used as the timeline/pivot axis
- _replacedChrome: "string", // what the default chrome is replaced with. Currently only supports the value of 'replaced' for PresBox's.
- _chromeStatus: "string", // determines the state of the collection chrome. values allowed are 'replaced', 'enabled', 'disabled', 'collapsed'
_columnsFill: "boolean", // whether documents in a stacking view column should be sized to fill the column
_columnsSort: "string", // how a document should be sorted "ascending", "descending", undefined (none)
_columnsHideIfEmpty: "boolean", // whether empty stacking view column headings should be hidden
diff --git a/src/fields/util.ts b/src/fields/util.ts
index 6038a0534..ea91cc057 100644
--- a/src/fields/util.ts
+++ b/src/fields/util.ts
@@ -1,5 +1,5 @@
import { UndoManager } from "../client/util/UndoManager";
-import { Doc, FieldResult, UpdatingFromServer, LayoutSym, AclPrivate, AclEdit, AclReadonly, AclAddonly, AclSym, DataSym, DocListCast, AclAdmin, HeightSym, WidthSym, updateCachedAcls, AclUnset, DocListCastAsync, ForceServerWrite } from "./Doc";
+import { Doc, FieldResult, UpdatingFromServer, LayoutSym, AclPrivate, AclEdit, AclReadonly, AclAddonly, AclSym, DataSym, DocListCast, AclAdmin, HeightSym, WidthSym, updateCachedAcls, AclUnset, DocListCastAsync, ForceServerWrite, Initializing } from "./Doc";
import { SerializationHelper } from "../client/util/SerializationHelper";
import { ProxyField, PrefetchProxy } from "./Proxy";
import { RefField } from "./RefField";
@@ -24,7 +24,6 @@ export function TraceMobx() {
tracing && trace();
}
-
export interface GetterResult {
value: FieldResult;
shouldReturn?: boolean;
@@ -96,9 +95,12 @@ const _setterImpl = action(function (target: any, prop: string | symbol | number
} else {
DocServer.registerDocWithCachedUpdate(receiver, prop as string, curValue);
}
- (!receiver[UpdatingFromServer] || receiver[ForceServerWrite]) && UndoManager.AddEvent({
+ !receiver[Initializing] && (!receiver[UpdatingFromServer] || receiver[ForceServerWrite]) && UndoManager.AddEvent({
redo: () => receiver[prop] = value,
- undo: () => receiver[prop] = curValue
+ undo: () => {
+ // console.log("Undo: " + prop + " = " + curValue); // bcz: uncomment to log undo
+ receiver[prop] = curValue;
+ }
});
return true;
}
@@ -162,7 +164,7 @@ export function GetEffectiveAcl(target: any, user?: string): symbol {
}
function getPropAcl(target: any, prop: string | symbol | number) {
- if (prop === UpdatingFromServer || target[UpdatingFromServer] || prop === AclSym) return AclAdmin; // requesting the UpdatingFromServer prop or AclSym must always go through to keep the local DB consistent
+ if (prop === UpdatingFromServer || prop === Initializing || target[UpdatingFromServer] || prop === AclSym) return AclAdmin; // requesting the UpdatingFromServer prop or AclSym must always go through to keep the local DB consistent
if (prop && DocServer.PlaygroundFields?.includes(prop.toString())) return AclEdit; // playground props are always editable
return GetEffectiveAcl(target);
}
@@ -274,8 +276,6 @@ export function distributeAcls(key: string, acl: SharingPermissions, target: Doc
dataDocChanged && updateCachedAcls(dataDoc);
}
-const layoutProps = ["panX", "panY", "width", "height", "nativeWidth", "nativeHeight", "fitWidth", "fitToBox",
- "chromeStatus", "viewType", "gridGap", "xMargin", "yMargin", "autoHeight"];
export function setter(target: any, in_prop: string | symbol | number, value: any, receiver: any): boolean {
let prop = in_prop;
const effectiveAcl = getPropAcl(target, prop);
@@ -285,10 +285,6 @@ export function setter(target: any, in_prop: string | symbol | number, value: an
// if (typeof prop === "string" && prop.startsWith("acl") && !["Can Edit", "Can Augment", "Can View", "Not Shared", undefined].includes(value)) return true;
if (typeof prop === "string" && prop !== "__id" && prop !== "__fields" && prop.startsWith("_")) {
- // if (!prop.startsWith("_")) {
- // console.log(prop + " is deprecated - switch to _" + prop);
- // prop = "_" + prop;
- // }
if (!prop.startsWith("__")) prop = prop.substring(1);
if (target.__LAYOUT__) {
target.__LAYOUT__[prop] = value;
@@ -380,6 +376,7 @@ export function updateFunction(target: any, prop: any, value: any, receiver: any
lastValue = ObjectField.MakeCopy(receiver[prop]);
},
undo: action(() => {
+ // console.log("undo $add: " + prop, diff.items) // bcz: uncomment to log undo
diff.items.forEach((item: any) => {
const ind = receiver[prop].indexOf(item.value ? item.value() : item);
ind !== -1 && receiver[prop].splice(ind, 1);
@@ -397,6 +394,7 @@ export function updateFunction(target: any, prop: any, value: any, receiver: any
lastValue = ObjectField.MakeCopy(receiver[prop]);
}),
undo: () => {
+ // console.log("undo $rem: " + prop, diff.items) // bcz: uncomment to log undo
diff.items.forEach((item: any) => {
const ind = (prevValue as List<any>).indexOf(item.value ? item.value() : item);
ind !== -1 && receiver[prop].indexOf(item.value ? item.value() : item) === -1 && receiver[prop].splice(ind, 0, item);
@@ -410,6 +408,7 @@ export function updateFunction(target: any, prop: any, value: any, receiver: any
lastValue = ObjectField.MakeCopy(receiver[prop]);
},
undo: () => {
+ // console.log("undo list: " + prop, receiver[prop]) // bcz: uncomment to log undo
receiver[prop] = ObjectField.MakeCopy(prevValue as List<any>);
lastValue = ObjectField.MakeCopy(receiver[prop]);
}