diff --git a/src/lib/components/publications/Publication.svelte b/src/lib/components/publications/Publication.svelte index 5f1a9de..ec4ec10 100644 --- a/src/lib/components/publications/Publication.svelte +++ b/src/lib/components/publications/Publication.svelte @@ -7,6 +7,7 @@ SidebarGroup, SidebarWrapper, Heading, + CloseButton, } from "flowbite-svelte"; import { getContext, onDestroy, onMount } from "svelte"; import { @@ -90,6 +91,10 @@ return currentBlog !== null && $publicationColumnVisibility.inner; } + function closeToc() { + publicationColumnVisibility.update((v) => ({ ...v, toc: false })); + } + function closeDiscussion() { publicationColumnVisibility.update((v) => ({ ...v, discussion: false })); } @@ -155,13 +160,20 @@ -{#if publicationType !== "blog" || !isLeaf} - { - publicationTree.setBookmark(address); - }} - /> +{#if publicationType !== 'blog' || !isLeaf} + {#if $publicationColumnVisibility.toc} + + + { + publicationTree.setBookmark(address); + }} + /> + + {/if} {/if} @@ -205,9 +217,7 @@ {#if $publicationColumnVisibility.blog}
- import type { TableOfContents, TocEntry } from '$lib/components/publications/table_of_contents.svelte'; + import { TableOfContents, type TocEntry } from '$lib/components/publications/table_of_contents.svelte'; import { getContext } from 'svelte'; - import { Accordion, AccordionItem, Card } from 'flowbite-svelte'; + import { Accordion, AccordionItem, Card, SidebarDropdownWrapper, SidebarGroup, SidebarItem } from 'flowbite-svelte'; import Self from './TableOfContents.svelte'; + import type { SveltePublicationTree } from './svelte_publication_tree.svelte'; + import { page } from '$app/state'; - let { + export type TocDisplayMode = 'accordion' | 'sidebar'; + + let { + displayMode = 'accordion', + rootAddress, depth, onSectionFocused, } = $props<{ + displayMode?: TocDisplayMode; + rootAddress: string; depth: number; onSectionFocused?: (address: string) => void; }>(); - let toc = getContext('toc') as TableOfContents; + let publicationTree = getContext('publicationTree') as SveltePublicationTree; + let toc = new TableOfContents(rootAddress, publicationTree, page.url.pathname ?? ""); - let entries = $derived( - Array + let entries = $derived.by(() => { + console.debug("[ToC] Filtering entries for depth", depth); + const entries = Array .from(toc.addressMap.values()) - .filter((entry) => entry.depth === depth) - ); + .filter((entry) => entry.depth === depth); + console.debug("[ToC] Filtered entries", entries.map((e) => e.title)); + return entries; + }); // Track the currently visible section for highlighting let currentSection = $state(null); @@ -51,13 +63,34 @@ } - - {#each entries as entry} - -

{entry.title}

+{#if displayMode === 'accordion'} + + {#each entries as entry} + + {#snippet header()} + {entry.title} + {/snippet} + {#if entry.children.length > 0} + + {/if} + + {/each} + +{:else} + + {#each entries as entry} {#if entry.children.length > 0} - + + + + {:else} + {/if} -
- {/each} -
+ {/each} + +{/if} \ No newline at end of file