From b264ad2ebdc8d4ee4aab5c994df968025207021f Mon Sep 17 00:00:00 2001 From: Maxime Pauvert Date: Tue, 23 Jul 2024 16:05:20 +0200 Subject: [PATCH] feat(CommandPalette): handle `static` groups (#1458) Co-authored-by: Benjamin Canac --- src/runtime/components/navigation/CommandPalette.vue | 9 +++++++-- src/runtime/types/command-palette.ts | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/runtime/components/navigation/CommandPalette.vue b/src/runtime/components/navigation/CommandPalette.vue index d27e650c..3e186d34 100644 --- a/src/runtime/components/navigation/CommandPalette.vue +++ b/src/runtime/components/navigation/CommandPalette.vue @@ -216,7 +216,7 @@ export default defineComponent({ const commands = computed(() => { const commands: Command[] = [] for (const group of props.groups) { - if (!group.search) { + if (!group.search && !group.static) { commands.push(...(group.commands?.map(command => ({ ...command, group: group.key })) || [])) } } @@ -274,9 +274,14 @@ export default defineComponent({ return getGroupWithCommands(group, [...commands]) }) + const staticGroups: Group[] = props.groups.filter((group) => group.static && group.commands?.length).map((group) => { + return getGroupWithCommands(group, group.commands) + }) + return [ ...groups, - ...searchGroups + ...searchGroups, + ...staticGroups ] }) diff --git a/src/runtime/types/command-palette.ts b/src/runtime/types/command-palette.ts index 4a46f5f1..d08acfc5 100644 --- a/src/runtime/types/command-palette.ts +++ b/src/runtime/types/command-palette.ts @@ -24,5 +24,6 @@ export interface Group { commands?: Command[] search?: Function filter?: Function + static?: Boolean [key: string]: any }