From a24819f5b1bfede842bbdd7f03aeb35a60ec1815 Mon Sep 17 00:00:00 2001 From: arlo Date: Mon, 8 Jan 2024 20:20:06 +0800 Subject: [PATCH] chore: update --- packages/client/src/composables/state-commands.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/client/src/composables/state-commands.ts b/packages/client/src/composables/state-commands.ts index 62e50279..586b6358 100644 --- a/packages/client/src/composables/state-commands.ts +++ b/packages/client/src/composables/state-commands.ts @@ -12,6 +12,12 @@ export interface CommandItem { action: () => void | CommandItem[] | Promise } +function uniqueById(items: CommandItem[]): CommandItem[] { + const unique = new Map() + items.forEach(item => unique.set(item.id, item)) + return Array.from(unique.values()) +} + const registeredCommands = reactive(new Map>()) // @unocss-include @@ -68,13 +74,13 @@ export function useCommands() { })) return computed(() => { - return [ + return uniqueById([ ...fixedCommands, ...tabCommands.value, ...resolveCustomCommands(customCommands.value), ...Array.from(registeredCommands.values()) .flatMap(i => toValue(i)), - ] + ]) }) }