Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/composables/node/useNodeImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const useNodePreview = <T extends MediaElement>(
/**
* Attaches a preview image to a node.
*/
export const useNodeImage = (node: LGraphNode) => {
export const useNodeImage = (node: LGraphNode, callback?: () => void) => {
node.previewMediaType = 'image'

const loadElement = (url: string): Promise<HTMLImageElement | null> =>
Expand All @@ -112,6 +112,7 @@ export const useNodeImage = (node: LGraphNode) => {
const onLoaded = (elements: HTMLImageElement[]) => {
node.imageIndex = null
node.imgs = elements
callback?.()
}

return useNodePreview(node, {
Expand All @@ -126,7 +127,7 @@ export const useNodeImage = (node: LGraphNode) => {
/**
* Attaches a preview video to a node.
*/
export const useNodeVideo = (node: LGraphNode) => {
export const useNodeVideo = (node: LGraphNode, callback?: () => void) => {
node.previewMediaType = 'video'
let minHeight = DEFAULT_VIDEO_SIZE
let minWidth = DEFAULT_VIDEO_SIZE
Expand Down Expand Up @@ -187,6 +188,7 @@ export const useNodeVideo = (node: LGraphNode) => {
}

node.videoContainer.replaceChildren(videoElement)
callback?.()
}

return useNodePreview(node, {
Expand Down
1 change: 0 additions & 1 deletion src/core/graph/subgraph/proxyWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ function addProxyWidget(
afterQueued: undefined,
computedHeight: undefined,
isProxyWidget: true,
label: name,
last_y: undefined,
name,
node: subgraphNode,
Expand Down
12 changes: 9 additions & 3 deletions src/core/graph/subgraph/proxyWidgetUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,15 @@ export function promoteRecommendedWidgets(subgraphNode: SubgraphNode) {
const interiorNodes = subgraphNode.subgraph.nodes
for (const node of interiorNodes) {
node.updateComputedDisabled()
//NOTE: Since this operation is async, previews still don't exist after the single frame
//Add an onLoad callback to updatePreviews?
updatePreviews(node)
function checkWidgets() {
updatePreviews(node)
const widget = node.widgets?.find((w) => w.name.startsWith('$$'))
if (!widget) return
const pw = getProxyWidgets(subgraphNode)
if (pw.some(matchesPropertyItem([node, widget]))) return
promoteWidget(node, widget, [subgraphNode])
}
requestAnimationFrame(() => updatePreviews(node, checkWidgets))
}
const filteredWidgets: WidgetItem[] = interiorNodes
.flatMap(nodeWidgets)
Expand Down
5 changes: 4 additions & 1 deletion src/core/schemas/proxyWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ export type ProxyWidgetsProperty = z.infer<typeof proxyWidgetsPropertySchema>
export function parseProxyWidgets(
property: NodeProperty | undefined
): ProxyWidgetsProperty {
const result = proxyWidgetsPropertySchema.safeParse(property)
if (typeof property === 'string') property = JSON.parse(property)
const result = proxyWidgetsPropertySchema.safeParse(
typeof property === 'string' ? JSON.parse(property) : property
)
if (result.success) return result.data

const error = fromZodError(result.error)
Expand Down
10 changes: 5 additions & 5 deletions src/services/litegraphService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -853,14 +853,14 @@ export const useLitegraphService = () => {
return []
}
}
function updatePreviews(node: LGraphNode) {
function updatePreviews(node: LGraphNode, callback?: () => void) {
try {
unsafeUpdatePreviews.call(node)
unsafeUpdatePreviews.call(node, callback)
} catch (error) {
console.error('Error drawing node background', error)
}
}
function unsafeUpdatePreviews(this: LGraphNode) {
function unsafeUpdatePreviews(this: LGraphNode, callback?: () => void) {
if (this.flags.collapsed) return

const nodeOutputStore = useNodeOutputStore()
Expand Down Expand Up @@ -891,9 +891,9 @@ export const useLitegraphService = () => {
(this.animatedImages && !isAnimatedWebp && !isAnimatedPng) ||
isVideoNode(this)
if (isVideo) {
useNodeVideo(this).showPreview()
useNodeVideo(this, callback).showPreview()
} else {
useNodeImage(this).showPreview()
useNodeImage(this, callback).showPreview()
}
}

Expand Down
Loading