mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-23 07:50:15 +00:00
[Refactor] Move node composables to subfolder (#2712)
This commit is contained in:
31
src/composables/node/useNodePaste.ts
Normal file
31
src/composables/node/useNodePaste.ts
Normal 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user