| 1 |
import { delegate } from "../lib/events"; |
| 2 |
|
| 3 |
/** |
| 4 |
* Account trees. |
| 5 |
* |
| 6 |
* This handles the toggling of accounts in the accounts trees. |
| 7 |
* |
| 8 |
* This is not used in Fava anymore but provided for extension compatibility. |
| 9 |
*/ |
| 10 |
export class TreeTableCustomElement extends HTMLElement { |
| 11 |
constructor() { |
| 12 |
super(); |
| 13 |
|
| 14 |
const expandAllLink = this.querySelector(".expand-all"); |
| 15 |
expandAllLink?.addEventListener("click", () => { |
| 16 |
expandAllLink.classList.add("hidden"); |
| 17 |
this.querySelectorAll(".toggled").forEach((el) => { |
| 18 |
el.classList.remove("toggled"); |
| 19 |
}); |
| 20 |
}); |
| 21 |
|
| 22 |
delegate(this, "click", "span.has-children", (event) => { |
| 23 |
if (!(event instanceof MouseEvent)) { |
| 24 |
return; |
| 25 |
} |
| 26 |
const { target } = event; |
| 27 |
if ( |
| 28 |
!(target instanceof HTMLElement) || |
| 29 |
target instanceof HTMLAnchorElement |
| 30 |
) { |
| 31 |
return; |
| 32 |
} |
| 33 |
const row = target.closest("li"); |
| 34 |
if (!row) { |
| 35 |
return; |
| 36 |
} |
| 37 |
const willShow = row.classList.contains("toggled"); |
| 38 |
if (event.shiftKey) { |
| 39 |
this.querySelectorAll("li").forEach((el) => { |
| 40 |
el.classList.toggle("toggled", !willShow); |
| 41 |
}); |
| 42 |
} |
| 43 |
if (event.ctrlKey || event.metaKey) { |
| 44 |
this.querySelectorAll("li").forEach((el) => { |
| 45 |
el.classList.toggle("toggled", willShow); |
| 46 |
}); |
| 47 |
} |
| 48 |
row.classList.toggle("toggled"); |
| 49 |
|
| 50 |
expandAllLink?.classList.toggle( |
| 51 |
"hidden", |
| 52 |
!this.querySelectorAll(".toggled").length, |
| 53 |
); |
| 54 |
}); |
| 55 |
} |
| 56 |
} |