@@ -7,6 +7,7 @@ import { shallowRef } from 'vue'
77import { useCanvasPositionConversion } from '@/composables/element/useCanvasPositionConversion'
88import { registerProxyWidgets } from '@/core/graph/subgraph/proxyWidget'
99import { st , t } from '@/i18n'
10+ import type { IContextMenuValue } from '@/lib/litegraph/src/interfaces'
1011import {
1112 LGraph ,
1213 LGraphCanvas ,
@@ -1667,6 +1668,56 @@ export class ComfyApp {
16671668 useExtensionService ( ) . registerExtension ( extension )
16681669 }
16691670
1671+ /**
1672+ * Collects context menu items from all extensions for canvas menus
1673+ * @param canvas The canvas instance
1674+ * @returns Array of context menu items from all extensions
1675+ */
1676+ collectCanvasMenuItems ( canvas : LGraphCanvas ) : IContextMenuValue [ ] {
1677+ const items : IContextMenuValue [ ] = [ ]
1678+
1679+ for ( const ext of this . extensions ) {
1680+ if ( ext . getCanvasMenuItems ) {
1681+ try {
1682+ const extItems = ext . getCanvasMenuItems ( canvas )
1683+ items . push ( ...extItems )
1684+ } catch ( error ) {
1685+ console . error (
1686+ `[Context Menu] Extension "${ ext . name } " failed to provide canvas menu items:` ,
1687+ error
1688+ )
1689+ }
1690+ }
1691+ }
1692+
1693+ return items
1694+ }
1695+
1696+ /**
1697+ * Collects context menu items from all extensions for node menus
1698+ * @param node The node being right-clicked
1699+ * @returns Array of context menu items from all extensions
1700+ */
1701+ collectNodeMenuItems ( node : LGraphNode ) : IContextMenuValue [ ] {
1702+ const items : IContextMenuValue [ ] = [ ]
1703+
1704+ for ( const ext of this . extensions ) {
1705+ if ( ext . getNodeMenuItems ) {
1706+ try {
1707+ const extItems = ext . getNodeMenuItems ( node )
1708+ items . push ( ...extItems )
1709+ } catch ( error ) {
1710+ console . error (
1711+ `[Context Menu] Extension "${ ext . name } " failed to provide node menu items:` ,
1712+ error
1713+ )
1714+ }
1715+ }
1716+ }
1717+
1718+ return items
1719+ }
1720+
16701721 /**
16711722 * Refresh combo list on whole nodes
16721723 */
0 commit comments