mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-06 16:10:09 +00:00
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
import { SidebarTabExtension, ToastManager } from '@/types/extensionTypes'
|
|
import { defineStore } from 'pinia'
|
|
import { useToastStore } from './toastStore'
|
|
|
|
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()
|
|
}
|
|
},
|
|
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]
|
|
}
|
|
}
|
|
})
|