mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-05-04 21:22:07 +00:00
Backport of #10165 to `core/1.42` Automatically created by backport workflow. ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-10199-backport-core-1-42-fix-track-nodePreviewImages-in-usePromotedPreviews-3266d73d3650813a9d41f7cb4330ba52) by [Unito](https://www.unito.io) Co-authored-by: Christian Byrne <cbyrne@comfy.org> Co-authored-by: GitHub Action <action@github.com>
50 lines
1.3 KiB
TypeScript
50 lines
1.3 KiB
TypeScript
import type { LGraphNode } from '@/lib/litegraph/src/litegraph'
|
|
import { useImagePreviewWidget } from '@/renderer/extensions/vueNodes/widgets/composables/useImagePreviewWidget'
|
|
|
|
import { CANVAS_IMAGE_PREVIEW_WIDGET } from '@/composables/node/canvasImagePreviewTypes'
|
|
|
|
/**
|
|
* Composable for handling canvas image previews in nodes
|
|
*/
|
|
export function useNodeCanvasImagePreview() {
|
|
const imagePreviewWidget = useImagePreviewWidget()
|
|
/**
|
|
* Shows canvas image preview for a node
|
|
* @param node The graph node to show the preview for
|
|
*/
|
|
function showCanvasImagePreview(node: LGraphNode) {
|
|
if (!node.imgs?.length) return
|
|
|
|
if (node.isSubgraphNode()) return
|
|
|
|
if (!node.widgets?.find((w) => w.name === CANVAS_IMAGE_PREVIEW_WIDGET)) {
|
|
imagePreviewWidget(node, {
|
|
type: 'IMAGE_PREVIEW',
|
|
name: CANVAS_IMAGE_PREVIEW_WIDGET
|
|
})
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Removes canvas image preview from a node
|
|
* @param node The graph node to remove the preview from
|
|
*/
|
|
function removeCanvasImagePreview(node: LGraphNode) {
|
|
if (!node.widgets) return
|
|
|
|
const widgetIdx = node.widgets.findIndex(
|
|
(w) => w.name === CANVAS_IMAGE_PREVIEW_WIDGET
|
|
)
|
|
|
|
if (widgetIdx > -1) {
|
|
node.widgets[widgetIdx].onRemove?.()
|
|
node.widgets.splice(widgetIdx, 1)
|
|
}
|
|
}
|
|
|
|
return {
|
|
showCanvasImagePreview,
|
|
removeCanvasImagePreview
|
|
}
|
|
}
|