11<script setup lang="ts">
22import { LinkBase } from ' #components'
3+ import type { NavigationConfig , NavigationConfigWithGroups } from ' ~/types'
34import { isEditableElement } from ' ~/utils/input'
45
56withDefaults (
@@ -13,6 +14,106 @@ withDefaults(
1314
1415const { isConnected, npmUser } = useConnector ()
1516
17+ const desktopLinks = computed <NavigationConfig >(() => [
18+ {
19+ name: ' Compare' ,
20+ label: $t (' nav.compare' ),
21+ to: { name: ' compare' },
22+ keyshortcut: ' c' ,
23+ type: ' link' ,
24+ external: false ,
25+ iconClass: ' i-carbon:compare' ,
26+ },
27+ {
28+ name: ' Settings' ,
29+ label: $t (' nav.settings' ),
30+ to: { name: ' settings' },
31+ keyshortcut: ' ,' ,
32+ type: ' link' ,
33+ external: false ,
34+ iconClass: ' i-carbon:settings' ,
35+ },
36+ ])
37+
38+ const mobileLinks = computed <NavigationConfigWithGroups >(() => [
39+ {
40+ name: ' Desktop Links' ,
41+ type: ' group' ,
42+ items: [... desktopLinks .value ],
43+ },
44+ {
45+ type: ' separator' ,
46+ },
47+ {
48+ name: ' About & Policies' ,
49+ type: ' group' ,
50+ items: [
51+ {
52+ name: ' About' ,
53+ label: $t (' footer.about' ),
54+ to: { name: ' about' },
55+ type: ' link' ,
56+ external: false ,
57+ iconClass: ' i-carbon:information' ,
58+ },
59+ {
60+ name: ' Privacy Policy' ,
61+ label: $t (' privacy_policy.title' ),
62+ to: { name: ' privacy' },
63+ type: ' link' ,
64+ external: false ,
65+ iconClass: ' i-carbon:security' ,
66+ },
67+ ],
68+ },
69+ {
70+ type: ' separator' ,
71+ },
72+ {
73+ name: ' External Links' ,
74+ type: ' group' ,
75+ label: $t (' nav.links' ),
76+ items: [
77+ {
78+ name: ' Docs' ,
79+ label: $t (' footer.docs' ),
80+ href: ' https://docs.npmx.dev' ,
81+ target: ' _blank' ,
82+ type: ' link' ,
83+ external: true ,
84+ iconClass: ' i-carbon:document' ,
85+ },
86+ {
87+ name: ' Source' ,
88+ label: $t (' footer.source' ),
89+ href: ' https://repo.npmx.dev' ,
90+ target: ' _blank' ,
91+ type: ' link' ,
92+ external: true ,
93+ iconClass: ' i-carbon:logo-github' ,
94+ },
95+ {
96+ name: ' Social' ,
97+ label: $t (' footer.social' ),
98+ href: ' https://social.npmx.dev' ,
99+ target: ' _blank' ,
100+ type: ' link' ,
101+ external: true ,
102+ iconClass: ' i-simple-icons:bluesky' ,
103+ },
104+ {
105+ name: ' Chat' ,
106+ label: $t (' footer.chat' ),
107+ href: ' https://chat.npmx.dev' ,
108+ target: ' _blank' ,
109+ type: ' link' ,
110+ external: true ,
111+ iconClass: ' i-carbon:chat' ,
112+ },
113+ ],
114+ },
115+ ])
116+
16117const showFullSearch = shallowRef (false )
17118const showMobileMenu = shallowRef (false )
18119
@@ -63,23 +164,18 @@ function handleSearchFocus() {
63164}
64165
65166onKeyStroke (
66- e => isKeyWithoutModifiers (e , ' ,' ) && ! isEditableElement (e .target ),
67167 e => {
68- e .preventDefault ()
69- navigateTo ({ name: ' settings' })
70- },
71- { dedupe: true },
72- )
168+ if (isEditableElement (e .target )) {
169+ return
170+ }
73171
74- onKeyStroke (
75- e =>
76- isKeyWithoutModifiers (e , ' c' ) &&
77- ! isEditableElement (e .target ) &&
78- // Allow more specific handlers to take precedence
79- ! e .defaultPrevented ,
80- e => {
81- e .preventDefault ()
82- navigateTo ({ name: ' compare' })
172+ for (const link of desktopLinks .value ) {
173+ if (link .to && link .keyshortcut && isKeyWithoutModifiers (e , link .keyshortcut )) {
174+ e .preventDefault ()
175+ navigateTo (link .to .name )
176+ break
177+ }
178+ }
83179 },
84180 { dedupe: true },
85181)
@@ -156,24 +252,16 @@ onKeyStroke(
156252
157253 <!-- End: Desktop nav items + Mobile menu button -->
158254 <div class =" hidden sm:flex flex-shrink-0" >
159- <!-- Desktop: Compare link -->
160- <LinkBase
161- class =" border-none"
162- variant =" button-secondary"
163- :to =" { name: 'compare' }"
164- keyshortcut =" c"
165- >
166- {{ $t('nav.compare') }}
167- </LinkBase >
168-
169- <!-- Desktop: Settings link -->
255+ <!-- Desktop: Explore link -->
170256 <LinkBase
257+ v-for =" link in desktopLinks"
258+ :key =" link.name"
171259 class =" border-none"
172260 variant =" button-secondary"
173- :to =" { name: 'settings' } "
174- keyshortcut =" , "
261+ :to =" link.to "
262+ : keyshortcut =" link.keyshortcut "
175263 >
176- {{ $t('nav.settings') }}
264+ {{ link.label }}
177265 </LinkBase >
178266
179267 <HeaderAccountMenu />
@@ -191,6 +279,6 @@ onKeyStroke(
191279 </nav >
192280
193281 <!-- Mobile menu -->
194- <HeaderMobileMenu v-model:open =" showMobileMenu" />
282+ <HeaderMobileMenu :links = " mobileLinks " v-model:open =" showMobileMenu" />
195283 </header >
196284</template >
0 commit comments