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.tsx83
1 files changed, 61 insertions, 22 deletions
diff --git a/src/client/views/DocComponent.tsx b/src/client/views/DocComponent.tsx
index 3d5a5b945..de4df1830 100644
--- a/src/client/views/DocComponent.tsx
+++ b/src/client/views/DocComponent.tsx
@@ -5,17 +5,17 @@ import { DateField } from '../../fields/DateField';
import { Doc, DocListCast, Field, Opt } from '../../fields/Doc';
import { AclAdmin, AclAugment, AclEdit, AclPrivate, AclReadonly, DocData } from '../../fields/DocSymbols';
import { List } from '../../fields/List';
+import { RefField } from '../../fields/RefField';
import { GetEffectiveAcl, inheritParentAcls } from '../../fields/util';
import { DocumentType } from '../documents/DocumentTypes';
import { DocUtils } from '../documents/Documents';
import { DocumentManager } from '../util/DocumentManager';
+import { DragManager } from '../util/DragManager';
import { ObservableReactComponent } from './ObservableReactComponent';
import { CollectionFreeFormView } from './collections/collectionFreeForm';
-import { FieldViewProps, FocusViewOptions } from './nodes/FieldView';
import { DocumentView, OpenWhere } from './nodes/DocumentView';
+import { FieldViewProps, FocusViewOptions } from './nodes/FieldView';
import { PinProps } from './nodes/trails';
-import { RefField } from '../../fields/RefField';
-import { DragManager } from '../util/DragManager';
/**
* Shared interface among all viewBox'es (ie, react classes that render the contents of a Doc)
@@ -75,15 +75,25 @@ export function DocComponent<P extends DocComponentProps>() {
makeObservable(this);
}
- //TODO This might be pretty inefficient if doc isn't observed, because computed doesn't cache then
+ /**
+ * 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,)
+ */
get Document() {
return this._props.Document;
}
- // This is the rendering data of a document -- it may be "The Document", or it may be some template document that holds the rendering info
+
+ /**
+ * 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 this._props.LayoutTemplateString ? this.Document : Doc.Layout(this.Document, this._props.LayoutTemplate?.());
}
- // This is the data part of a document -- ie, the data that is constant across all views of the document
+
+ /**
+ * This is the unique data repository for a dcoument that stores the intrinsic document data
+ */
@computed get dataDoc() {
return this.Document[DocData];
}
@@ -109,19 +119,32 @@ export function ViewBoxBaseComponent<P extends FieldViewProps>() {
get DocumentView() {
return this._props.DocumentView;
}
- //TODO This might be pretty inefficient if doc isn't observed, because computed doesn't cache then
+
+ /**
+ * 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,)
+ */
get Document() {
return this._props.Document;
}
- // This is the rendering data of a document -- it may be "The Document", or it may be some template document that holds the rendering info
+ /**
+ * 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);
}
- // This is the data part of a document -- ie, the data that is constant across all views of the document
+
+ /**
+ * 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];
}
- // key where data is stored
+
+ /**
+ * this is the field key where the primary rendering data is stored for the layout doc (e.g., it's often the 'data' field for a collection, or the 'text' field for rich text)
+ */
get fieldKey() {
return this._props.fieldKey;
}
@@ -154,23 +177,39 @@ export function ViewBoxAnnotatableComponent<P extends FieldViewProps>() {
get DocumentView() {
return this._props.DocumentView;
}
- //TODO This might be pretty inefficient if doc isn't observed, because computed doesn't cache then
+
+ /**
+ * 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,)
+ */
@computed get Document() {
return this._props.Document;
}
- // This is the rendering data of a document -- it may be "The Document", or it may be some template document that holds the rendering info
+ /**
+ * 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);
}
- // This is the data part of a document -- ie, the data that is constant across all views of the document
+
+ /**
+ * 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];
}
- // key where data is stored
+ /**
+ * this is the field key where the primary rendering data is stored for the layout doc (e.g., it's often the 'data' field for a collection, or the 'text' field for rich text)
+ */
@computed get fieldKey() {
return this._props.fieldKey;
}
+
+ /**
+ * this is field key where the list of annotations is stored
+ */
@computed public get annotationKey() {
return this.fieldKey + (this._annotationKeySuffix() ? '_' + this._annotationKeySuffix() : '');
}
@@ -182,19 +221,19 @@ export function ViewBoxAnnotatableComponent<P extends FieldViewProps>() {
const docs = indocs.filter(doc => [AclEdit, AclAdmin].includes(effectiveAcl) || GetEffectiveAcl(doc) === AclAdmin);
// docs.forEach(doc => doc.annotationOn === this.Document && Doc.SetInPlace(doc, 'annotationOn', undefined, true));
- const targetDataDoc = this.dataDoc;
+ const targetDataDoc = this.Document[DocData]; // this.dataDoc; // we want to write to the template, not the actual data doc
const value = DocListCast(targetDataDoc[annotationKey ?? this.annotationKey]);
const toRemove = value.filter(v => docs.includes(v));
if (toRemove.length !== 0) {
- const recent = this.Document !== Doc.MyRecentlyClosed ? Doc.MyRecentlyClosed : undefined;
+ const recentlyClosed = this.Document !== Doc.MyRecentlyClosed ? Doc.MyRecentlyClosed : undefined;
toRemove.forEach(doc => {
leavePushpin && DocUtils.LeavePushpin(doc, annotationKey ?? this.annotationKey);
Doc.RemoveDocFromList(targetDataDoc, annotationKey ?? this.annotationKey, doc, true);
- Doc.RemoveEmbedding(doc, doc);
doc.embedContainer = undefined;
- if (recent && !dontAddToRemoved) {
- doc.type !== DocumentType.LOADING && Doc.AddDocToList(recent, 'data', doc, undefined, true, true);
+ if (recentlyClosed && !dontAddToRemoved && doc.type !== DocumentType.LOADING) {
+ Doc.AddDocToList(recentlyClosed, 'data', doc, undefined, true, true);
+ Doc.RemoveEmbedding(doc, doc);
}
});
if (targetDataDoc.isGroup && DocListCast(targetDataDoc[annotationKey ?? this.annotationKey]).length < 2) {
@@ -228,7 +267,7 @@ export function ViewBoxAnnotatableComponent<P extends FieldViewProps>() {
if (this._props.filterAddDocument?.(docs) === false || docs.find(doc => Doc.AreProtosEqual(doc, this.Document) && Doc.LayoutField(doc) === Doc.LayoutField(this.Document))) {
return false;
}
- const targetDataDoc = this.dataDoc;
+ const targetDataDoc = this.Document[DocData]; // this.dataDoc; // we want to write to the template, not the actual data doc
const effectiveAcl = GetEffectiveAcl(targetDataDoc);
if (effectiveAcl === AclPrivate || effectiveAcl === AclReadonly) {
@@ -245,9 +284,9 @@ export function ViewBoxAnnotatableComponent<P extends FieldViewProps>() {
inheritParentAcls(targetDataDoc, doc, true);
});
- const annoDocs = Doc.Get(targetDataDoc, annotationKey ?? this.annotationKey, true) as List<Doc>; // get the dataDoc directly ... when using templates there may be some default items already there, but we can't change them. maybe we should copy them over, though...
+ const annoDocs = Doc.Get(targetDataDoc, annotationKey ?? this.annotationKey, true) as List<Doc>; // get the dataDoc directly ... when using templates there may be some default items already there, but we can't change them, so we copy them below (should really be some kind of inheritance since the template contents could change)
if (annoDocs instanceof List) annoDocs.push(...added.filter(add => !annoDocs.includes(add)));
- else targetDataDoc[annotationKey ?? this.annotationKey] = new List<Doc>(added);
+ else targetDataDoc[annotationKey ?? this.annotationKey] = new List<Doc>([...added, ...(annoDocs === undefined ? DocListCast(targetDataDoc[annotationKey ?? this.annotationKey]) : [])]);
targetDataDoc[(annotationKey ?? this.annotationKey) + '_modificationDate'] = new DateField();
}
}