Update litegraph (Getters) (#829)

* Update litegraph (Getters)

* Update
This commit is contained in:
Chenlei Hu
2024-09-14 17:10:57 +09:00
committed by GitHub
parent 588cfeca4b
commit 12c699cc87
16 changed files with 36 additions and 50 deletions

View File

@@ -17,8 +17,7 @@ const Workflow = {
const id = `workflow/${name}`
// Check if lready registered/in use in this workflow
if (app.graph.extra?.groupNodes?.[name]) {
// @ts-expect-error
if (app.graph._nodes.find((n) => n.type === id)) {
if (app.graph.nodes.find((n) => n.type === id)) {
return Workflow.InUse.InWorkflow
} else {
return Workflow.InUse.Registered

View File

@@ -388,8 +388,7 @@ export class ManageGroupDialog extends ComfyDialog<HTMLDialogElement> {
'button.comfy-btn',
{
onclick: (e) => {
// @ts-expect-error
const node = app.graph._nodes.find(
const node = app.graph.nodes.find(
(n) => n.type === 'workflow/' + this.selectedGroup
)
if (node) {
@@ -470,8 +469,7 @@ export class ManageGroupDialog extends ComfyDialog<HTMLDialogElement> {
types[g] = type
if (!nodesByType) {
// @ts-expect-error
nodesByType = app.graph._nodes.reduce((p, n) => {
nodesByType = app.graph.nodes.reduce((p, n) => {
p[n.type] ??= []
p[n.type].push(n)
return p

View File

@@ -15,7 +15,7 @@ function addNodesToGroup(group, nodes = []) {
x1 = y1 = x2 = y2 = -1
nx1 = ny1 = nx2 = ny2 = -1
for (var n of [group._nodes, nodes]) {
for (var n of [group.nodes, nodes]) {
for (var i in n) {
node = n[i]
@@ -90,7 +90,7 @@ app.registerExtension({
// Group nodes aren't recomputed until the group is moved, this ensures the nodes are up-to-date
group.recomputeInsideNodes()
const nodesInGroup = group._nodes
const nodesInGroup = group.nodes
options.push({
content: 'Add Selected Nodes To Group',

View File

@@ -137,7 +137,7 @@ app.registerExtension({
// After moving a group (while app.shiftDown), snap all the child nodes and, finally,
// align the group itself.
this.recomputeInsideNodes()
for (const node of this._nodes) {
for (const node of this.nodes) {
node.alignToGrid()
}
LGraphNode.prototype.alignToGrid.apply(this)
@@ -178,8 +178,7 @@ app.registerExtension({
LGraphCanvas.onGroupAdd = function () {
const v = onGroupAdd.apply(app.canvas, arguments)
if (app.shiftDown) {
// @ts-expect-error
const lastGroup = app.graph._groups[app.graph._groups.length - 1]
const lastGroup = app.graph.groups[app.graph.groups.length - 1]
if (lastGroup) {
roundVectorToGrid(lastGroup.pos)
roundVectorToGrid(lastGroup.size)

View File

@@ -827,8 +827,7 @@ app.registerExtension({
}
function isNodeAtPos(pos) {
// @ts-expect-error Fix litegraph types
for (const n of app.graph._nodes) {
for (const n of app.graph.nodes) {
if (n.pos[0] === pos[0] && n.pos[1] === pos[1]) {
return true
}

View File

@@ -1396,7 +1396,7 @@ export class ComfyApp {
return
}
var groups = this.graph._groups
var groups = this.graph.groups
ctx.save()
ctx.globalAlpha = 0.7 * this.editor_alpha
@@ -1632,8 +1632,7 @@ export class ComfyApp {
api.addEventListener('execution_start', ({ detail }) => {
this.lastExecutionError = null
// @ts-expect-error
this.graph._nodes.forEach((node) => {
this.graph.nodes.forEach((node) => {
// @ts-expect-error
if (node.onExecutionStart)
// @ts-expect-error
@@ -1690,8 +1689,7 @@ export class ComfyApp {
// @ts-expect-error
app.graph.onConfigure = function () {
// Fire callbacks before the onConfigure, this is used by widget inputs to setup the config
// @ts-expect-error
for (const node of app.graph._nodes) {
for (const node of app.graph.nodes) {
// @ts-expect-error
node.onGraphConfigured?.()
}
@@ -1699,8 +1697,7 @@ export class ComfyApp {
const r = onConfigure?.apply(this, arguments)
// Fire after onConfigure, used by primitives to generate widget using input nodes config
// @ts-expect-error _nodes is private.
for (const node of app.graph._nodes) {
for (const node of app.graph.nodes) {
node.onAfterGraphConfigured?.()
}
@@ -2334,8 +2331,7 @@ export class ComfyApp {
return
}
// @ts-expect-error
for (const node of this.graph._nodes) {
for (const node of this.graph.nodes) {
const size = node.computeSize()
size[0] = Math.max(node.size[0], size[0])
size[1] = Math.max(node.size[1], size[1])
@@ -2893,10 +2889,8 @@ export class ComfyApp {
for (const nodeId in defs) {
this.registerNodeDef(nodeId, defs[nodeId])
}
// @ts-expect-error
for (let nodeNum in this.graph._nodes) {
// @ts-expect-error
const node = this.graph._nodes[nodeNum]
for (let nodeNum in this.graph.nodes) {
const node = this.graph.nodes[nodeNum]
const def = defs[node.type]
// @ts-expect-error
// Allow primitive nodes to handle refresh

View File

@@ -224,8 +224,8 @@ const computeVisibleNodes = LGraphCanvas.prototype.computeVisibleNodes
//@ts-ignore
LGraphCanvas.prototype.computeVisibleNodes = function (): LGraphNode[] {
const visibleNodes = computeVisibleNodes.apply(this, arguments)
// @ts-expect-error
for (const node of app.graph._nodes) {
for (const node of app.graph.nodes) {
if (elementWidgets.has(node)) {
const hidden = visibleNodes.indexOf(node) === -1
for (const w of node.widgets) {
@@ -354,8 +354,7 @@ LGraphNode.prototype.addDOMWidget = function (
width: `${widgetWidth - margin * 2}px`,
height: `${(widget.computedHeight ?? 50) - margin * 2}px`,
position: 'absolute',
// @ts-expect-error
zIndex: app.graph._nodes.indexOf(node)
zIndex: app.graph.nodes.indexOf(node)
})
if (enableDomClipping) {

View File

@@ -56,14 +56,12 @@ export function applyTextReplacements(app: ComfyApp, value: string): string {
}
// Find node with matching S&R property name
// @ts-expect-error
let nodes = app.graph._nodes.filter(
let nodes = app.graph.nodes.filter(
(n) => n.properties?.['Node name for S&R'] === split[0]
)
// If we cant, see if there is a node with that title
if (!nodes.length) {
// @ts-expect-error
nodes = app.graph._nodes.filter((n) => n.title === split[0])
nodes = app.graph.nodes.filter((n) => n.title === split[0])
}
if (!nodes.length) {
console.warn('Unable to find node', split[0])

View File

@@ -361,7 +361,7 @@ export function initWidgets(app) {
options: ['before', 'after'],
onChange(value) {
controlValueRunBefore = value === 'before'
for (const n of app.graph._nodes) {
for (const n of app.graph.nodes) {
if (!n.widgets) continue
for (const w of n.widgets) {
if (w[IS_CONTROL_WIDGET]) {