Files
ComfyUI_frontend/src/stores/workspaceStateStore.ts
Chenlei Hu 3585cb69f5 Allow extension register custom topbar menu command (#982)
* Refactor command store

* Rename coreMenuStore to menuStore

* Extension API to register command

* Update README

* Add playwright test
2024-09-26 10:44:15 +09:00

56 lines
1.5 KiB
TypeScript

import type { SidebarTabExtension, ToastManager } from '@/types/extensionTypes'
import { defineStore } from 'pinia'
import { useToastStore } from './toastStore'
import { useQueueSettingsStore } from './queueStore'
import { useMenuItemStore } from './menuItemStore'
interface WorkspaceState {
spinner: boolean
activeSidebarTab: string | null
sidebarTabs: SidebarTabExtension[]
}
export const useWorkspaceStore = defineStore('workspace', {
state: (): WorkspaceState => ({
spinner: false,
activeSidebarTab: null,
sidebarTabs: []
}),
getters: {
toast(): ToastManager {
return useToastStore()
},
queueSettings() {
return useQueueSettingsStore()
},
menu() {
return {
registerTopbarCommands: useMenuItemStore().registerCommands
}
}
},
actions: {
updateActiveSidebarTab(tabId: string) {
this.activeSidebarTab = tabId
},
registerSidebarTab(tab: SidebarTabExtension) {
this.sidebarTabs = [...this.sidebarTabs, tab]
},
unregisterSidebarTab(id: string) {
const index = this.sidebarTabs.findIndex((tab) => tab.id === id)
if (index !== -1) {
const tab = this.sidebarTabs[index]
if (tab.type === 'custom' && tab.destroy) {
tab.destroy()
}
const newSidebarTabs = [...this.sidebarTabs]
newSidebarTabs.splice(index, 1)
this.sidebarTabs = newSidebarTabs
}
},
getSidebarTabs() {
return [...this.sidebarTabs]
}
}
})