This commit is contained in:
bymyself
2025-11-13 10:05:29 -08:00
parent 8bb1d5724b
commit c30e1faa22
4 changed files with 47 additions and 35 deletions

View File

@@ -35,10 +35,8 @@ import { selectionBounds } from '@/renderer/core/layout/utils/layoutMath'
import { api } from '@/scripts/api'
import { app } from '@/scripts/app'
import { useDialogService } from '@/services/dialogService'
import {
invokeToggleWidgetPromotion,
useLitegraphService
} from '@/services/litegraphService'
import { useLitegraphService } from '@/services/litegraphService'
import { invokeToggleWidgetPromotion } from '@/services/widgetPromotionHandlers'
import type { ComfyCommand } from '@/stores/commandStore'
import { useExecutionStore } from '@/stores/executionStore'
import { useHelpCenterStore } from '@/stores/helpCenterStore'

View File

@@ -13,10 +13,8 @@ import type { SubgraphNode } from '@/lib/litegraph/src/subgraph/SubgraphNode'
import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets.ts'
import { useToastStore } from '@/platform/updates/common/toastStore'
import { useCanvasStore } from '@/renderer/core/canvas/canvasStore'
import {
registerWidgetPromotionHandlers,
useLitegraphService
} from '@/services/litegraphService'
import { useLitegraphService } from '@/services/litegraphService'
import { registerWidgetPromotionHandlers } from '@/services/widgetPromotionHandlers'
import { useSubgraphNavigationStore } from '@/stores/subgraphNavigationStore'
type PartialNode = Pick<LGraphNode, 'title' | 'id' | 'type'>

View File

@@ -21,7 +21,6 @@ import type {
Point,
Subgraph
} from '@/lib/litegraph/src/litegraph'
import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets'
import type {
ExportedSubgraphInstance,
ISerialisableNodeInput,
@@ -58,31 +57,11 @@ import {
import { getOrderedInputSpecs } from '@/utils/nodeDefOrderingUtil'
import { useExtensionService } from './extensionService'
import { addWidgetPromotionOptions as invokeAddWidgetPromotionOptions } from './widgetPromotionHandlers'
export const CONFIG = Symbol()
export const GET_CONFIG = Symbol()
type WidgetPromotionHandlers = {
addWidgetPromotionOptions?: (
options: (IContextMenuValue<unknown> | null)[],
widget: IBaseWidget,
node: LGraphNode
) => void
tryToggleWidgetPromotion?: () => void
}
let widgetPromotionHandlers: WidgetPromotionHandlers = {}
export const registerWidgetPromotionHandlers = (
handlers: WidgetPromotionHandlers
) => {
widgetPromotionHandlers = handlers
}
export const invokeToggleWidgetPromotion = () => {
widgetPromotionHandlers.tryToggleWidgetPromotion?.()
}
/**
* Service that augments litegraph with ComfyUI specific functionality.
*/
@@ -847,11 +826,7 @@ export const useLitegraphService = () => {
const [x, y] = canvas.graph_mouse
const overWidget = this.getWidgetOnPos(x, y, true)
if (overWidget) {
widgetPromotionHandlers.addWidgetPromotionOptions?.(
options,
overWidget,
this
)
invokeAddWidgetPromotionOptions(options, overWidget, this)
}
}

View File

@@ -0,0 +1,41 @@
import { shallowRef } from 'vue'
import type {
IContextMenuValue,
LGraphNode
} from '@/lib/litegraph/src/litegraph'
import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets'
type WidgetPromotionHandlers = {
addWidgetPromotionOptions?: (
options: (IContextMenuValue<unknown> | null)[],
widget: IBaseWidget,
node: LGraphNode
) => void
tryToggleWidgetPromotion?: () => void
}
const handlersRef = shallowRef<WidgetPromotionHandlers>({})
export const registerWidgetPromotionHandlers = (
handlers: WidgetPromotionHandlers
) => {
handlersRef.value = handlers
return () => {
if (handlersRef.value === handlers) {
handlersRef.value = {}
}
}
}
export const invokeToggleWidgetPromotion = () => {
handlersRef.value.tryToggleWidgetPromotion?.()
}
export const addWidgetPromotionOptions = (
options: (IContextMenuValue<unknown> | null)[],
widget: IBaseWidget,
node: LGraphNode
) => {
handlersRef.value.addWidgetPromotionOptions?.(options, widget, node)
}