mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-28 10:12:11 +00:00
[Refactor] Prefer canvas store over app.canvas
This commit is contained in:
@@ -20,8 +20,8 @@ import type {
|
|||||||
NodeId
|
NodeId
|
||||||
} from '@/schemas/comfyWorkflowSchema'
|
} from '@/schemas/comfyWorkflowSchema'
|
||||||
import { api } from '@/scripts/api'
|
import { api } from '@/scripts/api'
|
||||||
import { app } from '@/scripts/app'
|
|
||||||
|
|
||||||
|
import { useCanvasStore } from './graphStore'
|
||||||
import { ComfyWorkflow } from './workflowStore'
|
import { ComfyWorkflow } from './workflowStore'
|
||||||
|
|
||||||
export interface QueuedPrompt {
|
export interface QueuedPrompt {
|
||||||
@@ -37,6 +37,8 @@ export interface QueuedPrompt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const useExecutionStore = defineStore('execution', () => {
|
export const useExecutionStore = defineStore('execution', () => {
|
||||||
|
const canvasStore = useCanvasStore()
|
||||||
|
|
||||||
const clientId = ref<string | null>(null)
|
const clientId = ref<string | null>(null)
|
||||||
const activePromptId = ref<string | null>(null)
|
const activePromptId = ref<string | null>(null)
|
||||||
const queuedPrompts = ref<Record<NodeId, QueuedPrompt>>({})
|
const queuedPrompts = ref<Record<NodeId, QueuedPrompt>>({})
|
||||||
@@ -54,9 +56,8 @@ export const useExecutionStore = defineStore('execution', () => {
|
|||||||
if (!canvasState) return null
|
if (!canvasState) return null
|
||||||
|
|
||||||
return (
|
return (
|
||||||
canvasState.nodes.find(
|
canvasState.nodes.find((n) => String(n.id) === executingNodeId.value) ??
|
||||||
(n: ComfyNode) => String(n.id) === executingNodeId.value
|
null
|
||||||
) ?? null
|
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -156,7 +157,7 @@ export const useExecutionStore = defineStore('execution', () => {
|
|||||||
activePrompt.value.nodes[e.detail.node] = true
|
activePrompt.value.nodes[e.detail.node] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleExecuting(e: CustomEvent<NodeId | null>) {
|
function handleExecuting(e: CustomEvent<NodeId | null>): void {
|
||||||
// Clear the current node progress when a new node starts executing
|
// Clear the current node progress when a new node starts executing
|
||||||
_executingNodeProgress.value = null
|
_executingNodeProgress.value = null
|
||||||
|
|
||||||
@@ -196,7 +197,7 @@ export const useExecutionStore = defineStore('execution', () => {
|
|||||||
const { nodeId, text } = e.detail
|
const { nodeId, text } = e.detail
|
||||||
if (!text || !nodeId) return
|
if (!text || !nodeId) return
|
||||||
|
|
||||||
const node = app.graph.getNodeById(nodeId)
|
const node = canvasStore.getCanvas().graph?.getNodeById(nodeId)
|
||||||
if (!node) return
|
if (!node) return
|
||||||
|
|
||||||
useNodeProgressText().showTextPreview(node, text)
|
useNodeProgressText().showTextPreview(node, text)
|
||||||
@@ -204,7 +205,7 @@ export const useExecutionStore = defineStore('execution', () => {
|
|||||||
|
|
||||||
function handleDisplayComponent(e: CustomEvent<DisplayComponentWsMessage>) {
|
function handleDisplayComponent(e: CustomEvent<DisplayComponentWsMessage>) {
|
||||||
const { node_id, component, props = {} } = e.detail
|
const { node_id, component, props = {} } = e.detail
|
||||||
const node = app.graph.getNodeById(node_id)
|
const node = canvasStore.getCanvas().graph?.getNodeById(node_id)
|
||||||
if (!node) return
|
if (!node) return
|
||||||
|
|
||||||
if (component === 'ChatHistoryWidget') {
|
if (component === 'ChatHistoryWidget') {
|
||||||
|
|||||||
@@ -442,6 +442,14 @@ export const useWorkflowStore = defineStore('workflow', () => {
|
|||||||
isSubgraphActive.value = isSubgraph(subgraph)
|
isSubgraphActive.value = isSubgraph(subgraph)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const executionIdToCurrentId = (id: string) => {
|
||||||
|
const subgraph = activeSubgraph.value
|
||||||
|
|
||||||
|
if (!id.includes(':')) {
|
||||||
|
return subgraph
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
watch(activeWorkflow, updateActiveGraph)
|
watch(activeWorkflow, updateActiveGraph)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -469,7 +477,8 @@ export const useWorkflowStore = defineStore('workflow', () => {
|
|||||||
|
|
||||||
isSubgraphActive,
|
isSubgraphActive,
|
||||||
activeSubgraph,
|
activeSubgraph,
|
||||||
updateActiveGraph
|
updateActiveGraph,
|
||||||
|
executionIdToCurrentId
|
||||||
}
|
}
|
||||||
}) satisfies () => WorkflowStore
|
}) satisfies () => WorkflowStore
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user