aboutsummaryrefslogtreecommitdiff
path: root/src/fields
diff options
context:
space:
mode:
Diffstat (limited to 'src/fields')
-rw-r--r--src/fields/Doc.ts22
-rw-r--r--src/fields/ScriptField.ts2
-rw-r--r--src/fields/documentSchemas.ts3
-rw-r--r--src/fields/util.ts16
4 files changed, 28 insertions, 15 deletions
diff --git a/src/fields/Doc.ts b/src/fields/Doc.ts
index 1a062fa3b..4c3c45d92 100644
--- a/src/fields/Doc.ts
+++ b/src/fields/Doc.ts
@@ -25,6 +25,7 @@ import JSZip = require("jszip");
import { saveAs } from "file-saver";
import { CollectionDockingView } from "../client/views/collections/CollectionDockingView";
import { SelectionManager } from "../client/util/SelectionManager";
+import { DocumentView } from "../client/views/nodes/DocumentView";
export namespace Field {
export function toKeyValueString(doc: Doc, key: string): string {
@@ -91,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 ForceServerWrite = Symbol("ForceServerWrite");
export const CachedUpdates = Symbol("Cached updates");
const AclMap = new Map<string, symbol>([
@@ -184,9 +186,10 @@ export class Doc extends RefField {
@observable public [AclSym]: { [key: string]: symbol };
private [UpdatingFromServer]: boolean = false;
+ private [ForceServerWrite]: boolean = false;
private [Update] = (diff: any) => {
- !this[UpdatingFromServer] && DocServer.UpdateField(this[Id], diff);
+ (!this[UpdatingFromServer] || this[ForceServerWrite]) && DocServer.UpdateField(this[Id], diff);
}
private [Self] = this;
@@ -679,7 +682,7 @@ export namespace Doc {
templateLayoutDoc.resolvedDataDoc && (templateLayoutDoc = Cast(templateLayoutDoc.proto, Doc, null) || templateLayoutDoc); // if the template has already been applied (ie, a nested template), then use the template's prototype
if (!targetDoc[expandedLayoutFieldKey]) {
_pendingMap.set(targetDoc[Id] + expandedLayoutFieldKey + args, true);
- setTimeout(() => {
+ setTimeout(action(() => {
const newLayoutDoc = Doc.MakeDelegate(templateLayoutDoc, undefined, "[" + templateLayoutDoc.title + "]");
// the template's arguments are stored in params which is derefenced to find
// the actual field key where the parameterized template data is stored.
@@ -693,7 +696,7 @@ export namespace Doc {
targetDoc[expandedLayoutFieldKey] = newLayoutDoc;
_pendingMap.delete(targetDoc[Id] + expandedLayoutFieldKey + args);
- });
+ }));
}
}
}
@@ -882,6 +885,15 @@ export namespace Doc {
export function SetLayout(doc: Doc, layout: Doc | string) { doc[StrCast(doc.layoutKey, "layout")] = layout; }
export function LayoutField(doc: Doc) { return doc[StrCast(doc.layoutKey, "layout")]; }
export function LayoutFieldKey(doc: Doc): string { return StrCast(Doc.Layout(doc).layout).split("'")[1]; }
+ export function NativeAspect(doc: Doc, dataDoc?: Doc, useDim?: boolean) {
+ return Doc.NativeWidth(doc, dataDoc, useDim) / (Doc.NativeHeight(doc, dataDoc, useDim) || 1);
+ }
+ export function NativeWidth(doc?: Doc, dataDoc?: Doc, useWidth?: boolean) { return !doc ? 0 : NumCast(doc._nativeWidth, NumCast((dataDoc || doc)[Doc.LayoutFieldKey(doc) + "-nativeWidth"], useWidth ? doc[WidthSym]() : 0)); }
+ export function NativeHeight(doc?: Doc, dataDoc?: Doc, useHeight?: boolean) { return !doc ? 0 : NumCast(doc._nativeHeight, NumCast((dataDoc || doc)[Doc.LayoutFieldKey(doc) + "-nativeHeight"], useHeight ? doc[HeightSym]() : 0)); }
+ export function SetNativeWidth(doc: Doc, width: number | undefined) { doc[Doc.LayoutFieldKey(doc) + "-nativeWidth"] = width; }
+ export function SetNativeHeight(doc: Doc, height: number | undefined) { doc[Doc.LayoutFieldKey(doc) + "-nativeHeight"] = height; }
+
+
const manager = new DocData();
export function SearchQuery(): string { return manager._searchQuery; }
export function SetSearchQuery(query: string) { runInAction(() => manager._searchQuery = query); }
@@ -1086,14 +1098,14 @@ export namespace Doc {
export function toggleNativeDimensions(layoutDoc: Doc, contentScale: number, panelWidth: number, panelHeight: number) {
runInAction(() => {
- if (layoutDoc._nativeWidth || layoutDoc._nativeHeight) {
+ if (Doc.NativeWidth(layoutDoc) || Doc.NativeHeight(layoutDoc)) {
layoutDoc._viewScale = NumCast(layoutDoc._viewScale, 1) * contentScale;
layoutDoc._nativeWidth = undefined;
layoutDoc._nativeHeight = undefined;
}
else {
layoutDoc._autoHeight = false;
- if (!layoutDoc._nativeWidth) {
+ if (!Doc.NativeWidth(layoutDoc)) {
layoutDoc._nativeWidth = NumCast(layoutDoc._width, panelWidth);
layoutDoc._nativeHeight = NumCast(layoutDoc._height, panelHeight);
}
diff --git a/src/fields/ScriptField.ts b/src/fields/ScriptField.ts
index 47efccc99..024017302 100644
--- a/src/fields/ScriptField.ts
+++ b/src/fields/ScriptField.ts
@@ -196,7 +196,7 @@ export class ComputedField extends ScriptField {
}
Scripting.addGlobal(function getIndexVal(list: any[], index: number) {
- return list.reduce((p, x, i) => (i <= index && x !== undefined) || p === undefined ? x : p, undefined as any);
+ return list?.reduce((p, x, i) => (i <= index && x !== undefined) || p === undefined ? x : p, undefined as any);
}, "returns the value at a given index of a list", "(list: any[], index: number)");
Scripting.addGlobal(function makeScript(script: string) {
diff --git a/src/fields/documentSchemas.ts b/src/fields/documentSchemas.ts
index 71294c59c..e0404d9d3 100644
--- a/src/fields/documentSchemas.ts
+++ b/src/fields/documentSchemas.ts
@@ -15,11 +15,11 @@ export const documentSchema = createSchema({
// "Location" properties in a very general sense
_curPage: "number", // current page of a page based document
_currentFrame: "number", // current frame of a frame based collection (e.g., a progressive slide)
+ _fullScreenView: Doc, // alias to display when double-clicking to open document in a full-screen view
lastFrame: "number", // last frame of a frame based collection (e.g., a progressive slide)
activeFrame: "number", // the active frame of a frame based animated document
_currentTimecode: "number", // current play back time of a temporal document (video / audio)
displayTimecode: "number", // the time that a document should be displayed (e.g., time an annotation should be displayed on a video)
- inOverlay: "boolean", // whether the document is rendered in an OverlayView which handles selection/dragging differently
isLabel: "boolean", // whether the document is a label or not (video / audio)
audioStart: "number", // the time frame where the audio should begin playing
audioEnd: "number", // the time frame where the audio should stop playing
@@ -34,6 +34,7 @@ export const documentSchema = createSchema({
_scrollLeft: "number", // scroll position of a scrollable document (pdf, text, web)
// appearance properties on the layout
+ "_backgroundGrid-spacing": "number", // the size of the grid for collection views
_autoHeight: "boolean", // whether the height of the document should be computed automatically based on its contents
_nativeWidth: "number", // native width of document which determines how much document contents are scaled when the document's width is set
_nativeHeight: "number", // "
diff --git a/src/fields/util.ts b/src/fields/util.ts
index a374c7f54..ecb3fb343 100644
--- a/src/fields/util.ts
+++ b/src/fields/util.ts
@@ -379,12 +379,12 @@ export function updateFunction(target: any, prop: any, value: any, receiver: any
diff?.op === "$addToSet" ?
{
redo: () => {
- receiver[prop].push(...diff.items.map((item: any) => item.value()));
+ receiver[prop].push(...diff.items.map((item: any) => item.value ? item.value() : item));
lastValue = ObjectField.MakeCopy(receiver[prop]);
},
undo: action(() => {
- diff.items.forEach((doc: any) => {
- const ind = receiver[prop].indexOf(doc.value());
+ diff.items.forEach((item: any) => {
+ const ind = receiver[prop].indexOf(item.value ? item.value() : item);
ind !== -1 && receiver[prop].splice(ind, 1);
});
lastValue = ObjectField.MakeCopy(receiver[prop]);
@@ -393,16 +393,16 @@ export function updateFunction(target: any, prop: any, value: any, receiver: any
diff?.op === "$remFromSet" ?
{
redo: action(() => {
- diff.items.forEach((doc: any) => {
- const ind = receiver[prop].indexOf(doc.value());
+ diff.items.forEach((item: any) => {
+ const ind = receiver[prop].indexOf(item.value ? item.value() : item);
ind !== -1 && receiver[prop].splice(ind, 1);
});
lastValue = ObjectField.MakeCopy(receiver[prop]);
}),
undo: () => {
- diff.items.map((item: any) => {
- const ind = (prevValue as List<any>).indexOf(diff.items[0].value());
- ind !== -1 && receiver[prop].indexOf(diff.items[0].value()) === -1 && receiver[prop].splice(ind, 0, item);
+ 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);
});
lastValue = ObjectField.MakeCopy(receiver[prop]);
}