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.tsx94
1 files changed, 73 insertions, 21 deletions
diff --git a/src/client/views/DocComponent.tsx b/src/client/views/DocComponent.tsx
index e351e2dec..1ecd82dbc 100644
--- a/src/client/views/DocComponent.tsx
+++ b/src/client/views/DocComponent.tsx
@@ -3,9 +3,9 @@ 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 { toList } from '../../fields/Types';
+import { DocCast, toList } from '../../fields/Types';
import { GetEffectiveAcl, inheritParentAcls } from '../../fields/util';
import { DocumentType } from '../documents/DocumentTypes';
import { ObservableReactComponent } from './ObservableReactComponent';
@@ -19,6 +19,7 @@ import { FieldViewProps } from './nodes/FieldView';
* */
export interface DocComponentProps {
Document: Doc;
+ TemplateDataDocument?: Doc;
LayoutTemplate?: () => Opt<Doc>;
LayoutTemplateString?: string;
}
@@ -30,23 +31,44 @@ export function DocComponent<P extends DocComponentProps>() {
}
/**
- * This is the document being rendered. In the case of a compound template, it
- * may not be the actual document rendered and it also may not be the 'real' root document.
- * Rather, it specifies the shared properties of all layouts of the document (eg, x,y,)
+ * 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 Document() {
return this._props.Document;
}
/**
- * This is the document being rendered. It may be a template so it may or may no inherit from the data doc.
+ * This is the "root" Doc being rendered. In the case of a compound template Doc,
+ * 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.
+ */
+ 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
+ * case of a compound template, this will be the expanded template Doc
+ * that represents the component of the compound Doc being rendered.
+ * This may or may not inherit from the data doc.
*/
@computed get layoutDoc() {
- return this._props.LayoutTemplateString ? this.Document : Doc.Layout(this.Document, this._props.LayoutTemplate?.());
+ return this._props.LayoutTemplateString ? this.Document : Doc.LayoutDoc(this.Document, this._props.LayoutTemplate?.());
}
/**
- * This is the unique data repository for a dcoument that stores the intrinsic document data
+ * This is the unique data repository for a document that stores the intrinsic document data.
*/
@computed get dataDoc() {
return this.Document[DocData];
@@ -75,18 +97,34 @@ export function ViewBoxBaseComponent<P extends FieldViewProps>() {
}
/**
- * This is the document being rendered. In the case of a compound template, it
- * may not be the actual document rendered and it also may not be the 'real' root document.
- * Rather, it specifies the shared properties of all layouts of the document (eg, x,y,)
+ * 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.
*/
get Document() {
return this._props.Document;
}
+
+ /**
+ * This is the "root" Doc being rendered. In the case of a compound template Doc,
+ * 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 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.
+ * This is the document being rendered by the React component. In the
+ * case of a compound template, this will be the expanded template Doc
+ * that represents the component of the compound Doc being rendered.
+ * This may or may not inherit from the data doc.
*/
@computed get layoutDoc() {
- return Doc.Layout(this.Document);
+ return this.Document[DocLayout];
}
/**
@@ -133,25 +171,40 @@ export function ViewBoxAnnotatableComponent<P extends FieldViewProps>() {
}
/**
- * This is the document being rendered. In the case of a compound template, it
- * may not be the actual document rendered and it also may not be the 'real' root document.
- * Rather, it specifies the shared properties of all layouts of the document (eg, x,y,)
+ * 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.
*/
- @computed get Document() {
+ get Document() {
return this._props.Document;
}
+
+ /**
+ * This is the "root" Doc being rendered. In the case of a compound template Doc,
+ * 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 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.Document);
+ return this.Document[DocLayout];
}
/**
* This is the unique data repository for a dcoument that stores the intrinsic document data
*/
@computed get dataDoc() {
- return this.Document.isTemplateForField || this.Document.isTemplateDoc ? (this._props.TemplateDataDocument ?? this.Document[DocData]) : this.Document[DocData];
+ return this.Document.isTemplateForField || this.Document.isTemplateDoc ?
+ (this._props.TemplateDataDocument ?? this.Document[DocData]) :
+ this.Document[DocData]; // prettier-ignore
}
/**
@@ -225,8 +278,7 @@ export function ViewBoxAnnotatableComponent<P extends FieldViewProps>() {
if ([AclAugment, AclEdit, AclAdmin].includes(effectiveAcl)) {
added.forEach(adoc => {
adoc._dragOnlyWithinContainer = undefined;
- if (annotationKey ?? this._annotationKeySuffix()) adoc[DocData].annotationOn = this.Document;
- else adoc[DocData].annotationOn = undefined;
+ adoc.$annotationOn = (annotationKey ?? this._annotationKeySuffix()) ? this.Document : undefined;
Doc.SetContainer(adoc, this.Document);
inheritParentAcls(targetDataDoc, adoc, true);
});