Fix command links in widgets and multi widget suport

This commit is contained in:
Zef Hemel
2024-01-09 09:37:06 +01:00
parent 59a9e161de
commit e07001dae9
2 changed files with 26 additions and 3 deletions
+16
View File
@@ -136,6 +136,7 @@ export class MarkdownWidget extends WidgetType {
}
private attachListeners(div: HTMLElement, buttons?: CodeWidgetButton[]) {
// Override wiki links with local navigate (faster)
div.querySelectorAll("a[data-ref]").forEach((el_) => {
const el = el_ as HTMLElement;
// 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
div.querySelectorAll("span[data-external-task-ref]").forEach((el: any) => {
const taskRef = el.dataset.externalTaskRef;