@@ -3,6 +3,7 @@ import { type NodeId } from '@/lib/litegraph/src/LGraphNode'
3
3
import {
4
4
type ExecutableLGraphNode ,
5
5
type ExecutionId ,
6
+ LGraphCanvas ,
6
7
LGraphNode ,
7
8
LiteGraph ,
8
9
SubgraphNode
@@ -1172,8 +1173,7 @@ export class GroupNodeHandler {
1172
1173
// @ts -expect-error fixme ts strict error
1173
1174
getExtraMenuOptions ?. apply ( this , arguments )
1174
1175
1175
- // @ts -expect-error fixme ts strict error
1176
- let optionIndex = options . findIndex ( ( o ) => o . content === 'Outputs' )
1176
+ let optionIndex = options . findIndex ( ( o ) => o ?. content === 'Outputs' )
1177
1177
if ( optionIndex === - 1 ) optionIndex = options . length
1178
1178
else optionIndex ++
1179
1179
options . splice (
@@ -1634,6 +1634,57 @@ export class GroupNodeHandler {
1634
1634
}
1635
1635
}
1636
1636
1637
+ function addConvertToGroupOptions ( ) {
1638
+ // @ts -expect-error fixme ts strict error
1639
+ function addConvertOption ( options , index ) {
1640
+ const selected = Object . values ( app . canvas . selected_nodes ?? { } )
1641
+ const disabled =
1642
+ selected . length < 2 ||
1643
+ selected . find ( ( n ) => GroupNodeHandler . isGroupNode ( n ) )
1644
+ options . splice ( index , null , {
1645
+ content : `Convert to Group Node (Deprecated)` ,
1646
+ disabled,
1647
+ callback : convertSelectedNodesToGroupNode
1648
+ } )
1649
+ }
1650
+
1651
+ // @ts -expect-error fixme ts strict error
1652
+ function addManageOption ( options , index ) {
1653
+ const groups = app . graph . extra ?. groupNodes
1654
+ const disabled = ! groups || ! Object . keys ( groups ) . length
1655
+ options . splice ( index , null , {
1656
+ content : `Manage Group Nodes` ,
1657
+ disabled,
1658
+ callback : ( ) => manageGroupNodes ( )
1659
+ } )
1660
+ }
1661
+
1662
+ // Add to canvas
1663
+ const getCanvasMenuOptions = LGraphCanvas . prototype . getCanvasMenuOptions
1664
+ LGraphCanvas . prototype . getCanvasMenuOptions = function ( ) {
1665
+ // @ts -expect-error fixme ts strict error
1666
+ const options = getCanvasMenuOptions . apply ( this , arguments )
1667
+ const index = options . findIndex ( ( o ) => o ?. content === 'Add Group' )
1668
+ const insertAt = index === - 1 ? options . length - 1 : index + 2
1669
+ addConvertOption ( options , insertAt )
1670
+ addManageOption ( options , insertAt + 1 )
1671
+ return options
1672
+ }
1673
+
1674
+ // Add to nodes
1675
+ const getNodeMenuOptions = LGraphCanvas . prototype . getNodeMenuOptions
1676
+ LGraphCanvas . prototype . getNodeMenuOptions = function ( node ) {
1677
+ // @ts -expect-error fixme ts strict error
1678
+ const options = getNodeMenuOptions . apply ( this , arguments )
1679
+ if ( ! GroupNodeHandler . isGroupNode ( node ) ) {
1680
+ const index = options . findIndex ( ( o ) => o ?. content === 'Properties' )
1681
+ const insertAt = index === - 1 ? options . length - 1 : index
1682
+ addConvertOption ( options , insertAt )
1683
+ }
1684
+ return options
1685
+ }
1686
+ }
1687
+
1637
1688
const replaceLegacySeparators = ( nodes : ComfyNode [ ] ) : void => {
1638
1689
for ( const node of nodes ) {
1639
1690
if ( typeof node . type === 'string' && node . type . startsWith ( 'workflow/' ) ) {
@@ -1729,6 +1780,9 @@ const ext: ComfyExtension = {
1729
1780
}
1730
1781
}
1731
1782
] ,
1783
+ setup ( ) {
1784
+ addConvertToGroupOptions ( )
1785
+ } ,
1732
1786
async beforeConfigureGraph (
1733
1787
graphData : ComfyWorkflowJSON ,
1734
1788
missingNodeTypes : string [ ]
0 commit comments