File tree Expand file tree Collapse file tree 5 files changed +22
-12
lines changed Expand file tree Collapse file tree 5 files changed +22
-12
lines changed Original file line number Diff line number Diff line change @@ -98,7 +98,7 @@ const useNodePreview = <T extends MediaElement>(
98
98
/**
99
99
* Attaches a preview image to a node.
100
100
*/
101
- export const useNodeImage = ( node : LGraphNode ) => {
101
+ export const useNodeImage = ( node : LGraphNode , callback ?: ( ) => void ) => {
102
102
node . previewMediaType = 'image'
103
103
104
104
const loadElement = ( url : string ) : Promise < HTMLImageElement | null > =>
@@ -112,6 +112,7 @@ export const useNodeImage = (node: LGraphNode) => {
112
112
const onLoaded = ( elements : HTMLImageElement [ ] ) => {
113
113
node . imageIndex = null
114
114
node . imgs = elements
115
+ callback ?.( )
115
116
}
116
117
117
118
return useNodePreview ( node , {
@@ -126,7 +127,7 @@ export const useNodeImage = (node: LGraphNode) => {
126
127
/**
127
128
* Attaches a preview video to a node.
128
129
*/
129
- export const useNodeVideo = ( node : LGraphNode ) => {
130
+ export const useNodeVideo = ( node : LGraphNode , callback ?: ( ) => void ) => {
130
131
node . previewMediaType = 'video'
131
132
let minHeight = DEFAULT_VIDEO_SIZE
132
133
let minWidth = DEFAULT_VIDEO_SIZE
@@ -187,6 +188,7 @@ export const useNodeVideo = (node: LGraphNode) => {
187
188
}
188
189
189
190
node . videoContainer . replaceChildren ( videoElement )
191
+ callback ?.( )
190
192
}
191
193
192
194
return useNodePreview ( node , {
Original file line number Diff line number Diff line change @@ -121,7 +121,6 @@ function addProxyWidget(
121
121
afterQueued : undefined ,
122
122
computedHeight : undefined ,
123
123
isProxyWidget : true ,
124
- label : name ,
125
124
last_y : undefined ,
126
125
name,
127
126
node : subgraphNode ,
Original file line number Diff line number Diff line change @@ -119,9 +119,15 @@ export function promoteRecommendedWidgets(subgraphNode: SubgraphNode) {
119
119
const interiorNodes = subgraphNode . subgraph . nodes
120
120
for ( const node of interiorNodes ) {
121
121
node . updateComputedDisabled ( )
122
- //NOTE: Since this operation is async, previews still don't exist after the single frame
123
- //Add an onLoad callback to updatePreviews?
124
- updatePreviews ( node )
122
+ function checkWidgets ( ) {
123
+ updatePreviews ( node )
124
+ const widget = node . widgets ?. find ( ( w ) => w . name . startsWith ( '$$' ) )
125
+ if ( ! widget ) return
126
+ const pw = getProxyWidgets ( subgraphNode )
127
+ if ( pw . some ( matchesPropertyItem ( [ node , widget ] ) ) ) return
128
+ promoteWidget ( node , widget , [ subgraphNode ] )
129
+ }
130
+ requestAnimationFrame ( ( ) => updatePreviews ( node , checkWidgets ) )
125
131
}
126
132
const filteredWidgets : WidgetItem [ ] = interiorNodes
127
133
. flatMap ( nodeWidgets )
Original file line number Diff line number Diff line change @@ -9,7 +9,10 @@ export type ProxyWidgetsProperty = z.infer<typeof proxyWidgetsPropertySchema>
9
9
export function parseProxyWidgets (
10
10
property : NodeProperty | undefined
11
11
) : ProxyWidgetsProperty {
12
- const result = proxyWidgetsPropertySchema . safeParse ( property )
12
+ if ( typeof property === 'string' ) property = JSON . parse ( property )
13
+ const result = proxyWidgetsPropertySchema . safeParse (
14
+ typeof property === 'string' ? JSON . parse ( property ) : property
15
+ )
13
16
if ( result . success ) return result . data
14
17
15
18
const error = fromZodError ( result . error )
Original file line number Diff line number Diff line change @@ -853,14 +853,14 @@ export const useLitegraphService = () => {
853
853
return [ ]
854
854
}
855
855
}
856
- function updatePreviews ( node : LGraphNode ) {
856
+ function updatePreviews ( node : LGraphNode , callback ?: ( ) => void ) {
857
857
try {
858
- unsafeUpdatePreviews . call ( node )
858
+ unsafeUpdatePreviews . call ( node , callback )
859
859
} catch ( error ) {
860
860
console . error ( 'Error drawing node background' , error )
861
861
}
862
862
}
863
- function unsafeUpdatePreviews ( this : LGraphNode ) {
863
+ function unsafeUpdatePreviews ( this : LGraphNode , callback ?: ( ) => void ) {
864
864
if ( this . flags . collapsed ) return
865
865
866
866
const nodeOutputStore = useNodeOutputStore ( )
@@ -891,9 +891,9 @@ export const useLitegraphService = () => {
891
891
( this . animatedImages && ! isAnimatedWebp && ! isAnimatedPng ) ||
892
892
isVideoNode ( this )
893
893
if ( isVideo ) {
894
- useNodeVideo ( this ) . showPreview ( )
894
+ useNodeVideo ( this , callback ) . showPreview ( )
895
895
} else {
896
- useNodeImage ( this ) . showPreview ( )
896
+ useNodeImage ( this , callback ) . showPreview ( )
897
897
}
898
898
}
899
899
You can’t perform that action at this time.
0 commit comments