diff --git a/src/lib/components/furniture/TopNav.svelte b/src/lib/components/furniture/TopNav.svelte index 16e409a..eb604b1 100644 --- a/src/lib/components/furniture/TopNav.svelte +++ b/src/lib/components/furniture/TopNav.svelte @@ -15,17 +15,36 @@ import { frequentlyUsedTools, toolUsage } from '$lib/stores/toolUsage'; import { onMount } from 'svelte'; - $: currentPath = $page.url?.pathname ?? '/'; + const currentPath = $derived($page.url?.pathname ?? '/'); - let activeDropdown: string | null = null; - let activeSubDropdown: string | null = null; + let activeDropdown = $state(null); + let activeSubDropdown = $state(null); let timeoutId: number | null = null; let subTimeoutId: number | null = null; + let secondaryDropdownPositions = $state>({}); function showDropdown(href: string) { if (timeoutId) clearTimeout(timeoutId); timeoutId = window.setTimeout(() => { activeDropdown = href; + + // Calculate secondary dropdown positions when primary opens + if (hasSubPages(href)) { + requestAnimationFrame(() => { + document.querySelectorAll('.nav-group.has-secondary').forEach((group) => { + const title = group.querySelector('.group-title-text')?.textContent?.trim(); + if (!title) return; + + const rect = group.getBoundingClientRect(); + const spaceOnRight = window.innerWidth - rect.right - 20; + + secondaryDropdownPositions = { + ...secondaryDropdownPositions, + [title]: spaceOnRight < 330 ? 'left' : 'right' + }; + }); + }); + } }, 800); } @@ -81,10 +100,10 @@ } // Check if current mode has dropdowns (only default mode has dropdowns) - $: hasDropdowns = $navbarDisplay === 'default'; + const hasDropdowns = $derived($navbarDisplay === 'default'); // Reactive navigation items based on current display mode and store changes - $: navigationItems = (() => { + const navigationItems = $derived.by(() => { let items: NavItem[]; switch ($navbarDisplay) { @@ -121,7 +140,7 @@ // Keep default navigation items in their original order return TOP_NAV.filter((item) => item.label); } - })(); + }); onMount(() => { navbarDisplay.init(); @@ -136,8 +155,8 @@ class="nav-item" class:has-dropdown={hasSubPages(item.href)} role="presentation" - on:mouseenter={() => showDropdown(item.href)} - on:mouseleave={hideDropdown} + onmouseenter={() => showDropdown(item.href)} + onmouseleave={hideDropdown} >
@@ -197,13 +216,24 @@ class:has-secondary={subItem.items.length > 0} role="menuitem" tabindex="0" - on:mouseenter={() => showSubDropdown(subItem.title)} - on:mouseleave={hideSubDropdown} + onmouseenter={() => showSubDropdown(subItem.title)} + onmouseleave={hideSubDropdown} >
- {subItem.title} - {#if subItem.items.length > 0} - + {#if subItem.items.length > 0 && secondaryDropdownPositions[subItem.title] === 'left'} + + + + {/if} + {subItem.title} + {#if subItem.items.length > 0 && secondaryDropdownPositions[subItem.title] !== 'left'} + 0}