[Refactor] Move node composables to subfolder (#2712)

This commit is contained in:
bymyself
2025-02-24 12:04:16 -07:00
committed by GitHub
parent 9cb993cd3d
commit d340e634a8
8 changed files with 8 additions and 8 deletions

View File

@@ -0,0 +1,31 @@
import type { LGraphNode } from '@comfyorg/litegraph'
type PasteHandler<T> = (files: File[]) => Promise<T>
interface NodePasteOptions<T> {
onPaste: PasteHandler<T>
fileFilter?: (file: File) => boolean
allow_batch?: boolean
}
/**
* Adds paste handling to a node
*/
export const useNodePaste = <T>(
node: LGraphNode,
options: NodePasteOptions<T>
) => {
const { onPaste, fileFilter = () => true, allow_batch = false } = options
node.pasteFiles = function (files: File[]) {
const filteredFiles = Array.from(files).filter(fileFilter)
if (!filteredFiles.length) return false
const paste = allow_batch ? filteredFiles : filteredFiles.slice(0, 1)
onPaste(paste).then((result) => {
if (!result) return
})
return true
}
}