From 100ad0da00f2a5cea13508abc0c3a8c644095d65 Mon Sep 17 00:00:00 2001 From: Bob Zeleznik Date: Sat, 2 May 2020 14:31:16 -0400 Subject: turn off targetDropAction when dropping in same colleciton. cleaned up PresBox stuff to use single template to render all contents (which are otherwise unmodified). --- src/client/views/presentationview/PresElementBox.tsx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/client/views/presentationview') diff --git a/src/client/views/presentationview/PresElementBox.tsx b/src/client/views/presentationview/PresElementBox.tsx index 1887c8d45..fd202cdc1 100644 --- a/src/client/views/presentationview/PresElementBox.tsx +++ b/src/client/views/presentationview/PresElementBox.tsx @@ -5,7 +5,7 @@ import { Doc, DataSym, DocListCast } from "../../../new_fields/Doc"; import { documentSchema } from '../../../new_fields/documentSchemas'; import { Id } from "../../../new_fields/FieldSymbols"; import { createSchema, makeInterface } from '../../../new_fields/Schema'; -import { Cast, NumCast } from "../../../new_fields/Types"; +import { Cast, NumCast, BoolCast } from "../../../new_fields/Types"; import { emptyFunction, emptyPath, returnFalse, returnTrue, returnOne, returnZero } from "../../../Utils"; import { Transform } from "../../util/Transform"; import { CollectionViewType } from '../collections/CollectionView'; @@ -38,11 +38,11 @@ export class PresElementBox extends ViewBoxBaseComponent d === this.rootDoc); } - @computed get presBoxDoc() { return Cast(this.props.RenderData?.().presBox, Doc) as Doc; } + @computed get indexInPres() { return DocListCast(this.layoutDoc.presOrderedDocs).findIndex(d => d === this.rootDoc); } + @computed get collapsedHeight() { return NumCast(this.layoutDoc.presCollapsedHeight); } + @computed get presStatus() { return BoolCast(this.layoutDoc.presStatus); } + @computed get currentIndex() { return NumCast(this.layoutDoc.currentIndex); } @computed get targetDoc() { return this.rootDoc.presentationTargetDoc as Doc; } - @computed get currentIndex() { return NumCast(this.presBoxDoc?._itemIndex); } - @computed get collapsedHeight() { return NumCast(this.presBoxDoc?.presCollapsedHeight); } componentDidMount() { this._heightDisposer = reaction(() => [this.rootDoc.presExpandInlineButton, this.collapsedHeight], @@ -65,7 +65,7 @@ export class PresElementBox extends ViewBoxBaseComponent this.currentIndex && this.targetDoc) { + if (this.presStatus && this.indexInPres > this.currentIndex && this.targetDoc) { this.targetDoc.opacity = 0; } } @@ -86,7 +86,7 @@ export class PresElementBox extends ViewBoxBaseComponent Date: Sat, 2 May 2020 18:01:49 -0400 Subject: cleaned up presbox to not use reactions but to use a lookup script. put lookupField into DocComponent for general use --- src/client/views/DocComponent.tsx | 7 +++++- .../views/collections/CollectionDockingView.tsx | 1 + src/client/views/nodes/KeyValueBox.tsx | 2 +- src/client/views/nodes/PresBox.tsx | 27 ++++++++++++---------- .../views/presentationview/PresElementBox.tsx | 7 +++--- 5 files changed, 27 insertions(+), 17 deletions(-) (limited to 'src/client/views/presentationview') diff --git a/src/client/views/DocComponent.tsx b/src/client/views/DocComponent.tsx index fd0d2bdbb..11866aebe 100644 --- a/src/client/views/DocComponent.tsx +++ b/src/client/views/DocComponent.tsx @@ -1,7 +1,7 @@ import { Doc, Opt, DataSym } from '../../new_fields/Doc'; import { Touchable } from './Touchable'; import { computed, action, observable } from 'mobx'; -import { Cast, BoolCast } from '../../new_fields/Types'; +import { Cast, BoolCast, ScriptCast } from '../../new_fields/Types'; import { listSpec } from '../../new_fields/Schema'; import { InkingControl } from './InkingControl'; import { InkTool } from '../../new_fields/InkField'; @@ -33,6 +33,7 @@ export function DocComponent

