feat(CommandPalette): handle static groups (#1458)

Co-authored-by: Benjamin Canac <canacb1@gmail.com>
This commit is contained in:
Maxime Pauvert
2024-07-23 16:05:20 +02:00
committed by GitHub
parent f374b14dba
commit b264ad2ebd
2 changed files with 8 additions and 2 deletions

View File

@@ -216,7 +216,7 @@ export default defineComponent({
const commands = computed(() => { const commands = computed(() => {
const commands: Command[] = [] const commands: Command[] = []
for (const group of props.groups) { for (const group of props.groups) {
if (!group.search) { if (!group.search && !group.static) {
commands.push(...(group.commands?.map(command => ({ ...command, group: group.key })) || [])) commands.push(...(group.commands?.map(command => ({ ...command, group: group.key })) || []))
} }
} }
@@ -274,9 +274,14 @@ export default defineComponent({
return getGroupWithCommands(group, [...commands]) return getGroupWithCommands(group, [...commands])
}) })
const staticGroups: Group[] = props.groups.filter((group) => group.static && group.commands?.length).map((group) => {
return getGroupWithCommands(group, group.commands)
})
return [ return [
...groups, ...groups,
...searchGroups ...searchGroups,
...staticGroups
] ]
}) })

View File

@@ -24,5 +24,6 @@ export interface Group {
commands?: Command[] commands?: Command[]
search?: Function search?: Function
filter?: Function filter?: Function
static?: Boolean
[key: string]: any [key: string]: any
} }