Files
ComfyUI_frontend/src/composables/node/useNodePaste.ts
Benjamin Lu fef02e5f56 [refactor] Migrate litegraph imports from npm package to local subtree
- Updated all imports from '@comfyorg/litegraph' to '@/lib/litegraph/src/'
- Replaced deep dist imports with direct source paths
- Updated CSS import in main.ts
- All imports now use the @ alias consistently
2025-08-03 22:06:29 -04:00

30 lines
729 B
TypeScript

import type { LGraphNode } from '@/lib/litegraph/src/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)
void onPaste(paste)
return true
}
}