|
1 | 1 | <script setup lang="ts"> |
2 | 2 | import type { RouteLocationRaw } from 'vue-router' |
3 | 3 | import { SCROLL_TO_TOP_THRESHOLD } from '~/composables/useScrollToTop' |
4 | | -import { isEditableElement } from '~/utils/input' |
5 | 4 |
|
6 | 5 | const props = defineProps<{ |
7 | 6 | pkg?: Pick<SlimPackument, 'name' | 'versions' | 'dist-tags'> | null |
@@ -72,7 +71,6 @@ function hasProvenance(version: PackumentVersion | null): boolean { |
72 | 71 | return !!(version.dist as { attestations?: unknown }).attestations |
73 | 72 | } |
74 | 73 |
|
75 | | -const router = useRouter() |
76 | 74 | // Docs URL: use our generated API docs |
77 | 75 | const docsLink = computed(() => { |
78 | 76 | if (!props.resolvedVersion) return null |
@@ -120,59 +118,13 @@ const diffLink = computed((): RouteLocationRaw | null => { |
120 | 118 | return diffRoute(props.pkg.name, props.resolvedVersion, props.latestVersion.version) |
121 | 119 | }) |
122 | 120 |
|
123 | | -const keyboardShortcuts = useKeyboardShortcuts() |
124 | | -
|
125 | | -onKeyStroke( |
126 | | - e => keyboardShortcuts.value && isKeyWithoutModifiers(e, '.') && !isEditableElement(e.target), |
127 | | - e => { |
128 | | - if (codeLink.value === null) return |
129 | | - e.preventDefault() |
130 | | -
|
131 | | - navigateTo(codeLink.value) |
132 | | - }, |
133 | | - { dedupe: true }, |
134 | | -) |
135 | | -
|
136 | | -onKeyStroke( |
137 | | - e => keyboardShortcuts.value && isKeyWithoutModifiers(e, 'm') && !isEditableElement(e.target), |
138 | | - e => { |
139 | | - if (mainLink.value === null) return |
140 | | - e.preventDefault() |
141 | | -
|
142 | | - navigateTo(mainLink.value) |
143 | | - }, |
144 | | - { dedupe: true }, |
145 | | -) |
146 | | -
|
147 | | -onKeyStroke( |
148 | | - e => keyboardShortcuts.value && isKeyWithoutModifiers(e, 'd') && !isEditableElement(e.target), |
149 | | - e => { |
150 | | - if (!docsLink.value) return |
151 | | - e.preventDefault() |
152 | | - navigateTo(docsLink.value) |
153 | | - }, |
154 | | - { dedupe: true }, |
155 | | -) |
156 | | -
|
157 | | -onKeyStroke( |
158 | | - e => keyboardShortcuts.value && isKeyWithoutModifiers(e, 'c') && !isEditableElement(e.target), |
159 | | - e => { |
160 | | - if (!props.pkg) return |
161 | | - e.preventDefault() |
162 | | - router.push({ name: 'compare', query: { packages: props.pkg.name } }) |
163 | | - }, |
164 | | - { dedupe: true }, |
165 | | -) |
166 | | -
|
167 | | -onKeyStroke( |
168 | | - e => keyboardShortcuts.value && isKeyWithoutModifiers(e, 'f') && !isEditableElement(e.target), |
169 | | - e => { |
170 | | - if (diffLink.value === null) return |
171 | | - e.preventDefault() |
172 | | - navigateTo(diffLink.value) |
173 | | - }, |
174 | | - { dedupe: true }, |
175 | | -) |
| 121 | +useShortcuts({ |
| 122 | + '.': () => codeLink.value, |
| 123 | + 'm': () => mainLink.value, |
| 124 | + 'd': () => docsLink.value, |
| 125 | + 'c': () => props.pkg && { name: 'compare' as const, query: { packages: props.pkg.name } }, |
| 126 | + 'f': () => diffLink.value, |
| 127 | +}) |
176 | 128 |
|
177 | 129 | const fundingUrl = computed(() => { |
178 | 130 | let funding = props.displayVersion?.funding |
|
0 commit comments