aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/client/util/RichTextSchema.tsx9
-rw-r--r--src/client/views/nodes/ImageBox.tsx4
-rw-r--r--src/new_fields/Doc.ts6
3 files changed, 10 insertions, 9 deletions
diff --git a/src/client/util/RichTextSchema.tsx b/src/client/util/RichTextSchema.tsx
index 71d4530f2..7e4a095bc 100644
--- a/src/client/util/RichTextSchema.tsx
+++ b/src/client/util/RichTextSchema.tsx
@@ -768,7 +768,7 @@ export class DashDocView {
};
const alias = node.attrs.alias;
- const docid = node.attrs.docid || tbox.props.DataDoc?.[Id] || tbox.dataDoc?.[Id];
+ const docid = node.attrs.docid || tbox.props.Document[Id];// tbox.props.DataDoc?.[Id] || tbox.dataDoc?.[Id];
DocServer.GetRefField(docid + alias).then(async dashDoc => {
if (!(dashDoc instanceof Doc)) {
alias && DocServer.GetRefField(docid).then(async dashDocBase => {
@@ -800,10 +800,13 @@ export class DashDocView {
this._dashDoc = dashDoc;
const self = this;
const dashLayoutDoc = Doc.Layout(dashDoc);
- const finalLayout = this._textBox.props.Document instanceof Doc && (Doc.expandTemplateLayout(dashLayoutDoc,
+ const finalLayout = node.attrs.docid ? dashDoc : this._textBox.props.Document instanceof Doc && (Doc.expandTemplateLayout(dashLayoutDoc,
dashLayoutDoc !== dashDoc || !Doc.AreProtosEqual(this._textBox.dataDoc, this._textBox.props.Document) ? this._textBox.dataDoc : undefined, node.attrs.fieldKey));
if (!finalLayout) setTimeout(() => self.doRender(dashDoc, removeDoc, node, view, getPos), 0);
else {
+ if (!Doc.AreProtosEqual(finalLayout, dashDoc)) {
+ finalLayout.expandedTemplate = dashDoc.aliasOf;
+ }
const layoutKey = StrCast(finalLayout.layoutKey);
const finalKey = layoutKey && StrCast(finalLayout[layoutKey]).split("'")?.[1];
if (finalLayout !== dashDoc && finalKey) {
@@ -820,7 +823,7 @@ export class DashDocView {
}, { fireImmediately: true });
ReactDOM.render(<DocumentView
Document={finalLayout}
- DataDoc={!node.attrs.docid ? this._textBox.dataDoc : undefined}
+ DataDoc={Cast(finalLayout.resolvedDataDoc, Doc, null)}
LibraryPath={this._textBox.props.LibraryPath}
fitToBox={BoolCast(dashDoc._fitToBox)}
addDocument={returnFalse}
diff --git a/src/client/views/nodes/ImageBox.tsx b/src/client/views/nodes/ImageBox.tsx
index 04ebf477b..68eb4493a 100644
--- a/src/client/views/nodes/ImageBox.tsx
+++ b/src/client/views/nodes/ImageBox.tsx
@@ -258,10 +258,9 @@ export class ImageBox extends DocAnnotatableComponent<FieldViewProps, ImageDocum
width: NumCast(this.dataDoc[this.fieldKey + "-nativeWidth"]),
height: NumCast(this.dataDoc[this.fieldKey + "-nativeHeight"])
};
- const cachedImgPath = this.dataDoc[this.fieldKey + "-imgPath"];
const docAspect = this.Document[HeightSym]() / this.Document[WidthSym]();
const cachedAspect = cachedNativeSize.height / cachedNativeSize.width;
- if (!cachedNativeSize.width || !cachedNativeSize.height || Math.abs(NumCast(this.layoutDoc._width) / NumCast(this.layoutDoc._height) - cachedNativeSize.width / cachedNativeSize.height) > 0.05 || imgPath !== cachedImgPath) {
+ if (!cachedNativeSize.width || !cachedNativeSize.height || Math.abs(NumCast(this.layoutDoc._width) / NumCast(this.layoutDoc._height) - cachedNativeSize.width / cachedNativeSize.height) > 0.05) {
if (!this.layoutDoc.isTemplateDoc || this.dataDoc !== this.layoutDoc) {
requestImageSize(imgPath).then((inquiredSize: any) => {
const rotation = NumCast(this.dataDoc[this.fieldKey + "-rotation"]) % 180;
@@ -273,7 +272,6 @@ export class ImageBox extends DocAnnotatableComponent<FieldViewProps, ImageDocum
this.dataDoc[this.fieldKey + "-nativeWidth"] = this.Document._nativeWidth = rotatedNativeSize.width;
this.dataDoc[this.fieldKey + "-nativeHeight"] = this.Document._nativeHeight = rotatedNativeSize.height;
}
- this.dataDoc[this.fieldKey + "-imgPath"] = imgPath;
}), 0);
}).catch((err: any) => console.log(err));
} else if (Math.abs(1 - docAspect / cachedAspect) > 0.1) {
diff --git a/src/new_fields/Doc.ts b/src/new_fields/Doc.ts
index 3ac297e94..0e3bab32a 100644
--- a/src/new_fields/Doc.ts
+++ b/src/new_fields/Doc.ts
@@ -472,7 +472,7 @@ export namespace Doc {
// in the future, field references could be written as @<someparam> and then arguments would be passed in the layout key as:
// layout_mytemplate(somparam=somearg).
// then any references to @someparam would be rewritten as accesses to 'somearg' on the expandedTemplate
- export function expandTemplateLayout(templateLayoutDoc: Doc, targetDoc?: Doc, templateArgs?: string) {
+ export function expandTemplateLayout(templateLayoutDoc: Doc, targetDoc?: Doc, templateArgs?: string, templateParent?: Doc) {
if (!WillExpandTemplateLayout(templateLayoutDoc, targetDoc) || !targetDoc) return templateLayoutDoc;
const templateField = StrCast(templateLayoutDoc.isTemplateForField); // the field that the template renders
@@ -497,7 +497,7 @@ export namespace Doc {
// the template's arguments are stored in params which is derefenced to find
// the actual field key where the parameterized template data is stored.
newLayoutDoc[params] = args;
- newLayoutDoc.expandedTemplate = targetDoc;
+ newLayoutDoc.expandedTemplate = templateParent || targetDoc;
targetDoc[expandedLayoutFieldKey] = newLayoutDoc;
const dataDoc = Doc.GetProto(targetDoc);
newLayoutDoc.resolvedDataDoc = dataDoc;
@@ -519,7 +519,7 @@ export namespace Doc {
}
const existingResolvedDataDoc = childDoc[DataSym] !== Doc.GetProto(childDoc)[DataSym] && childDoc[DataSym];
const resolvedDataDoc = existingResolvedDataDoc || (Doc.AreProtosEqual(containerDataDoc, containerDoc) || !containerDataDoc || (!childDoc.isTemplateDoc && !childDoc.isTemplateForField) ? undefined : containerDataDoc);
- return { layout: Doc.expandTemplateLayout(childDoc, resolvedDataDoc, "(" + StrCast(containerDoc["PARAMS"]) + ")"), data: resolvedDataDoc };
+ return { layout: Doc.expandTemplateLayout(childDoc, resolvedDataDoc, "(" + StrCast(containerDoc["PARAMS"]) + ")", Cast(containerDoc.expandedTemplate, Doc, null)), data: resolvedDataDoc };
}
export function Overwrite(doc: Doc, overwrite: Doc, copyProto: boolean = false): Doc {