mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-03 06:47:33 +00:00
- 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
30 lines
729 B
TypeScript
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
|
|
}
|
|
}
|