Fix command links in widgets and multi widget suport
parent
59a9e161de
commit
e07001dae9
|
@ -38,6 +38,14 @@ export async function renderTemplateWidgets(side: "top" | "bottom"): Promise<
|
||||||
const templateBits: string[] = [];
|
const templateBits: string[] = [];
|
||||||
// Strategy: walk through all matching templates, evaluate the 'where' expression, and pick the first one that matches
|
// Strategy: walk through all matching templates, evaluate the 'where' expression, and pick the first one that matches
|
||||||
for (const template of allFrontMatterTemplates) {
|
for (const template of allFrontMatterTemplates) {
|
||||||
|
if (!template.where) {
|
||||||
|
console.warn(
|
||||||
|
"Skipping template",
|
||||||
|
template.ref,
|
||||||
|
"because it has no 'where' expression",
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
const exprAST = parseTreeToAST(
|
const exprAST = parseTreeToAST(
|
||||||
await language.parseLanguage("expression", template.where!),
|
await language.parseLanguage("expression", template.where!),
|
||||||
);
|
);
|
||||||
|
@ -45,7 +53,6 @@ export async function renderTemplateWidgets(side: "top" | "bottom"): Promise<
|
||||||
if (evalQueryExpression(parsedExpression, pageMeta)) {
|
if (evalQueryExpression(parsedExpression, pageMeta)) {
|
||||||
// Match! We're happy
|
// Match! We're happy
|
||||||
const templateText = await space.readPage(template.ref);
|
const templateText = await space.readPage(template.ref);
|
||||||
// templateBits.push(await space.readPage(template.ref));
|
|
||||||
let renderedTemplate = (await renderTemplate(
|
let renderedTemplate = (await renderTemplate(
|
||||||
templateText,
|
templateText,
|
||||||
pageMeta,
|
pageMeta,
|
||||||
|
@ -56,10 +63,10 @@ export async function renderTemplateWidgets(side: "top" | "bottom"): Promise<
|
||||||
rewritePageRefs(parsedMarkdown, template.ref);
|
rewritePageRefs(parsedMarkdown, template.ref);
|
||||||
renderedTemplate = renderToText(parsedMarkdown);
|
renderedTemplate = renderToText(parsedMarkdown);
|
||||||
|
|
||||||
templateBits.push(renderedTemplate);
|
templateBits.push(renderedTemplate.trim());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const summaryText = templateBits.join("");
|
const summaryText = templateBits.join("\n");
|
||||||
// console.log("Rendered", summaryText);
|
// console.log("Rendered", summaryText);
|
||||||
return {
|
return {
|
||||||
markdown: summaryText,
|
markdown: summaryText,
|
||||||
|
|
|
@ -136,6 +136,7 @@ export class MarkdownWidget extends WidgetType {
|
||||||
}
|
}
|
||||||
|
|
||||||
private attachListeners(div: HTMLElement, buttons?: CodeWidgetButton[]) {
|
private attachListeners(div: HTMLElement, buttons?: CodeWidgetButton[]) {
|
||||||
|
// Override wiki links with local navigate (faster)
|
||||||
div.querySelectorAll("a[data-ref]").forEach((el_) => {
|
div.querySelectorAll("a[data-ref]").forEach((el_) => {
|
||||||
const el = el_ as HTMLElement;
|
const el = el_ as HTMLElement;
|
||||||
// Override default click behavior with a local navigate (faster)
|
// Override default click behavior with a local navigate (faster)
|
||||||
|
@ -151,6 +152,21 @@ export class MarkdownWidget extends WidgetType {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
div.querySelectorAll("button[data-onclick]").forEach((el_) => {
|
||||||
|
const el = el_ as HTMLElement;
|
||||||
|
const onclick = el.dataset.onclick!;
|
||||||
|
const parsedOnclick = JSON.parse(onclick);
|
||||||
|
if (parsedOnclick[0] === "command") {
|
||||||
|
const command = parsedOnclick[1];
|
||||||
|
el.addEventListener("click", (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
console.info("Command link clicked in widget, running", command);
|
||||||
|
this.client.runCommandByName(command).catch(console.error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Implement task toggling
|
// Implement task toggling
|
||||||
div.querySelectorAll("span[data-external-task-ref]").forEach((el: any) => {
|
div.querySelectorAll("span[data-external-task-ref]").forEach((el: any) => {
|
||||||
const taskRef = el.dataset.externalTaskRef;
|
const taskRef = el.dataset.externalTaskRef;
|
||||||
|
|
Loading…
Reference in New Issue