aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBob Zeleznik <zzzman@gmail.com>2020-05-02 19:55:00 -0400
committerBob Zeleznik <zzzman@gmail.com>2020-05-02 19:55:00 -0400
commit585e304c1dc0359184aff2fb4758357143bf1d4a (patch)
tree1d0bf843c492e71e5e9f1e29221bd139f7a0b146 /src
parent18dc6b3c66c28d0e78a579479b80786aa6589970 (diff)
final pres box tweaks so that presentations don't require aliases
Diffstat (limited to 'src')
-rw-r--r--src/client/views/nodes/PresBox.tsx16
-rw-r--r--src/client/views/presentationview/PresElementBox.tsx4
2 files changed, 11 insertions, 9 deletions
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<FieldViewProps, PresBoxSchema>
@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<FieldViewProps, PresBoxSchema>
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<FieldViewProps, PresDoc
_heightDisposer: IReactionDisposer | undefined;
// 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 collapsedHeight() { return Number(this.lookupField("presCollapsedHeight")); } // the collapsed height changes depending on the state of the presBox. We could store this on the presentation elemnt template if it's used by only one presentation - but if it's shared by multiple, 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; }
+ @computed get targetDoc() { return Cast(this.rootDoc.presentationTargetDoc, Doc, null) || this.rootDoc; }
componentDidMount() {
this._heightDisposer = reaction(() => [this.rootDoc.presExpandInlineButton, this.collapsedHeight],