mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-29 10:42:44 +00:00
Refactor sidebarTabStore (#1111)
This commit is contained in:
45
src/stores/workspace/sidebarTabStore.ts
Normal file
45
src/stores/workspace/sidebarTabStore.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { SidebarTabExtension } from '@/types/extensionTypes'
|
||||
import { defineStore } from 'pinia'
|
||||
import { computed, ref } from 'vue'
|
||||
|
||||
export const useSidebarTabStore = defineStore('sidebarTab', () => {
|
||||
const sidebarTabs = ref<SidebarTabExtension[]>([])
|
||||
const activeSidebarTabId = ref<string | null>(null)
|
||||
|
||||
const activeSidebarTab = computed<SidebarTabExtension | null>(() => {
|
||||
return (
|
||||
sidebarTabs.value.find((tab) => tab.id === activeSidebarTabId.value) ??
|
||||
null
|
||||
)
|
||||
})
|
||||
|
||||
const toggleSidebarTab = (tabId: string) => {
|
||||
activeSidebarTabId.value = activeSidebarTabId.value === tabId ? null : tabId
|
||||
}
|
||||
|
||||
const registerSidebarTab = (tab: SidebarTabExtension) => {
|
||||
sidebarTabs.value = [...sidebarTabs.value, tab]
|
||||
}
|
||||
|
||||
const unregisterSidebarTab = (id: string) => {
|
||||
const index = sidebarTabs.value.findIndex((tab) => tab.id === id)
|
||||
if (index !== -1) {
|
||||
const tab = sidebarTabs.value[index]
|
||||
if (tab.type === 'custom' && tab.destroy) {
|
||||
tab.destroy()
|
||||
}
|
||||
const newSidebarTabs = [...sidebarTabs.value]
|
||||
newSidebarTabs.splice(index, 1)
|
||||
sidebarTabs.value = newSidebarTabs
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
sidebarTabs,
|
||||
activeSidebarTabId,
|
||||
activeSidebarTab,
|
||||
toggleSidebarTab,
|
||||
registerSidebarTab,
|
||||
unregisterSidebarTab
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user