mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-02 14:27:40 +00:00
refactor
This commit is contained in:
@@ -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'
|
||||
|
||||
@@ -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'>
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
41
src/services/widgetPromotionHandlers.ts
Normal file
41
src/services/widgetPromotionHandlers.ts
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user