Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions src/scripts/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { shallowRef } from 'vue'
import { useCanvasPositionConversion } from '@/composables/element/useCanvasPositionConversion'
import { registerProxyWidgets } from '@/core/graph/subgraph/proxyWidget'
import { st, t } from '@/i18n'
import type { IContextMenuValue } from '@/lib/litegraph/src/interfaces'
import {
LGraph,
LGraphCanvas,
Expand Down Expand Up @@ -1667,6 +1668,56 @@ export class ComfyApp {
useExtensionService().registerExtension(extension)
}

/**
* Collects context menu items from all extensions for canvas menus
* @param canvas The canvas instance
* @returns Array of context menu items from all extensions
*/
collectCanvasMenuItems(canvas: LGraphCanvas): IContextMenuValue[] {
const items: IContextMenuValue[] = []

for (const ext of this.extensions) {
if (ext.getCanvasMenuItems) {
try {
const extItems = ext.getCanvasMenuItems(canvas)
items.push(...extItems)
} catch (error) {
console.error(
`[Context Menu] Extension "${ext.name}" failed to provide canvas menu items:`,
error
)
}
}
}

return items
}

/**
* Collects context menu items from all extensions for node menus
* @param node The node being right-clicked
* @returns Array of context menu items from all extensions
*/
collectNodeMenuItems(node: LGraphNode): IContextMenuValue[] {
const items: IContextMenuValue[] = []

for (const ext of this.extensions) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

if (ext.getNodeMenuItems) {
try {
const extItems = ext.getNodeMenuItems(node)
items.push(...extItems)
} catch (error) {
console.error(
`[Context Menu] Extension "${ext.name}" failed to provide node menu items:`,
error
)
}
}
}

return items
}

/**
* Refresh combo list on whole nodes
*/
Expand Down
21 changes: 19 additions & 2 deletions src/types/comfy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import type { Positionable } from '@/lib/litegraph/src/interfaces'
import type { LGraphNode } from '@/lib/litegraph/src/litegraph'
import type {
IContextMenuValue,
Positionable
} from '@/lib/litegraph/src/interfaces'
import type { LGraphCanvas, LGraphNode } from '@/lib/litegraph/src/litegraph'
import type { SettingParams } from '@/platform/settings/types'
import type { ComfyWorkflowJSON } from '@/platform/workflow/validation/schemas/workflowSchema'
import type { Keybinding } from '@/schemas/keyBindingSchema'
Expand Down Expand Up @@ -106,6 +109,20 @@ export interface ComfyExtension {
*/
getSelectionToolboxCommands?(selectedItem: Positionable): string[]

/**
* Allows the extension to add context menu items to canvas right-click menus
* @param canvas The canvas instance
* @returns An array of context menu items to add
*/
getCanvasMenuItems?(canvas: LGraphCanvas): IContextMenuValue[]

/**
* Allows the extension to add context menu items to node right-click menus
* @param node The node being right-clicked
* @returns An array of context menu items to add
*/
getNodeMenuItems?(node: LGraphNode): IContextMenuValue[]

/**
* Allows the extension to add additional handling to the node before it is registered with **LGraph**
* @param nodeType The node class (not an instance)
Expand Down
Loading