mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-19 06:20:10 +00:00
Display recommended widgets on conversion.
This code will need refactoring later.
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
DEFAULT_DARK_COLOR_PALETTE,
|
||||
DEFAULT_LIGHT_COLOR_PALETTE
|
||||
} from '@/constants/coreColorPalettes'
|
||||
import { promoteRecommendedWidgets } from '@/core/graph/subgraph/proxyWidgetUtils'
|
||||
import { t } from '@/i18n'
|
||||
import {
|
||||
LGraphEventMode,
|
||||
@@ -858,6 +859,7 @@ export function useCoreCommands(): ComfyCommand[] {
|
||||
|
||||
const { node } = res
|
||||
canvas.select(node)
|
||||
promoteRecommendedWidgets(node)
|
||||
canvasStore.updateSelectedItems()
|
||||
}
|
||||
},
|
||||
|
||||
@@ -4,7 +4,10 @@ import type {
|
||||
} from '@/lib/litegraph/src/litegraph'
|
||||
import { SubgraphNode } from '@/lib/litegraph/src/subgraph/SubgraphNode'
|
||||
import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets.ts'
|
||||
import { parseProxyWidgets } from '@/schemas/proxyWidget'
|
||||
import {
|
||||
type ProxyWidgetsProperty,
|
||||
parseProxyWidgets
|
||||
} from '@/schemas/proxyWidget'
|
||||
import { useSubgraphNavigationStore } from '@/stores/subgraphNavigationStore'
|
||||
|
||||
function pushWidgets(node: SubgraphNode, ...widgets: [string, string][]) {
|
||||
@@ -90,3 +93,34 @@ export function addWidgetPromotionOptions(
|
||||
})
|
||||
}
|
||||
}
|
||||
//FIXME: This currently has ugly duplication with the sidebar pane
|
||||
//Refactor all the computed widget logic into a separate file (composable?)
|
||||
type WidgetItem = [LGraphNode, IBaseWidget]
|
||||
const recommendedNodes = [
|
||||
'CLIPTextEncode',
|
||||
'LoadImage',
|
||||
'SaveImage',
|
||||
'PreviewImage'
|
||||
]
|
||||
const recommendedWidgetNames = ['seed']
|
||||
function nodeWidgets(n: LGraphNode): WidgetItem[] {
|
||||
if (!n.widgets) return []
|
||||
return n.widgets.map((w: IBaseWidget) => [n, w])
|
||||
}
|
||||
export function promoteRecommendedWidgets(subgraphNode: SubgraphNode) {
|
||||
const interiorNodes = subgraphNode.subgraph.nodes
|
||||
const filteredWidgets: WidgetItem[] = interiorNodes
|
||||
.flatMap(nodeWidgets)
|
||||
//widget has connected link. Should not be eligible for promotion
|
||||
.filter(([_, w]: WidgetItem) => !w.computedDisabled)
|
||||
.filter(
|
||||
([node, widget]: WidgetItem) =>
|
||||
recommendedNodes.includes(node.type) ||
|
||||
recommendedWidgetNames.includes(widget.name)
|
||||
)
|
||||
const pw: ProxyWidgetsProperty = filteredWidgets.map(([n, w]: WidgetItem) => [
|
||||
`${n.id}`,
|
||||
w.name
|
||||
])
|
||||
subgraphNode.properties.proxyWidgets = JSON.stringify(pw)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user