Skip to content

Commit 516baeb

Browse files
committed
chore: apply suggestions from copilot
1 parent 6020a50 commit 516baeb

4 files changed

Lines changed: 60 additions & 38 deletions

File tree

app/components/CommandBar.vue

Lines changed: 50 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,54 @@
11
<template>
2-
<Transition name="fade">
3-
<div
4-
class="fixed inset-0 z-[1000] flex items-start justify-center bg-black/50 backdrop-blur-sm"
5-
v-show="show"
6-
>
2+
<Teleport to="body">
3+
<Transition name="fade">
74
<div
8-
class="cmdbar-container flex items-center justify-center border border-border shadow-lg rounded-xl bg-bg p2 flex-col gap-2 mt-5rem"
5+
class="fixed inset-0 z-[1000] flex items-start justify-center bg-black/50 backdrop-blur-sm"
6+
v-show="show"
97
>
10-
<label for="command-input" class="sr-only">command-input</label>
11-
12-
<search class="relative w-xl h-12 flex items-center">
13-
<span class="absolute inset-is-4 text-fg-subtle font-mono pointer-events-none"> > </span>
14-
<input
15-
type="text"
16-
v-model="inputVal"
17-
id="command-input"
18-
ref="inputRef"
19-
class="w-full h-full px-4 pl-8 text-fg outline-none bg-bg-subtle border border-border rounded-md"
20-
:placeholder="placeholderText"
21-
@keydown="handleKeydown"
22-
/>
23-
</search>
24-
25-
<div class="w-xl max-h-lg overflow-auto" v-if="view.type != 'INPUT'">
26-
<div
27-
v-for="item in filteredCmdList"
28-
:key="item.id"
29-
class="flex-col items-center justify-between px-4 py-2 not-first:mt-2 hover:bg-bg-elevated select-none cursor-pointer rounded-md transition"
30-
:class="{
31-
'bg-bg-subtle': item.id === selected,
32-
'trigger-anim': item.id === triggeringId,
33-
}"
34-
@click="onTrigger(item.id)"
35-
>
36-
<div class="text-fg">{{ item.name }}</div>
37-
<div class="text-fg-subtle text-sm">{{ item.description }}</div>
8+
<div
9+
class="cmdbar-container flex items-center justify-center border border-border shadow-lg rounded-xl bg-bg p2 flex-col gap-2 mt-5rem"
10+
role="dialog"
11+
aria-modal="true"
12+
aria-labelledby="command-input-label"
13+
>
14+
<label for="command-input" id="command-input-label" class="sr-only">{{
15+
t('command.label')
16+
}}</label>
17+
18+
<search class="relative w-xl h-12 flex items-center">
19+
<span class="absolute inset-is-4 text-fg-subtle font-mono pointer-events-none">
20+
>
21+
</span>
22+
<input
23+
type="text"
24+
v-model="inputVal"
25+
id="command-input"
26+
ref="inputRef"
27+
class="w-full h-full px-4 pl-8 text-fg outline-none bg-bg-subtle border border-border rounded-md"
28+
:placeholder="placeholderText"
29+
@keydown="handleKeydown"
30+
/>
31+
</search>
32+
33+
<div class="w-xl max-h-lg overflow-auto" v-if="view.type != 'INPUT'">
34+
<div
35+
v-for="item in filteredCmdList"
36+
:key="item.id"
37+
class="px-4 py-2 not-first:mt-2 hover:bg-bg-elevated select-none cursor-pointer rounded-md transition"
38+
:class="{
39+
'bg-bg-subtle': item.id === selected,
40+
'trigger-anim': item.id === triggeringId,
41+
}"
42+
@click="onTrigger(item.id)"
43+
>
44+
<div class="text-fg">{{ item.name }}</div>
45+
<div class="text-fg-subtle text-sm">{{ item.description }}</div>
46+
</div>
3847
</div>
3948
</div>
4049
</div>
41-
</div>
42-
</Transition>
50+
</Transition>
51+
</Teleport>
4352
</template>
4453

4554
<script setup lang="ts">
@@ -164,6 +173,11 @@ const handleKeydown = useThrottleFn((e: KeyboardEvent) => {
164173
return
165174
}
166175
176+
if ((e.key === 'ArrowDown' || e.key === 'ArrowUp') && !filteredCmdList.value.length) {
177+
e.preventDefault()
178+
return
179+
}
180+
167181
const currentIndex = filteredCmdList.value.findIndex((item: any) => item.id === selected.value)
168182
169183
if (e.key === 'ArrowDown') {

app/plugins/commands.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ export default defineNuxtPlugin(() => {
22
const { register } = useCommandRegistry()
33
const router = useRouter()
44

5+
const { t } = useI18n()
6+
57
register({
68
id: 'packages:search',
7-
name: 'Search Packages',
8-
description: 'Search for npm packages',
9+
name: t('command.package_search'),
10+
description: t('command.package_search_desc'),
911
handler: async () => {
1012
const searchInput = document.querySelector<HTMLInputElement>(
1113
'input[type="search"], input[name="q"]',

i18n/locales/en.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,9 @@
798798
},
799799
"command": {
800800
"placeholder": "Enter command...",
801+
"label": "Command",
802+
"package_search": "Search packages",
803+
"package_search_desc": "Search for npm packages",
801804
"copy_install": "Copy install command",
802805
"copy_install_desc": "Copy install command to clipboard",
803806
"copy_run": "Copy run command",

i18n/locales/zh-CN.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,9 @@
782782
},
783783
"command": {
784784
"placeholder": "输入命令...",
785+
"label": "命令",
786+
"package_search": "搜索包",
787+
"package_search_desc": "搜索 npm 包",
785788
"copy_install": "复制安装命令",
786789
"copy_install_desc": "复制安装命令到剪贴板",
787790
"copy_run": "复制运行命令",

0 commit comments

Comments
 (0)