Skip to content

Commit 6491db6

Browse files
authored
Further subgraph improvements (#6466)
- Prune disconnected widgets on config panel open - Fix breakage of DOMWidgets on double nest - Fix self clipping of proxied DOMWidget nodes - Blacklist cloning of promtoed widget prop ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-6466-Further-subgraph-improvements-29c6d73d365081c8b63dda068486805c) by [Unito](https://www.unito.io)
1 parent 041ce2d commit 6491db6

File tree

6 files changed

+22
-4
lines changed

6 files changed

+22
-4
lines changed

src/components/graph/widgets/DomWidget.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ onMounted(() => {
143143
widget.options.selectOn ?? ['focus', 'click'],
144144
() => {
145145
const lgCanvas = canvasStore.canvas
146-
lgCanvas?.selectNode(widget.node)
147-
lgCanvas?.bringToFront(widget.node)
146+
lgCanvas?.selectNode(widgetState.widget.node)
147+
lgCanvas?.bringToFront(widgetState.widget.node)
148148
}
149149
)
150150
})

src/core/graph/subgraph/SubgraphNode.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
matchesPropertyItem,
1818
matchesWidgetItem,
1919
promoteWidget,
20+
pruneDisconnected,
2021
widgetItemToProperty
2122
} from '@/core/graph/subgraph/proxyWidgetUtils'
2223
import type { WidgetItem } from '@/core/graph/subgraph/proxyWidgetUtils'
@@ -235,6 +236,7 @@ watchDebounced(
235236
)
236237
onMounted(() => {
237238
setDraggableState()
239+
if (activeNode.value) pruneDisconnected(activeNode.value)
238240
})
239241
onBeforeUnmount(() => {
240242
draggableList.value?.dispose()

src/core/graph/subgraph/proxyWidget.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,12 @@ type Overlay = Partial<IBaseWidget> & {
4848
* on the linked widget
4949
*/
5050
type ProxyWidget = IBaseWidget & { _overlay: Overlay }
51-
function isProxyWidget(w: IBaseWidget): w is ProxyWidget {
51+
export function isProxyWidget(w: IBaseWidget): w is ProxyWidget {
5252
return (w as { _overlay?: Overlay })?._overlay?.isProxyWidget ?? false
5353
}
54+
export function isDisconnectedWidget(w: ProxyWidget) {
55+
return w instanceof disconnectedWidget.constructor
56+
}
5457

5558
export function registerProxyWidgets(canvas: LGraphCanvas) {
5659
//NOTE: canvasStore hasn't been initialized yet
@@ -167,7 +170,7 @@ function resolveLinkedWidget(
167170
if (!n) return [undefined, undefined]
168171
const widget = n.widgets?.find((w: IBaseWidget) => w.name === widgetName)
169172
//Slightly hacky. Force recursive resolution of nested widgets
170-
if (widget instanceof disconnectedWidget.constructor && isProxyWidget(widget))
173+
if (widget && isProxyWidget(widget) && isDisconnectedWidget(widget))
171174
widget.computedHeight = 20
172175
return [n, widget]
173176
}

src/core/graph/subgraph/proxyWidgetUtils.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { parseProxyWidgets } from '@/core/schemas/proxyWidget'
22
import type { ProxyWidgetsProperty } from '@/core/schemas/proxyWidget'
3+
import {
4+
isProxyWidget,
5+
isDisconnectedWidget
6+
} from '@/core/graph/subgraph/proxyWidget'
37
import { t } from '@/i18n'
48
import type {
59
IContextMenuValue,
@@ -163,3 +167,10 @@ export function promoteRecommendedWidgets(subgraphNode: SubgraphNode) {
163167
subgraphNode.properties.proxyWidgets = proxyWidgets
164168
subgraphNode.computeSize(subgraphNode.size)
165169
}
170+
171+
export function pruneDisconnected(subgraphNode: SubgraphNode) {
172+
subgraphNode.properties.proxyWidgets = subgraphNode.widgets
173+
.filter(isProxyWidget)
174+
.filter((w) => !isDisconnectedWidget(w))
175+
.map((w) => [w._overlay.nodeId, w._overlay.widgetName])
176+
}

src/lib/litegraph/src/subgraph/SubgraphNode.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@ export class SubgraphNode extends LGraphNode implements BaseLGraph {
546546

547547
// Clean up all promoted widgets
548548
for (const widget of this.widgets) {
549+
if ('isProxyWidget' in widget && widget.isProxyWidget) continue
549550
this.subgraph.events.dispatch('widget-demoted', {
550551
widget,
551552
subgraphNode: this

src/lib/litegraph/src/widgets/BaseWidget.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ export abstract class BaseWidget<TWidget extends IBaseWidget = IBaseWidget>
140140
displayValue,
141141
// @ts-expect-error Prevent naming conflicts with custom nodes.
142142
labelBaseline,
143+
promoted,
143144
...safeValues
144145
} = widget
145146

0 commit comments

Comments
 (0)