Skip to content

Commit d607f6c

Browse files
authored
Revert "Add support for LiteGraph to convert to classes (#334)" (#386)
This reverts commit e2141a8.
1 parent d9df032 commit d607f6c

File tree

7 files changed

+37
-49
lines changed

7 files changed

+37
-49
lines changed

src/extensions/core/contextMenuFilter.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ const ext = {
88
init() {
99
const ctxMenu = LiteGraph.ContextMenu
1010
// @ts-expect-error
11-
// TODO Very hacky way to modify Litegraph behaviour. Fix ctx later.
11+
// TODO Very hacky way to modify Litegraph behaviour. Fix this later.
1212
LiteGraph.ContextMenu = function (values, options) {
13-
const ctx = new ctxMenu(values, options)
13+
const ctx = ctxMenu.call(this, values, options)
1414

1515
// If we are a dark menu (only used for combo boxes) then add a filter input
16-
if (options?.className === 'dark' && values?.length > 4) {
16+
if (options?.className === 'dark' && values?.length > 10) {
1717
const filter = document.createElement('input')
1818
filter.classList.add('comfy-context-menu-filter')
1919
filter.placeholder = 'Filter list'
20-
ctx.root.prepend(filter)
20+
this.root.prepend(filter)
2121

2222
const items = Array.from(
23-
ctx.root.querySelectorAll('.litemenu-entry')
23+
this.root.querySelectorAll('.litemenu-entry')
2424
) as HTMLElement[]
2525
let displayedItems = [...items]
2626
let itemCount = displayedItems.length
@@ -61,16 +61,16 @@ const ext = {
6161
}
6262

6363
const positionList = () => {
64-
const rect = ctx.root.getBoundingClientRect()
64+
const rect = this.root.getBoundingClientRect()
6565

6666
// If the top is off-screen then shift the element with scaling applied
6767
if (rect.top < 0) {
6868
const scale =
6969
1 -
70-
ctx.root.getBoundingClientRect().height /
71-
ctx.root.clientHeight
72-
const shift = (ctx.root.clientHeight * scale) / 2
73-
ctx.root.style.top = -shift + 'px'
70+
this.root.getBoundingClientRect().height /
71+
this.root.clientHeight
72+
const shift = (this.root.clientHeight * scale) / 2
73+
this.root.style.top = -shift + 'px'
7474
}
7575
}
7676

@@ -109,7 +109,7 @@ const ext = {
109109
selectedItem?.click()
110110
break
111111
case 'Escape':
112-
ctx.close()
112+
this.close()
113113
break
114114
}
115115
})
@@ -140,15 +140,15 @@ const ext = {
140140
let top = options.event.clientY - 10
141141

142142
const bodyRect = document.body.getBoundingClientRect()
143-
const rootRect = ctx.root.getBoundingClientRect()
143+
const rootRect = this.root.getBoundingClientRect()
144144
if (
145145
bodyRect.height &&
146146
top > bodyRect.height - rootRect.height - 10
147147
) {
148148
top = Math.max(0, bodyRect.height - rootRect.height - 10)
149149
}
150150

151-
ctx.root.style.top = top + 'px'
151+
this.root.style.top = top + 'px'
152152
positionList()
153153
}
154154
})

src/extensions/core/noteNode.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
import { LiteGraph, LGraphCanvas } from '@comfyorg/litegraph'
22
import { app } from '../../scripts/app'
33
import { ComfyWidgets } from '../../scripts/widgets'
4-
import { LGraphNode } from '@comfyorg/litegraph'
54
// Node that add notes to your project
65

76
app.registerExtension({
87
name: 'Comfy.NoteNode',
98
registerCustomNodes() {
10-
class NoteNode extends LGraphNode {
9+
class NoteNode {
1110
static category: string
1211

1312
color = LGraphCanvas.node_colors.yellow.color
1413
bgcolor = LGraphCanvas.node_colors.yellow.bgcolor
1514
groupcolor = LGraphCanvas.node_colors.yellow.groupcolor
15+
properties: { text: string }
16+
serialize_widgets: boolean
1617
isVirtualNode: boolean
1718
collapsable: boolean
1819
title_mode: number
1920

20-
constructor(title?: string) {
21-
super(title)
21+
constructor() {
2222
if (!this.properties) {
2323
this.properties = { text: '' }
2424
}
2525
ComfyWidgets.STRING(
26-
// Should we extends LGraphNode? Yesss
26+
// @ts-expect-error
27+
// Should we extends LGraphNode?
2728
this,
2829
'',
29-
// @ts-expect-error
3030
['', { default: this.properties.text, multiline: true }],
3131
app
3232
)
@@ -40,6 +40,7 @@ app.registerExtension({
4040

4141
LiteGraph.registerNodeType(
4242
'Note',
43+
// @ts-expect-error
4344
Object.assign(NoteNode, {
4445
title_mode: LiteGraph.NORMAL_TITLE,
4546
title: 'Note',

src/extensions/core/rerouteNode.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@ app.registerExtension({
1111
__outputType?: string
1212
}
1313

14-
class RerouteNode extends LGraphNode {
14+
class RerouteNode {
1515
static category: string | undefined
1616
static defaultVisibility = false
1717

18-
constructor(title?: string) {
19-
super(title)
18+
constructor() {
2019
if (!this.properties) {
2120
this.properties = {}
2221
}

src/extensions/core/widgetInputs.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { ComfyWidgets, addValueControlWidgets } from '../../scripts/widgets'
22
import { app } from '../../scripts/app'
33
import { applyTextReplacements } from '../../scripts/utils'
4-
import { LiteGraph, LGraphNode } from '@comfyorg/litegraph'
5-
import type { INodeInputSlot, IWidget } from '@comfyorg/litegraph'
4+
import { LiteGraph } from '@comfyorg/litegraph'
5+
import type { LGraphNode, INodeInputSlot, IWidget } from '@comfyorg/litegraph'
66

77
const CONVERTED_TYPE = 'converted-widget'
88
const VALID_TYPES = ['STRING', 'combo', 'number', 'toggle', 'BOOLEAN']
@@ -13,12 +13,11 @@ const TARGET = Symbol() // Used for reroutes to specify the real target widget
1313
interface PrimitiveNode extends LGraphNode {}
1414

1515
const replacePropertyName = 'Run widget replace on values'
16-
class PrimitiveNode extends LGraphNode {
16+
class PrimitiveNode {
1717
controlValues: any[]
1818
lastType: string
1919
static category: string
20-
constructor(title?: string) {
21-
super(title)
20+
constructor() {
2221
this.addOutput('connect to widget input', '*')
2322
this.serialize_widgets = true
2423
this.isVirtualNode = true

src/scripts/app.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,15 +1986,8 @@ export class ComfyApp {
19861986

19871987
async registerNodeDef(nodeId: string, nodeData: ComfyNodeDef) {
19881988
const self = this
1989-
const node = class ComfyNode extends LGraphNode {
1990-
static comfyClass? = nodeData.name
1991-
// TODO: change to "title?" once litegraph.d.ts has been updated
1992-
static title = nodeData.display_name || nodeData.name
1993-
static nodeData? = nodeData
1994-
static category?: string
1995-
1996-
constructor(title?: string) {
1997-
super(title)
1989+
const node = Object.assign(
1990+
function ComfyNode() {
19981991
var inputs = nodeData['input']['required']
19991992
if (nodeData['input']['optional'] != undefined) {
20001993
inputs = Object.assign(
@@ -2060,17 +2053,23 @@ export class ComfyApp {
20602053
this.serialize_widgets = true
20612054

20622055
app.#invokeExtensionsAsync('nodeCreated', this)
2056+
},
2057+
{
2058+
title: nodeData.display_name || nodeData.name,
2059+
comfyClass: nodeData.name,
2060+
nodeData
20632061
}
2064-
}
2065-
// @ts-expect-error
2062+
)
20662063
node.prototype.comfyClass = nodeData.name
20672064

20682065
this.#addNodeContextMenuHandler(node)
20692066
this.#addDrawBackgroundHandler(node)
20702067
this.#addNodeKeyHandler(node)
20712068

20722069
await this.#invokeExtensionsAsync('beforeRegisterNodeDef', node, nodeData)
2070+
// @ts-expect-error
20732071
LiteGraph.registerNodeType(nodeId, node)
2072+
// @ts-expect-error
20742073
node.category = nodeData.category
20752074
}
20762075

src/scripts/domWidget.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ export function addDomClippingSetting(): void {
254254
})
255255
}
256256

257+
//@ts-ignore
257258
LGraphNode.prototype.addDOMWidget = function (
258259
name: string,
259260
type: string,

src/types/litegraph-augmentation.d.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@ declare module '@comfyorg/litegraph' {
1414
* If the node is a frontend only node and should not be serialized into the prompt.
1515
*/
1616
isVirtualNode?: boolean
17-
18-
addDOMWidget(
19-
name: string,
20-
type: string,
21-
element: HTMLElement,
22-
options: Record<string, any>
23-
): DOMWidget
2417
}
2518

2619
interface IWidget<TValue = any, TOptions = any> {
@@ -74,8 +67,4 @@ declare module '@comfyorg/litegraph' {
7467
slotPos: Vector2
7568
): number
7669
}
77-
78-
interface ContextMenu {
79-
root?: HTMLDivElement
80-
}
8170
}

0 commit comments

Comments
 (0)