mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-04 20:50:06 +00:00
Contextmenu Monkeypatch Standardization (#5977)
This pull request introduces a new extension API for context menu customization, allowing extensions to contribute items to both canvas and node right-click menus. It adds two collection methods to the `ComfyApp` class to aggregate these menu items from all registered extensions, and updates the extension interface accordingly. Comprehensive unit tests are included to verify the correct aggregation behavior and error handling. **Extension API for Context Menus:** * Added optional `getCanvasMenuItems` and `getNodeMenuItems` methods to the `ComfyExtension` interface, enabling extensions to provide context menu items for canvas and node right-click menus (`src/types/comfy.ts`). * Updated type imports to support the new API, including `IContextMenuValue`, `LGraphCanvas`, and `LGraphNode` (`src/types/comfy.ts`, `src/scripts/app.ts`). [[1]](diffhunk://#diff-c29886a1b0c982c6fff3545af0ca8ec269876c2cf3948f867d08c14032c04d66L1-R5) [[2]](diffhunk://#diff-bde0dce9fe2403685d27b0e94a938c3d72824d02d01d1fd6167a0dddc6e585ddR10) **Core Implementation:** * Implemented `collectCanvasMenuItems` and `collectNodeMenuItems` methods in the `ComfyApp` class to gather menu items from all extensions, with robust error handling and logging for extension failures (`src/scripts/app.ts`). **Testing:** * Added a comprehensive test suite for the new context menu extension API, covering aggregation logic, error handling, and integration scenarios (`tests-ui/tests/extensions/contextMenuExtension.test.ts`). This is PR 1 of the 3 PRs in the Contextmenu standardizations. -https://github.com/Comfy-Org/ComfyUI_frontend/pull/5992 -https://github.com/Comfy-Org/ComfyUI_frontend/pull/5993
This commit is contained in:
committed by
GitHub
parent
9a505100ac
commit
eeb0977738
@@ -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,
|
||||
@@ -1667,6 +1668,28 @@ 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[] {
|
||||
return useExtensionService()
|
||||
.invokeExtensions('getCanvasMenuItems', canvas)
|
||||
.flat() as IContextMenuValue[]
|
||||
}
|
||||
|
||||
/**
|
||||
* 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[] {
|
||||
return useExtensionService()
|
||||
.invokeExtensions('getNodeMenuItems', node)
|
||||
.flat() as IContextMenuValue[]
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh combo list on whole nodes
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user