From 169ae4b03e34d61f6e08b9809850f53ea762bae8 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 14 Jun 2023 19:28:27 -0400 Subject: [PATCH 01/17] WIP --- packages/site-kit/src/lib/nav/Menu.svelte | 16 +- packages/site-kit/src/lib/nav/Nav.svelte | 141 ++++++++++++------ .../src/lib/nav/NavContextMenu.svelte | 9 +- packages/site-kit/src/lib/nav/NavItem.svelte | 124 --------------- packages/site-kit/src/lib/nav/index.js | 1 - packages/site-kit/src/lib/nav/nav.context.js | 24 --- packages/site-kit/src/lib/types.d.ts | 9 +- 7 files changed, 108 insertions(+), 216 deletions(-) delete mode 100644 packages/site-kit/src/lib/nav/NavItem.svelte delete mode 100644 packages/site-kit/src/lib/nav/nav.context.js diff --git a/packages/site-kit/src/lib/nav/Menu.svelte b/packages/site-kit/src/lib/nav/Menu.svelte index 13965e69..65790abc 100644 --- a/packages/site-kit/src/lib/nav/Menu.svelte +++ b/packages/site-kit/src/lib/nav/Menu.svelte @@ -5,30 +5,20 @@ const dispatch = createEventDispatcher(); - let open = false; - - function toggle() { - open = !open; - - if (!open) dispatch('close'); - } + /** @type {boolean} */ + export let open; function close() { dispatch('close'); - open = false; } $: $overlay_open = open;
-
- -
- {#if open} {/if}
diff --git a/packages/site-kit/src/lib/nav/Nav.svelte b/packages/site-kit/src/lib/nav/Nav.svelte index 32e87b9c..ac6ddc49 100644 --- a/packages/site-kit/src/lib/nav/Nav.svelte +++ b/packages/site-kit/src/lib/nav/Nav.svelte @@ -16,32 +16,23 @@ Top navigation bar for the application. It provides a slot for the left side, th import Menu from './Menu.svelte'; import NavContextMenu from './NavContextMenu.svelte'; import Separator from './Separator.svelte'; - import { set_nav_context } from './nav.context'; export let home_title = 'Homepage'; /** @type {string | undefined} */ export let title; - /** @type {import('../types').Menu} */ - export let menu; + /** @type {import('../types').NavigationLink[]} */ + export let links; - /** @type {import('svelte/store').Writable} */ - const current_menu_view = writable(null); + /** @type {import('../types').NavigationLink | undefined} */ + let current_menu_view = undefined; + + let show_context_menu = false; /** @type {import('svelte/store').Writable} */ const page_selected = writable(null); - set_nav_context({ current_menu_view, page_selected }); - - let context_menu = 'docs'; - - $: if ($current_menu_view ?? $page_selected) { - context_menu = /** @type {string} */ ($current_menu_view ?? $page_selected); - } - - $: context_menu_content = menu[context_menu]; - /** @type {NavContextMenu} */ let nav_context_instance; @@ -79,20 +70,22 @@ Top navigation bar for the application. It provides a slot for the left side, th } $: { - if (browser && $current_menu_view !== null) { + if (browser && current_menu_view) { nav_context_instance?.scrollToActive(); } } onMount(() => { - $current_menu_view = $page_selected; + const segment = $page.url.pathname.split('/')[1]; + current_menu_view = links.find((link) => link.prefix === segment); }); afterNavigate(({ to }) => { - if (to?.url.pathname === '/') { - $current_menu_view = null; - $page_selected = null; - } + // if (to?.url.pathname === '/') { + // const segment = $page.url.pathname.split('/')[1]; + // current_menu_view = links.find((link) => link.prefix === segment); + // show_context_menu = !!current_menu_view; + // } open = false; }); @@ -103,7 +96,7 @@ Top navigation bar for the application. It provides a slot for the left side, th * @returns {import('svelte/transition').TransitionConfig} */ const slide = (node, { duration = 400, easing = expoOut } = {}) => { - const height = context_menu ? node.clientHeight : universal_menu_inner_height; + const height = current_menu_view ? node.clientHeight : universal_menu_inner_height; return { css: (t, u) => @@ -167,21 +160,20 @@ Top navigation bar for the application. It provides a slot for the left side, th
- ($current_menu_view = $page_selected)}> - - + + + (open = false)}>
(ready = mounted)} /> @@ -210,8 +202,8 @@ Top navigation bar for the application. It provides a slot for the left side, th const a = 'calc(var(--height-difference) + 10px)'; const b = '10px'; - const start = $current_menu_view ? a : b; - const end = $current_menu_view ? b : a; + const start = current_menu_view ? a : b; + const end = current_menu_view ? b : a; const container = e.currentTarget; @@ -234,6 +226,25 @@ Top navigation bar for the application. It provides a slot for the left side, th
    + {#each links as link} +
  • + + {link.title} + + + {#if link.sections} + + {/if} +
  • + {/each}
@@ -247,10 +258,15 @@ Top navigation bar for the application. It provides a slot for the left side, th
- + {#if current_menu_view} + + {/if}
- @@ -266,8 +282,13 @@ Top navigation bar for the application. It provides a slot for the left side, th