[Refactor] Move addNodeOnGraph to litegraphService (#2100)

This commit is contained in:
Chenlei Hu
2024-12-30 16:09:44 -05:00
committed by GitHub
parent be7e2c6505
commit 3bf0dfd218
7 changed files with 48 additions and 40 deletions

View File

@@ -33,7 +33,6 @@
</template>
<script setup lang="ts">
import { app } from '@/scripts/app'
import { computed, ref, toRaw, watchEffect } from 'vue'
import NodeSearchBox from './NodeSearchBox.vue'
import Dialog from 'primevue/dialog'
@@ -53,15 +52,17 @@ import type {
import { useEventListener } from '@vueuse/core'
import { useSearchBoxStore } from '@/stores/workspace/searchBoxStore'
import { storeToRefs } from 'pinia'
import { useLitegraphService } from '@/services/litegraphService'
const settingStore = useSettingStore()
const litegraphService = useLitegraphService()
const { visible } = storeToRefs(useSearchBoxStore())
const dismissable = ref(true)
const triggerEvent = ref<LiteGraphCanvasEvent | null>(null)
const getNewNodeLocation = (): Vector2 => {
if (!triggerEvent.value) {
return app.getCanvasCenter()
return litegraphService.getCanvasCenter()
}
const originalEvent = (triggerEvent.value.detail as OriginalEvent)
@@ -85,7 +86,9 @@ const closeDialog = () => {
}
const addNode = (nodeDef: ComfyNodeDefImpl) => {
const node = app.addNodeOnGraph(nodeDef, { pos: getNewNodeLocation() })
const node = litegraphService.addNodeOnGraph(nodeDef, {
pos: getNewNodeLocation()
})
const eventDetail = triggerEvent.value?.detail
if (eventDetail && eventDetail.subType === 'empty-release') {