diff options
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/util/DropConverter.ts | 12 | ||||
-rw-r--r-- | src/client/views/TemplateMenu.tsx | 3 | ||||
-rw-r--r-- | src/client/views/collections/CollectionView.tsx | 4 | ||||
-rw-r--r-- | src/client/views/nodes/DocumentContentsView.tsx | 2 |
4 files changed, 15 insertions, 6 deletions
diff --git a/src/client/util/DropConverter.ts b/src/client/util/DropConverter.ts index d201934ea..28d88d867 100644 --- a/src/client/util/DropConverter.ts +++ b/src/client/util/DropConverter.ts @@ -15,14 +15,22 @@ import { ImageField } from "../../new_fields/URLField"; // after it has been converted to export function makeTemplate(doc: Doc, first: boolean = true, rename: Opt<string> = undefined): boolean { const layoutDoc = doc.layout instanceof Doc && doc.layout.isTemplateForField ? doc.layout : doc; - if (layoutDoc.layout instanceof Doc) return true; + if (layoutDoc.layout instanceof Doc) { // its already a template + return true; + } const layout = StrCast(layoutDoc.layout).match(/fieldKey={'[^']*'}/)![0]; const fieldKey = layout.replace("fieldKey={'", "").replace(/'}$/, ""); const docs = DocListCast(layoutDoc[fieldKey]); let any = false; docs.forEach(d => { if (!StrCast(d.title).startsWith("-")) { - any = Doc.MakeMetadataFieldTemplate(d, Doc.GetProto(layoutDoc)) || any; + const params = StrCast(d.title).match(/\(([a-zA-Z0-9_-]*)\)/)?.[1].replace("()", ""); + if (params) { + any = makeTemplate(d, false) || any; + d.PARAMS = params; + } else { + any = Doc.MakeMetadataFieldTemplate(d, Doc.GetProto(layoutDoc)) || any; + } } else if (d.type === DocumentType.COL || d.data instanceof RichTextField) { any = makeTemplate(d, false) || any; } diff --git a/src/client/views/TemplateMenu.tsx b/src/client/views/TemplateMenu.tsx index cf6ce2c6f..83dbd3db3 100644 --- a/src/client/views/TemplateMenu.tsx +++ b/src/client/views/TemplateMenu.tsx @@ -175,7 +175,8 @@ Scripting.addGlobal(function switchView(doc: Doc, template: Doc) { }); Scripting.addGlobal(function templateIsUsed(templateDoc: Doc, firstDocTitlte: string) { - const firstDoc = SelectionManager.SelectedDocuments()[0].props.Document; + const firstDoc = SelectionManager.SelectedDocuments().length ? SelectionManager.SelectedDocuments()[0].props.Document : undefined; + if (!firstDoc) return false; const template = StrCast(templateDoc.dragFactory ? Cast(templateDoc.dragFactory, Doc, null)?.title : templateDoc.title); return StrCast(firstDoc.layoutKey) === "layout_" + template ? 'check' : 'unchecked'; // return SelectionManager.SelectedDocuments().some(view => StrCast(view.props.Document.layoutKey) === "layout_" + template) ? 'check' : 'unchecked' diff --git a/src/client/views/collections/CollectionView.tsx b/src/client/views/collections/CollectionView.tsx index b01d76567..324417cf8 100644 --- a/src/client/views/collections/CollectionView.tsx +++ b/src/client/views/collections/CollectionView.tsx @@ -313,8 +313,8 @@ export class CollectionView extends Touchable<FieldViewProps> { } @computed get _allFacets() { const facets = new Set<string>(); - this.childDocs.forEach(child => Object.keys(Doc.GetProto(child)).forEach(key => facets.add(key))); - Doc.AreProtosEqual(this.dataDoc, this.props.Document) && this.childDocs.forEach(child => Object.keys(child).forEach(key => facets.add(key))); + this.childDocs.filter(child => child).forEach(child => Object.keys(Doc.GetProto(child)).forEach(key => facets.add(key))); + Doc.AreProtosEqual(this.dataDoc, this.props.Document) && this.childDocs.filter(child => child).forEach(child => Object.keys(child).forEach(key => facets.add(key))); return Array.from(facets); } diff --git a/src/client/views/nodes/DocumentContentsView.tsx b/src/client/views/nodes/DocumentContentsView.tsx index bf335937f..5ef330c5a 100644 --- a/src/client/views/nodes/DocumentContentsView.tsx +++ b/src/client/views/nodes/DocumentContentsView.tsx @@ -78,7 +78,7 @@ export class DocumentContentsView extends React.Component<DocumentViewProps & { return proto instanceof Promise ? undefined : proto; } get layoutDoc() { - return Doc.expandTemplateLayout(this.props.LayoutDoc?.() || Doc.Layout(this.props.Document), this.props.Document, StrCast(this.props.Document.layoutKey)); + return Doc.expandTemplateLayout(this.props.LayoutDoc?.() || Doc.Layout(this.props.Document), this.props.Document, "(" + StrCast(this.props.Document.PARAMS) + ")"); } CreateBindings(): JsxBindings { |