mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-30 03:01:54 +00:00
[Reland] Restrict applyToGraph to PrimitiveNode (#2724)
This commit is contained in:
@@ -11,6 +11,7 @@ import { INodeSlot } from '@comfyorg/litegraph'
|
|||||||
import { useNodeDefStore } from '@/stores/nodeDefStore'
|
import { useNodeDefStore } from '@/stores/nodeDefStore'
|
||||||
import { useSettingStore } from '@/stores/settingStore'
|
import { useSettingStore } from '@/stores/settingStore'
|
||||||
import type { InputSpec } from '@/types/apiTypes'
|
import type { InputSpec } from '@/types/apiTypes'
|
||||||
|
import { isPrimitiveNode } from '@/utils/typeGuardUtil'
|
||||||
|
|
||||||
import { app } from '../../scripts/app'
|
import { app } from '../../scripts/app'
|
||||||
import { applyTextReplacements } from '../../scripts/utils'
|
import { applyTextReplacements } from '../../scripts/utils'
|
||||||
@@ -30,10 +31,8 @@ const CONFIG = Symbol()
|
|||||||
const GET_CONFIG = Symbol()
|
const GET_CONFIG = Symbol()
|
||||||
const TARGET = Symbol() // Used for reroutes to specify the real target widget
|
const TARGET = Symbol() // Used for reroutes to specify the real target widget
|
||||||
|
|
||||||
interface PrimitiveNode extends LGraphNode {}
|
|
||||||
|
|
||||||
const replacePropertyName = 'Run widget replace on values'
|
const replacePropertyName = 'Run widget replace on values'
|
||||||
class PrimitiveNode extends LGraphNode {
|
export class PrimitiveNode extends LGraphNode {
|
||||||
controlValues: any[]
|
controlValues: any[]
|
||||||
lastType: string
|
lastType: string
|
||||||
static category: string
|
static category: string
|
||||||
@@ -577,10 +576,6 @@ function isValidCombo(combo: string[], obj: unknown) {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
function isPrimitiveNode(node: LGraphNode): node is PrimitiveNode {
|
|
||||||
return node.type === 'PrimitiveNode'
|
|
||||||
}
|
|
||||||
|
|
||||||
export function setWidgetConfig(slot, config, target?: IWidget) {
|
export function setWidgetConfig(slot, config, target?: IWidget) {
|
||||||
if (!slot.widget) return
|
if (!slot.widget) return
|
||||||
if (config) {
|
if (config) {
|
||||||
|
|||||||
2
src/types/litegraph-augmentation.d.ts
vendored
2
src/types/litegraph-augmentation.d.ts
vendored
@@ -82,8 +82,6 @@ declare module '@comfyorg/litegraph' {
|
|||||||
convertToNodes?(): LGraphNode[]
|
convertToNodes?(): LGraphNode[]
|
||||||
recreate?(): Promise<LGraphNode>
|
recreate?(): Promise<LGraphNode>
|
||||||
refreshComboInNode?(defs: Record<string, ComfyNodeDef>)
|
refreshComboInNode?(defs: Record<string, ComfyNodeDef>)
|
||||||
/** Used by virtual nodes (primitives) to insert their values into the graph prior to queueing. */
|
|
||||||
applyToGraph?(extraLinks?: LLink[]): void
|
|
||||||
/** @deprecated groupNode */
|
/** @deprecated groupNode */
|
||||||
updateLink?(link: LLink): LLink | null
|
updateLink?(link: LLink): LLink | null
|
||||||
onExecutionStart?(): unknown
|
onExecutionStart?(): unknown
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import type { LGraph } from '@comfyorg/litegraph'
|
|||||||
import { LGraphEventMode } from '@comfyorg/litegraph'
|
import { LGraphEventMode } from '@comfyorg/litegraph'
|
||||||
|
|
||||||
import type { ComfyApiWorkflow, ComfyWorkflowJSON } from '@/types/comfyWorkflow'
|
import type { ComfyApiWorkflow, ComfyWorkflowJSON } from '@/types/comfyWorkflow'
|
||||||
|
import { isPrimitiveNode } from '@/utils/typeGuardUtil'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts the current graph workflow for sending to the API.
|
* Converts the current graph workflow for sending to the API.
|
||||||
@@ -17,8 +18,7 @@ export const graphToPrompt = async (
|
|||||||
for (const node of graph.computeExecutionOrder(false)) {
|
for (const node of graph.computeExecutionOrder(false)) {
|
||||||
const innerNodes = node.getInnerNodes ? node.getInnerNodes() : [node]
|
const innerNodes = node.getInnerNodes ? node.getInnerNodes() : [node]
|
||||||
for (const innerNode of innerNodes) {
|
for (const innerNode of innerNodes) {
|
||||||
// Don't serialize frontend only nodes but let them make changes
|
if (isPrimitiveNode(innerNode)) {
|
||||||
if (innerNode.isVirtualNode) {
|
|
||||||
innerNode.applyToGraph?.()
|
innerNode.applyToGraph?.()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
9
src/utils/typeGuardUtil.ts
Normal file
9
src/utils/typeGuardUtil.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { LGraphNode } from '@comfyorg/litegraph'
|
||||||
|
|
||||||
|
import type { PrimitiveNode } from '@/extensions/core/widgetInputs'
|
||||||
|
|
||||||
|
export function isPrimitiveNode(
|
||||||
|
node: LGraphNode
|
||||||
|
): node is PrimitiveNode & LGraphNode {
|
||||||
|
return node.type === 'PrimitiveNode'
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user