diff options
-rw-r--r-- | src/client/views/collections/CollectionTimeView.tsx | 10 | ||||
-rw-r--r-- | src/client/views/nodes/ImageBox.tsx | 2 | ||||
-rw-r--r-- | src/new_fields/Doc.ts | 38 | ||||
-rw-r--r-- | src/new_fields/util.ts | 41 |
4 files changed, 60 insertions, 31 deletions
diff --git a/src/client/views/collections/CollectionTimeView.tsx b/src/client/views/collections/CollectionTimeView.tsx index 0c1f93829..4983acbc2 100644 --- a/src/client/views/collections/CollectionTimeView.tsx +++ b/src/client/views/collections/CollectionTimeView.tsx @@ -1,6 +1,6 @@ import { faEdit } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; -import { action, computed, observable, trace } from "mobx"; +import { action, computed, observable, trace, runInAction } from "mobx"; import { observer } from "mobx-react"; import { Set } from "typescript-collections"; import { Doc, DocListCast, Field } from "../../../new_fields/Doc"; @@ -323,7 +323,9 @@ Scripting.addGlobal(function pivotColumnClick(pivotDoc: Doc, bounds: ViewDefBoun let pfilterIndex = NumCast(pivotDoc._pfilterIndex); pivotDoc["_pfilter" + pfilterIndex] = ObjectField.MakeCopy(pivotDoc._docFilter as ObjectField); pivotDoc._pfilterIndex = ++pfilterIndex; - pivotDoc._docFilter = new List(); - (bounds.payload as string[]).map(filterVal => - Doc.setDocFilter(pivotDoc, StrCast(pivotDoc._pivotField), filterVal, "check")); + runInAction(() => { + pivotDoc._docFilter = new List(); + (bounds.payload as string[]).map(filterVal => + Doc.setDocFilter(pivotDoc, StrCast(pivotDoc._pivotField), filterVal, "check")); + }); });
\ No newline at end of file diff --git a/src/client/views/nodes/ImageBox.tsx b/src/client/views/nodes/ImageBox.tsx index 1951fcc1a..896ac1685 100644 --- a/src/client/views/nodes/ImageBox.tsx +++ b/src/client/views/nodes/ImageBox.tsx @@ -257,7 +257,7 @@ export class ImageBox extends DocAnnotatableComponent<FieldViewProps, ImageDocum }), 0); }) .catch((err: any) => console.log(err)); - } else if (this.Document._nativeHeight !== cachedNativeSize.width || this.Document._nativeWidth !== cachedNativeSize.height) { + } else if (this.Document._nativeWidth !== cachedNativeSize.width || this.Document._nativeHeight !== cachedNativeSize.height) { !(this.Document[StrCast(this.props.Document.layoutKey)] instanceof Doc) && setTimeout(() => { if (!(this.Document[StrCast(this.props.Document.layoutKey)] instanceof Doc)) { this.Document._nativeWidth = cachedNativeSize.width; diff --git a/src/new_fields/Doc.ts b/src/new_fields/Doc.ts index 529634990..bc2d5c49e 100644 --- a/src/new_fields/Doc.ts +++ b/src/new_fields/Doc.ts @@ -1,4 +1,4 @@ -import { observable, ObservableMap, runInAction, action } from "mobx"; +import { observable, ObservableMap, runInAction, action, computed } from "mobx"; import { alias, map, serializable } from "serializr"; import { DocServer } from "../client/DocServer"; import { DocumentType } from "../client/documents/DocumentTypes"; @@ -90,6 +90,7 @@ export function DocListCast(field: FieldResult): Doc[] { export const WidthSym = Symbol("Width"); export const HeightSym = Symbol("Height"); export const DataSym = Symbol("Data"); +export const LayoutSym = Symbol("Layout"); export const UpdatingFromServer = Symbol("UpdatingFromServer"); const CachedUpdates = Symbol("Cached updates"); @@ -111,8 +112,11 @@ export class Doc extends RefField { get: getter, // getPrototypeOf: (target) => Cast(target[SelfProxy].proto, Doc) || null, // TODO this might be able to replace the proto logic in getter has: (target, key) => key in target.__fields, - ownKeys: target => Object.keys(target.__fields), + ownKeys: target => Object.keys(target.__allfields), getOwnPropertyDescriptor: (target, prop) => { + if (prop.toString() === "__LAYOUT__") { + return Reflect.getOwnPropertyDescriptor(target, prop); + } if (prop in target.__fields) { return { configurable: true,//TODO Should configurable be true? @@ -139,6 +143,13 @@ export class Doc extends RefField { private get __fields() { return this.___fields; } + private get __allfields() { + let obj = {} as any; + Object.assign(obj, this.___fields); + runInAction(() => obj.__LAYOUT__ = this.__LAYOUT__); + return obj; + } + private set __fields(value) { this.___fields = value; @@ -168,6 +179,15 @@ export class Doc extends RefField { public [WidthSym] = () => NumCast(this[SelfProxy]._width); public [HeightSym] = () => NumCast(this[SelfProxy]._height); public get [DataSym]() { return Cast(this[SelfProxy].resolvedDataDoc, Doc, null) || this[SelfProxy]; } + @computed public get __LAYOUT__() { + const layoutKey = StrCast(this[SelfProxy].layoutKey); + const resolvedLayout = Cast(layoutKey, Doc); + if (resolvedLayout instanceof Doc) { + let layout = (resolvedLayout.layout as string).split("'")[1]; + return this[SelfProxy][layout + "-layout[" + resolvedLayout[Id] + "]"] || resolvedLayout; + } + return undefined; + } [ToScriptString]() { return "invalid"; @@ -672,12 +692,14 @@ export namespace Doc { // the document containing the view layout information - will be the Document itself unless the Document has // a layout field. In that case, all layout information comes from there unless overriden by Document export function Layout(doc: Doc): Doc { - let templateLayoutDoc = Cast(Doc.LayoutField(doc), Doc, null); - if (templateLayoutDoc) { - const renderFieldKey = Doc.LayoutFieldKey(templateLayoutDoc); - return Cast(doc[renderFieldKey + "-layout[" + templateLayoutDoc[Id] + "]"], Doc, null) || templateLayoutDoc; - } - return doc; + return doc.__LAYOUT__ || Cast(Doc.LayoutField(doc), Doc, null) || doc; + // let templateLayoutDoc = Cast(Doc.LayoutField(doc), Doc, null); + // if (templateLayoutDoc) { + // const renderFieldKey = Doc.LayoutFieldKey(templateLayoutDoc); + // const layout = Cast(doc[renderFieldKey + "-layout[" + templateLayoutDoc[Id] + "]"], Doc, null) || templateLayoutDoc; + // return layout; + // } + // return 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")]; } diff --git a/src/new_fields/util.ts b/src/new_fields/util.ts index 45ec676b2..52bb7afcd 100644 --- a/src/new_fields/util.ts +++ b/src/new_fields/util.ts @@ -1,5 +1,5 @@ import { UndoManager } from "../client/util/UndoManager"; -import { Doc, Field, FieldResult, UpdatingFromServer } from "./Doc"; +import { Doc, Field, FieldResult, UpdatingFromServer, LayoutSym } from "./Doc"; import { SerializationHelper } from "../client/util/SerializationHelper"; import { ProxyField, PrefetchProxy } from "./Proxy"; import { RefField } from "./RefField"; @@ -104,41 +104,46 @@ let layoutProps = ["panX", "panY", "width", "height", "nativeWidth", "nativeHeig "LODdisable", "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; - if (typeof prop === "string" && prop !== "__id" && prop !== "__fields" && + if (typeof prop === "string" && prop !== "__id" && prop !== "__LAYOUT__" && prop !== "__fields" && ((prop as string).startsWith("_") || layoutProps.includes(prop))) { if (!prop.startsWith("_")) { console.log(prop + " is deprecated - switch to _" + prop); prop = "_" + prop; } - const resolvedLayout = getFieldImpl(target, getFieldImpl(target, "layoutKey", receiver), receiver); - if (resolvedLayout instanceof Doc) { - let x = resolvedLayout[Id]; - let layout = (resolvedLayout.layout as string).split("'")[1]; - let expanded = getFieldImpl(target, layout + "-layout[" + x + "]", receiver); - expanded && (expanded[prop] = value); - // resolvedLayout[prop] = value; + if (target.__LAYOUT__) { + target.__LAYOUT__[prop] = value; return true; } + // const resolvedLayout = getFieldImpl(target, getFieldImpl(target, "layoutKey", receiver), receiver); + // if (resolvedLayout instanceof Doc) { + // let x = resolvedLayout[Id]; + // let layout = (resolvedLayout.layout as string).split("'")[1]; + // let expanded = getFieldImpl(target, layout + "-layout[" + x + "]", receiver); + // //expanded && (expanded[prop] = value); + // // resolvedLayout[prop] = value; + // return true; + // } } return _setter(target, prop, value, receiver); } export function getter(target: any, in_prop: string | symbol | number, receiver: any): any { let prop = in_prop; - if (typeof prop === "string" && prop !== "__id" && prop !== "__fields" && + if (typeof prop === "string" && prop !== "__id" && prop !== "__LAYOUT__" && prop !== "__fields" && ((prop as string).startsWith("_") || layoutProps.includes(prop))) { if (!prop.startsWith("_")) { console.log(prop + " is deprecated - switch to _" + prop); prop = "_" + prop; } - const resolvedLayout = getFieldImpl(target, getFieldImpl(target, "layoutKey", receiver), receiver); - if (resolvedLayout instanceof Doc) { - let x = resolvedLayout[Id]; - let layout = (resolvedLayout.layout as string).split("'")[1]; - let expanded = getFieldImpl(target, layout + "-layout[" + x + "]", receiver); - return (expanded || resolvedLayout)?.[prop]; - //return resolvedLayout[prop]; - } + if (target.__LAYOUT__) return target.__LAYOUT__[prop]; + // const resolvedLayout = getFieldImpl(target, getFieldImpl(target, "layoutKey", receiver), receiver); + // if (resolvedLayout instanceof Doc) { + // let x = resolvedLayout[Id]; + // let layout = (resolvedLayout.layout as string).split("'")[1]; + // let expanded = getFieldImpl(target, layout + "-layout[" + x + "]", receiver); + // return (expanded)?.[prop]; + // //return resolvedLayout[prop]; + // } } if (prop === "then") {//If we're being awaited return undefined; |