aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBob Zeleznik <zzzman@gmail.com>2020-03-30 12:56:21 -0400
committerBob Zeleznik <zzzman@gmail.com>2020-03-30 12:56:21 -0400
commit5667b083af700c552a86131acd00f31ab6507536 (patch)
treeeb217054bfc400b822d9045a159bde6d66ef373c /src
parent042b9c37f0fee3c85d34aa2df7dd64b4f7aadd21 (diff)
more nested template fixes
Diffstat (limited to 'src')
-rw-r--r--src/client/util/RichTextRules.ts2
-rw-r--r--src/new_fields/Doc.ts7
2 files changed, 5 insertions, 4 deletions
diff --git a/src/client/util/RichTextRules.ts b/src/client/util/RichTextRules.ts
index 51a0aeb67..76e42f169 100644
--- a/src/client/util/RichTextRules.ts
+++ b/src/client/util/RichTextRules.ts
@@ -116,7 +116,7 @@ export class RichTextRules {
}),
// create an inline view of a document {{ <layoutKey> : <Doc> }} // {{:Doc}} => show default view of document {{<layout>}} => show layout for this doc {{<layout> : Doc}} => show layout for another doc
new InputRule(
- new RegExp(/\{\{([a-zA-Z_ \-0-9]*)(\([a-zA-Z_ \-0-9]*\))?(:[a-zA-Z_ \-0-9]+)?\}\}$/),
+ new RegExp(/\{\{([a-zA-Z_ \-0-9]*)(\(([a-zA-Z0-9\._\-]*)\))?(:[a-zA-Z_ \-0-9]+)?\}\}$/),
(state, match, start, end) => {
const fieldKey = match[1];
const fieldParam = match[2];
diff --git a/src/new_fields/Doc.ts b/src/new_fields/Doc.ts
index aec085014..6748882c0 100644
--- a/src/new_fields/Doc.ts
+++ b/src/new_fields/Doc.ts
@@ -490,9 +490,10 @@ export namespace Doc {
expandedTemplateLayout = undefined;
}
else if (expandedTemplateLayout === undefined) {
- if (templateLayoutDoc.resolvedDataDoc === Doc.GetProto(targetDoc)) {
- expandedTemplateLayout = templateLayoutDoc;
+ if (templateLayoutDoc.resolvedDataDoc === Doc.GetProto(targetDoc) && templateLayoutDoc.PARAMS === StrCast(targetDoc.PARAMS)) {
+ expandedTemplateLayout = templateLayoutDoc; // reuse an existing template layout if its for the same document with the same params
} else {
+ templateLayoutDoc.resolvedDataDoc && (templateLayoutDoc = Cast(templateLayoutDoc.proto, Doc, null) || templateLayoutDoc); // if the template has already been applied (ie, a nested template), then use the template's prototype
setTimeout(action(() => {
if (!targetDoc[expandedLayoutFieldKey]) {
const newLayoutDoc = Doc.MakeDelegate(templateLayoutDoc, undefined, "[" + templateLayoutDoc.title + "]");
@@ -504,7 +505,7 @@ export namespace Doc {
const dataDoc = Doc.GetProto(targetDoc);
newLayoutDoc.resolvedDataDoc = dataDoc;
if (dataDoc[templateField] === undefined && templateLayoutDoc[templateField] instanceof List) {
- dataDoc[templateField] = ComputedField.MakeFunction(`ObjectField.MakeCopy(templateLayoutDoc["${templateField}"] as List)`, { templateLayoutDoc: Doc.name }, { templateLayoutDoc: templateLayoutDoc });
+ dataDoc[templateField] = ComputedField.MakeFunction(`ObjectField.MakeCopy(templateLayoutDoc["${templateField}"] as List)`, { templateLayoutDoc: Doc.name }, { templateLayoutDoc });
}
}
}), 0);