mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-25 17:24:07 +00:00
Fix extension register tab with API (#229)
* Get rid of extension manager impl * nit * Test register tab
This commit is contained in:
@@ -1,43 +0,0 @@
|
||||
import { useWorkspaceStore } from '@/stores/workspaceStateStore'
|
||||
import { ExtensionManager, SidebarTabExtension } from '@/types/extensionTypes'
|
||||
|
||||
export class ExtensionManagerImpl implements ExtensionManager {
|
||||
private sidebarTabs: SidebarTabExtension[] = []
|
||||
private workspaceStore = useWorkspaceStore()
|
||||
|
||||
registerSidebarTab(tab: SidebarTabExtension) {
|
||||
this.sidebarTabs.push(tab)
|
||||
this.updateSidebarOrder()
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
this.sidebarTabs.splice(index, 1)
|
||||
this.updateSidebarOrder()
|
||||
}
|
||||
}
|
||||
|
||||
getSidebarTabs() {
|
||||
return this.sidebarTabs.sort((a, b) => {
|
||||
const orderA = this.workspaceStore.sidebarTabsOrder.indexOf(a.id)
|
||||
const orderB = this.workspaceStore.sidebarTabsOrder.indexOf(b.id)
|
||||
return orderA - orderB
|
||||
})
|
||||
}
|
||||
|
||||
private updateSidebarOrder() {
|
||||
const currentOrder = this.workspaceStore.sidebarTabsOrder
|
||||
const newTabs = this.sidebarTabs.filter(
|
||||
(tab) => !currentOrder.includes(tab.id)
|
||||
)
|
||||
this.workspaceStore.updateSidebarOrder([
|
||||
...currentOrder,
|
||||
...newTabs.map((tab) => tab.id)
|
||||
])
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user