mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-29 10:42:44 +00:00
Add pp.addNodeOnGraph to simplify adding node on canvas (#239)
This commit is contained in:
@@ -22,19 +22,17 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { app } from '@/scripts/app'
|
import { app } from '@/scripts/app'
|
||||||
import { inject, onMounted, onUnmounted, reactive, Ref, ref } from 'vue'
|
import { onMounted, onUnmounted, reactive, ref } from 'vue'
|
||||||
import NodeSearchBox from './NodeSearchBox.vue'
|
import NodeSearchBox from './NodeSearchBox.vue'
|
||||||
import Dialog from 'primevue/dialog'
|
import Dialog from 'primevue/dialog'
|
||||||
import {
|
import {
|
||||||
INodeSlot,
|
INodeSlot,
|
||||||
LiteGraph,
|
|
||||||
LiteGraphCanvasEvent,
|
LiteGraphCanvasEvent,
|
||||||
LGraphNode,
|
LGraphNode,
|
||||||
LinkReleaseContext
|
LinkReleaseContext
|
||||||
} from '@comfyorg/litegraph'
|
} from '@comfyorg/litegraph'
|
||||||
import { FilterAndValue } from '@/services/nodeSearchService'
|
import { FilterAndValue } from '@/services/nodeSearchService'
|
||||||
import { ComfyNodeDef } from '@/types/apiTypes'
|
import { ComfyNodeDefImpl, useNodeDefStore } from '@/stores/nodeDefStore'
|
||||||
import { useNodeDefStore } from '@/stores/nodeDefStore'
|
|
||||||
|
|
||||||
interface LiteGraphPointerEvent extends Event {
|
interface LiteGraphPointerEvent extends Event {
|
||||||
canvasX: number
|
canvasX: number
|
||||||
@@ -99,17 +97,14 @@ const connectNodeOnLinkRelease = (
|
|||||||
node.connect(destSlotIndex, srcNode, srcSlotIndex)
|
node.connect(destSlotIndex, srcNode, srcSlotIndex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const addNode = (nodeDef: ComfyNodeDef) => {
|
const addNode = (nodeDef: ComfyNodeDefImpl) => {
|
||||||
closeDialog()
|
closeDialog()
|
||||||
const node = LiteGraph.createNode(nodeDef.name, nodeDef.display_name, {})
|
|
||||||
if (node) {
|
|
||||||
node.pos = getNewNodeLocation()
|
|
||||||
app.graph.add(node)
|
|
||||||
|
|
||||||
const eventDetail = triggerEvent.value.detail
|
const node = app.addNodeOnGraph(nodeDef, { pos: getNewNodeLocation() })
|
||||||
if (eventDetail.subType === 'empty-release') {
|
|
||||||
connectNodeOnLinkRelease(node, eventDetail.linkReleaseContext)
|
const eventDetail = triggerEvent.value.detail
|
||||||
}
|
if (eventDetail.subType === 'empty-release') {
|
||||||
|
connectNodeOnLinkRelease(node, eventDetail.linkReleaseContext)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,12 @@ import { StorageLocation } from '@/types/settingTypes'
|
|||||||
import '@comfyorg/litegraph/css/litegraph.css'
|
import '@comfyorg/litegraph/css/litegraph.css'
|
||||||
import '../assets/css/style.css'
|
import '../assets/css/style.css'
|
||||||
import { ExtensionManager } from '@/types/extensionTypes'
|
import { ExtensionManager } from '@/types/extensionTypes'
|
||||||
import { SYSTEM_NODE_DEFS, useNodeDefStore } from '@/stores/nodeDefStore'
|
import {
|
||||||
|
ComfyNodeDefImpl,
|
||||||
|
SYSTEM_NODE_DEFS,
|
||||||
|
useNodeDefStore
|
||||||
|
} from '@/stores/nodeDefStore'
|
||||||
|
import { Vector2 } from '@comfyorg/litegraph'
|
||||||
|
|
||||||
export const ANIM_PREVIEW_WIDGET = '$$comfy_animation_preview'
|
export const ANIM_PREVIEW_WIDGET = '$$comfy_animation_preview'
|
||||||
|
|
||||||
@@ -2933,6 +2938,19 @@ export class ComfyApp {
|
|||||||
this.lastExecutionError = null
|
this.lastExecutionError = null
|
||||||
this.runningNodeId = null
|
this.runningNodeId = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addNodeOnGraph(
|
||||||
|
nodeDef: ComfyNodeDef | ComfyNodeDefImpl,
|
||||||
|
options: Record<string, any> = {}
|
||||||
|
): LGraphNode {
|
||||||
|
const node = LiteGraph.createNode(
|
||||||
|
nodeDef.name,
|
||||||
|
nodeDef.display_name,
|
||||||
|
options
|
||||||
|
)
|
||||||
|
this.graph.add(node)
|
||||||
|
return node
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const app = new ComfyApp()
|
export const app = new ComfyApp()
|
||||||
|
|||||||
Reference in New Issue
Block a user