aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/DocComponent.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views/DocComponent.tsx')
-rw-r--r--src/client/views/DocComponent.tsx52
1 files changed, 32 insertions, 20 deletions
diff --git a/src/client/views/DocComponent.tsx b/src/client/views/DocComponent.tsx
index 8f254ddcd..45c80c6f7 100644
--- a/src/client/views/DocComponent.tsx
+++ b/src/client/views/DocComponent.tsx
@@ -3,7 +3,7 @@ import * as React from 'react';
import { returnFalse } from '../../ClientUtils';
import { DateField } from '../../fields/DateField';
import { Doc, DocListCast, Opt } from '../../fields/Doc';
-import { AclAdmin, AclAugment, AclEdit, AclPrivate, AclReadonly, DocData } from '../../fields/DocSymbols';
+import { AclAdmin, AclAugment, AclEdit, AclPrivate, AclReadonly, DocData, DocLayout } from '../../fields/DocSymbols';
import { List } from '../../fields/List';
import { DocCast, toList } from '../../fields/Types';
import { GetEffectiveAcl, inheritParentAcls } from '../../fields/util';
@@ -19,6 +19,7 @@ import { FieldViewProps } from './nodes/FieldView';
* */
export interface DocComponentProps {
Document: Doc;
+ TemplateDataDocument?: Doc;
LayoutTemplate?: () => Opt<Doc>;
LayoutTemplateString?: string;
}
@@ -36,7 +37,7 @@ export function DocComponent<P extends DocComponentProps>() {
* NOTE: it is very unlikely that you really want to use this method. Instead
* consider: Document, layoutDoc, dataDoc
*/
- get _renderDoc() {
+ get Document() {
return this._props.Document;
}
@@ -46,8 +47,15 @@ export function DocComponent<P extends DocComponentProps>() {
* necessarily the Doc being rendered in the current React component.
* This Doc inherits from the dataDoc, and may or may not inherit (or be) the layoutDoc.
*/
- get Document() {
- return DocCast(this._renderDoc.rootDocument, this._renderDoc);
+ get rootDoc() {
+ return DocCast(this.Document.rootDocument, this.Document);
+ }
+
+ /**
+ * Whether the doc is a sub-componentn of a compound template doc.
+ */
+ get isTemplateForField() {
+ return this.rootDoc !== this.layoutDoc && this._props.TemplateDataDocument;
}
/**
* This is the document being rendered by the React component. In the
@@ -56,14 +64,14 @@ export function DocComponent<P extends DocComponentProps>() {
* This may or may not inherit from the data doc.
*/
@computed get layoutDoc() {
- return this._props.LayoutTemplateString ? this._renderDoc : Doc.Layout(this._renderDoc, this._props.LayoutTemplate?.());
+ return this._props.LayoutTemplateString ? this.Document : Doc.Layout(this.Document, this._props.LayoutTemplate?.());
}
/**
* This is the unique data repository for a document that stores the intrinsic document data.
*/
@computed get dataDoc() {
- return this._renderDoc[DocData];
+ return this.Document[DocData];
}
}
return Component;
@@ -92,10 +100,8 @@ export function ViewBoxBaseComponent<P extends FieldViewProps>() {
* This is the doc that is being rendered. It will be either:
* 1) the same as Document if the root of a regular or compound Doc is rendered
* 2) the same as the layoutDoc if a component of a compound Doc is rendered.
- * NOTE: it is very unlikely that you really want to use this method. Instead
- * consider: Document, layoutDoc, dataDoc
*/
- get _renderDoc() {
+ get Document() {
return this._props.Document;
}
@@ -104,9 +110,12 @@ export function ViewBoxBaseComponent<P extends FieldViewProps>() {
* this is the outermost Doc that represents the entire compound Doc. It is not
* necessarily the Doc being rendered in the current React component.
* This Doc inherits from the dataDoc, and may or may not inherit (or be) the layoutDoc.
+ *
+ * NOTE: it is very unlikely that you really want to use this method. Instead
+ * consider: Document, layoutDoc, dataDoc
*/
- get Document() {
- return DocCast(this._renderDoc.rootDocument, this._renderDoc);
+ get rootDoc() {
+ return DocCast(this.Document.rootDocument, this.Document);
}
/**
* This is the document being rendered by the React component. In the
@@ -115,14 +124,14 @@ export function ViewBoxBaseComponent<P extends FieldViewProps>() {
* This may or may not inherit from the data doc.
*/
@computed get layoutDoc() {
- return Doc.Layout(this._renderDoc);
+ return this.Document[DocLayout];
}
/**
* This is the unique data repository for a dcoument that stores the intrinsic document data
*/
@computed get dataDoc() {
- return this._renderDoc.isTemplateForField || this._renderDoc.isTemplateDoc ? (this._props.TemplateDataDocument ?? this._renderDoc[DocData]) : this._renderDoc[DocData];
+ return this.Document.isTemplateForField || this.Document.isTemplateDoc ? (this._props.TemplateDataDocument ?? this.Document[DocData]) : this.Document[DocData];
}
/**
@@ -165,10 +174,8 @@ export function ViewBoxAnnotatableComponent<P extends FieldViewProps>() {
* This is the doc that is being rendered. It will be either:
* 1) the same as Document if the root of a regular or compound Doc is rendered
* 2) the same as the layoutDoc if a component of a compound Doc is rendered.
- * NOTE: it would unlikely that you really want to use this instead of the
- * other Doc options (Document, layoutDoc, dataDoc)
*/
- get _renderDoc() {
+ get Document() {
return this._props.Document;
}
@@ -177,22 +184,27 @@ export function ViewBoxAnnotatableComponent<P extends FieldViewProps>() {
* this is the outermost Doc that represents the entire compound Doc. It is not
* necessarily the Doc being rendered in the current React component.
* This Doc inherits from the dataDoc, and may or may not inherit (or be) the layoutDoc.
+ *
+ * NOTE: it would unlikely that you really want to use this instead of the
+ * other Doc options (Document, layoutDoc, dataDoc)
*/
- @computed get Document() {
- return DocCast(this._renderDoc.rootDocument, this._renderDoc);
+ @computed get rootDoc() {
+ return DocCast(this.Document.rootDocument, this.Document);
}
/**
* This is the document being rendered. It may be a template so it may or may no inherit from the data doc.
*/
@computed get layoutDoc() {
- return Doc.Layout(this._renderDoc);
+ return this.Document[DocLayout];
}
/**
* This is the unique data repository for a dcoument that stores the intrinsic document data
*/
@computed get dataDoc() {
- return this._renderDoc.isTemplateForField || this._renderDoc.isTemplateDoc ? (this._props.TemplateDataDocument ?? this._renderDoc[DocData]) : this._props.Document[DocData];
+ return this.Document.isTemplateForField || this.Document.isTemplateDoc ?
+ (this._props.TemplateDataDocument ?? this.Document[DocData]) :
+ this.Document[DocData]; // prettier-ignore
}
/**