(schemaCtor: (doc: D interface ViewBoxBaseProps { Document: Doc; DataDoc?: Doc; + ContainingCollectionDoc: Opt; fieldKey: string; isSelected: (outsideReaction?: boolean) => boolean; renderDepth: number; @@ -53,6 +54,8 @@ export function ViewBoxBaseComponent

(schemaCtor: // key where data is stored @computed get fieldKey() { return this.props.fieldKey; } + lookupField = (field: string) => ScriptCast(this.layoutDoc.lookupField)?.script.run({ self: this.layoutDoc, data: this.rootDoc, field: field, container: this.props.ContainingCollectionDoc }).result; + active = (outsideReaction?: boolean) => !this.props.Document.isBackground && (this.props.rootSelected(outsideReaction) || this.props.isSelected(outsideReaction) || this.props.renderDepth === 0 || this.layoutDoc.forceActive);// && !InkingControl.Instance.selectedTool; // bcz: inking state shouldn't affect static tools protected multiTouchDisposer?: InteractionUtils.MultiTouchEventDisposer; } @@ -87,6 +90,8 @@ export function ViewBoxAnnotatableComponent

ScriptCast((this.layoutDoc as any).lookupField)?.script.run({ self: this.layoutDoc, data: this.rootDoc, field: field }).result; + protected multiTouchDisposer?: InteractionUtils.MultiTouchEventDisposer; _annotationKey: string = "annotations"; diff --git a/src/client/views/collections/CollectionDockingView.tsx b/src/client/views/collections/CollectionDockingView.tsx index 0d859c3f1..822f44f5a 100644 --- a/src/client/views/collections/CollectionDockingView.tsx +++ b/src/client/views/collections/CollectionDockingView.tsx @@ -685,6 +685,7 @@ export class DockedFrameRenderer extends React.Component { if (curPres) { const pinDoc = Doc.MakeAlias(doc); pinDoc.presentationTargetDoc = doc; + pinDoc.presZoomButton = true; Doc.AddDocToList(curPres, "data", pinDoc); if (!DocumentManager.Instance.getDocumentView(curPres)) { CollectionDockingView.AddRightSplit(curPres); diff --git a/src/client/views/nodes/KeyValueBox.tsx b/src/client/views/nodes/KeyValueBox.tsx index 2970674a2..39d7109b1 100644 --- a/src/client/views/nodes/KeyValueBox.tsx +++ b/src/client/views/nodes/KeyValueBox.tsx @@ -238,8 +238,8 @@ export class KeyValueBox extends React.Component { const openItems: ContextMenuProps[] = open && "subitems" in open ? open.subitems : []; openItems.push({ description: "Default Perspective", event: () => { - this.props.addDocTab(this.fieldDocToLayout, "inTab"); this.props.addDocTab(this.props.Document, "close"); + this.props.addDocTab(this.fieldDocToLayout, "onRight"); }, icon: "image" }); !open && cm.addItem({ description: "Change Perspective...", subitems: openItems, icon: "external-link-alt" }); diff --git a/src/client/views/nodes/PresBox.tsx b/src/client/views/nodes/PresBox.tsx index 53b6aa408..57975c3af 100644 --- a/src/client/views/nodes/PresBox.tsx +++ b/src/client/views/nodes/PresBox.tsx @@ -19,6 +19,8 @@ import { makeInterface } from "../../../new_fields/Schema"; import { List } from "../../../new_fields/List"; import { Docs } from "../../documents/Documents"; import { PrefetchProxy } from "../../../new_fields/Proxy"; +import { ScriptField } from "../../../new_fields/ScriptField"; +import { Scripting } from "../../util/Scripting"; type PresBoxSchema = makeInterface<[typeof documentSchema]>; const PresBoxDocument = makeInterface(documentSchema); @@ -26,32 +28,30 @@ const PresBoxDocument = makeInterface(documentSchema); @observer export class PresBox extends ViewBoxBaseComponent(PresBoxDocument) { public static LayoutString(fieldKey: string) { return FieldView.LayoutString(PresBox, fieldKey); } - _docsDisposer: IReactionDisposer | undefined; - _viewDisposer: IReactionDisposer | undefined; @observable _isChildActive = false; @computed get childDocs() { return DocListCast(this.dataDoc[this.fieldKey]); } @computed get currentIndex() { return NumCast(this.presElement?.currentIndex); } - @computed get presElement() { return Cast(this.rootDoc.presElement, Doc, null); } + @computed get presElement() { return Cast(Doc.UserDoc().presElement, Doc, null); } constructor(props: any) { super(props); - if (!this.presElement) { - this.rootDoc.presElement = new PrefetchProxy(Docs.Create.PresElementBoxDocument({ + if (!this.presElement) { // create exactly one presElmentBox template to use by any and all presentations. Save it to the user doc. + Doc.UserDoc().presElement = new PrefetchProxy(Docs.Create.PresElementBoxDocument({ title: "pres element template", backgroundColor: "transparent", _xMargin: 5, _height: 46, isTemplateDoc: true, isTemplateForField: "data" })); + (this.presElement as Doc).lookupField = ScriptField.MakeScript( + "const presDoc = container.presentationDoc;" + + `if (field === 'indexInPres') return docList(presDoc[presDoc.presentationFieldKey]).indexOf(data);` + + "if (field === 'presCollapsedHeight') return presDoc._viewType === CollectionViewType.Stacking ? 50 : 46;" + + "return undefined;", { field: "string", data: Doc.name, container: Doc.name }); } - } - - componentWillUnmount() { - this._docsDisposer?.(); - this._viewDisposer?.(); + this.props.Document.presentationDoc = this.props.Document; + this.props.Document.presentationFieldKey = this.fieldKey; } componentDidMount() { this.rootDoc.presBox = this.rootDoc; this.rootDoc._forceRenderEngine = "timeline"; this.rootDoc._replacedChrome = "replaced"; - this._docsDisposer = reaction(() => this.childDocs, docs => this.presElement.presOrderedDocs = new List(docs), { fireImmediately: true }); - this._viewDisposer = reaction(() => this.rootDoc._viewType, viewType => this.presElement.presCollapsedHeight = viewType === CollectionViewType.Tree ? 50 : 46, { fireImmediately: true }); } updateCurrentPresentation = () => Doc.UserDoc().activePresentation = this.rootDoc; @@ -309,6 +309,7 @@ export class PresBox extends ViewBoxBaseComponent

{mode !== CollectionViewType.Invalid ?
; } } +Scripting.addGlobal(function lookupPresBoxField(presLayout: Doc, data: Doc, fieldKey: string) { +}); diff --git a/src/client/views/presentationview/PresElementBox.tsx b/src/client/views/presentationview/PresElementBox.tsx index fd202cdc1..999f907c9 100644 --- a/src/client/views/presentationview/PresElementBox.tsx +++ b/src/client/views/presentationview/PresElementBox.tsx @@ -5,7 +5,7 @@ import { Doc, DataSym, DocListCast } from "../../../new_fields/Doc"; import { documentSchema } from '../../../new_fields/documentSchemas'; import { Id } from "../../../new_fields/FieldSymbols"; import { createSchema, makeInterface } from '../../../new_fields/Schema'; -import { Cast, NumCast, BoolCast } from "../../../new_fields/Types"; +import { Cast, NumCast, BoolCast, ScriptCast } from "../../../new_fields/Types"; import { emptyFunction, emptyPath, returnFalse, returnTrue, returnOne, returnZero } from "../../../Utils"; import { Transform } from "../../util/Transform"; import { CollectionViewType } from '../collections/CollectionView'; @@ -38,8 +38,9 @@ export class PresElementBox extends ViewBoxBaseComponent d === this.rootDoc); } - @computed get collapsedHeight() { return NumCast(this.layoutDoc.presCollapsedHeight); } + // these fields are conditionally computed fields on the layout document that take this document as a parameter + @computed get indexInPres() { return Number(this.lookupField("indexInPres")); } // the index field is where this document is in the presBox display list (since this value is different for each presentation element, the value can't be stored on the layout template which is used by all display elements) + @computed get collapsedHeight() { return Number(this.lookupField("presCollapsedHeight")); } // the collapsed height changes depending on the state of the presBox. We could store this on the presentation elmeent template if it's guaranteed to be used only once - but if it's shared by different presentations, then this value must be looked up @computed get presStatus() { return BoolCast(this.layoutDoc.presStatus); } @computed get currentIndex() { return NumCast(this.layoutDoc.currentIndex); } @computed get targetDoc() { return this.rootDoc.presentationTargetDoc as Doc; } -- cgit v1.2.3-70-g09d2 From 585e304c1dc0359184aff2fb4758357143bf1d4a Mon Sep 17 00:00:00 2001 From: Bob Zeleznik Date: Sat, 2 May 2020 19:55:00 -0400 Subject: final pres box tweaks so that presentations don't require aliases --- src/client/views/nodes/PresBox.tsx | 16 +++++++++------- src/client/views/presentationview/PresElementBox.tsx | 4 ++-- 2 files changed, 11 insertions(+), 9 deletions(-) (limited to 'src/client/views/presentationview') diff --git a/src/client/views/nodes/PresBox.tsx b/src/client/views/nodes/PresBox.tsx index 57975c3af..343e74c87 100644 --- a/src/client/views/nodes/PresBox.tsx +++ b/src/client/views/nodes/PresBox.tsx @@ -34,18 +34,20 @@ export class PresBox extends ViewBoxBaseComponent @computed get presElement() { return Cast(Doc.UserDoc().presElement, Doc, null); } constructor(props: any) { super(props); - if (!this.presElement) { // create exactly one presElmentBox template to use by any and all presentations. Save it to the user doc. + if (!this.presElement) { // create exactly one presElmentBox template to use by any and all presentations. Doc.UserDoc().presElement = new PrefetchProxy(Docs.Create.PresElementBoxDocument({ title: "pres element template", backgroundColor: "transparent", _xMargin: 5, _height: 46, isTemplateDoc: true, isTemplateForField: "data" })); + // this script will be called by each presElement to get rendering-specific info that the PresBox knows about but which isn't written to the PresElement + // this is a design choice -- we could write this data to the presElements which would require a reaction to keep it up to date, and it would prevent + // the preselement docs from being part of multiple presentations since they would all have the same field, or we'd have to keep per-presentation data + // stored on each pres element. (this.presElement as Doc).lookupField = ScriptField.MakeScript( - "const presDoc = container.presentationDoc;" + - `if (field === 'indexInPres') return docList(presDoc[presDoc.presentationFieldKey]).indexOf(data);` + - "if (field === 'presCollapsedHeight') return presDoc._viewType === CollectionViewType.Stacking ? 50 : 46;" + + `if (field === 'indexInPres') return docList(container[container.presentationFieldKey]).indexOf(data);` + + "if (field === 'presCollapsedHeight') return container._viewType === CollectionViewType.Stacking ? 50 : 46;" + "return undefined;", { field: "string", data: Doc.name, container: Doc.name }); } - this.props.Document.presentationDoc = this.props.Document; - this.props.Document.presentationFieldKey = this.fieldKey; + this.props.Document.presentationFieldKey = this.fieldKey; // provide info to the presElement script so that it can look up rendering information about the presBox } componentDidMount() { @@ -172,7 +174,7 @@ export class PresBox extends ViewBoxBaseComponent const srcContext = aliasOf && await DocCastAsync(aliasOf.context); if (docToJump === curDoc) { //checking if curDoc has navigation open - const target = await DocCastAsync(curDoc.presentationTargetDoc); + const target = (await DocCastAsync(curDoc.presentationTargetDoc)) || curDoc; if (curDoc.presNavButton && target) { DocumentManager.Instance.jumpToDocument(target, false, undefined, srcContext); } else if (curDoc.presZoomButton && target) { diff --git a/src/client/views/presentationview/PresElementBox.tsx b/src/client/views/presentationview/PresElementBox.tsx index 999f907c9..6d7602268 100644 --- a/src/client/views/presentationview/PresElementBox.tsx +++ b/src/client/views/presentationview/PresElementBox.tsx @@ -40,10 +40,10 @@ export class PresElementBox extends ViewBoxBaseComponent [this.rootDoc.presExpandInlineButton, this.collapsedHeight], -- cgit v1.2.3-70-g09d2