| 1 |
<script lang="ts"> |
| 2 |
import { writable } from "svelte/store"; |
| 3 |
|
| 4 |
import type { AccountTreeNode } from "../charts/hierarchy"; |
| 5 |
import { _ } from "../i18n"; |
| 6 |
import { currency_name, operating_currency } from "../stores"; |
| 7 |
import { collapse_account, invert_account } from "../stores/accounts"; |
| 8 |
import AccountCellHeader from "./AccountCellHeader.svelte"; |
| 9 |
import { get_collapsed, get_not_shown, setTreeTableContext } from "./helpers"; |
| 10 |
import TreeTableNode from "./TreeTableNode.svelte"; |
| 11 |
|
| 12 |
interface Props { |
| 13 |
/** The account tree to show. */ |
| 14 |
tree: AccountTreeNode; |
| 15 |
/** The end date (for closed accounts). */ |
| 16 |
end: Date | null; |
| 17 |
} |
| 18 |
|
| 19 |
let { tree, end }: Props = $props(); |
| 20 |
|
| 21 |
// Initialize context. |
| 22 |
// toggled is computed once on initialisation; not_shown is kept updated. |
| 23 |
const toggled = writable(get_collapsed(tree, $collapse_account)); |
| 24 |
const not_shown = writable(new Set<string>()); |
| 25 |
setTreeTableContext({ toggled, not_shown }); |
| 26 |
|
| 27 |
$effect(() => { |
| 28 |
$not_shown = $get_not_shown(tree, end); |
| 29 |
}); |
| 30 |
</script> |
| 31 |
|
| 32 |
<ol |
| 33 |
class="flex-table tree-table-new" |
| 34 |
class:wider={$operating_currency.length > 1} |
| 35 |
> |
| 36 |
<li class="head"> |
| 37 |
<p> |
| 38 |
<AccountCellHeader /> |
| 39 |
{#each $operating_currency as currency} |
| 40 |
<span class="num" title={$currency_name(currency)}>{currency}</span> |
| 41 |
{/each} |
| 42 |
<span class="num other">{_("Other")}</span> |
| 43 |
</p> |
| 44 |
</li> |
| 45 |
{#each tree.account === "" ? tree.children : [tree] as n} |
| 46 |
<TreeTableNode node={n} invert={$invert_account(n.account) ? -1 : 1} /> |
| 47 |
{/each} |
| 48 |
</ol> |
| 49 |
|
| 50 |
<style> |
| 51 |
/* For two or more operating currencies, set a slightly smaller size. */ |
| 52 |
.wider { |
| 53 |
font-size: 0.9em; |
| 54 |
} |
| 55 |
</style> |