mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-30 11:11:53 +00:00
[Refactor] Use more explicit types in usePaste (#2721)
This commit is contained in:
@@ -32,20 +32,19 @@ export const usePaste = () => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
useEventListener(document, 'paste', async (e: ClipboardEvent) => {
|
useEventListener(document, 'paste', async (e) => {
|
||||||
// ctrl+shift+v is used to paste nodes with connections
|
// ctrl+shift+v is used to paste nodes with connections
|
||||||
// this is handled by litegraph
|
// this is handled by litegraph
|
||||||
if (workspaceStore.shiftDown) return
|
if (workspaceStore.shiftDown) return
|
||||||
|
|
||||||
const canvas = canvasStore.canvas
|
const { canvas } = canvasStore
|
||||||
if (!canvas) return
|
if (!canvas) return
|
||||||
|
|
||||||
const graph = canvas.graph
|
const { graph } = canvas
|
||||||
// @ts-expect-error: Property 'clipboardData' does not exist on type 'Window & typeof globalThis'.
|
let data: DataTransfer | string | null = e.clipboardData
|
||||||
// Did you mean 'Clipboard'?ts(2551)
|
if (!data) throw new Error('No clipboard data on clipboard event')
|
||||||
// TODO: Not sure what the code wants to do.
|
|
||||||
let data = e.clipboardData || window.clipboardData
|
const { items } = data
|
||||||
const items: DataTransferItemList = data.items
|
|
||||||
|
|
||||||
const currentNode = canvas.current_node as LGraphNode
|
const currentNode = canvas.current_node as LGraphNode
|
||||||
const isNodeSelected = currentNode?.is_selected
|
const isNodeSelected = currentNode?.is_selected
|
||||||
@@ -66,9 +65,8 @@ export const usePaste = () => {
|
|||||||
if (!imageNode) {
|
if (!imageNode) {
|
||||||
// No image node selected: add a new one
|
// No image node selected: add a new one
|
||||||
const newNode = LiteGraph.createNode('LoadImage')
|
const newNode = LiteGraph.createNode('LoadImage')
|
||||||
// @ts-expect-error array to Float32Array
|
newNode.pos = [canvas.graph_mouse[0], canvas.graph_mouse[1]]
|
||||||
newNode.pos = [...canvas.graph_mouse]
|
if (newNode) imageNode = graph?.add(newNode) ?? null
|
||||||
imageNode = graph?.add(newNode) ?? null
|
|
||||||
graph?.change()
|
graph?.change()
|
||||||
}
|
}
|
||||||
pasteItemOnNode(items, imageNode)
|
pasteItemOnNode(items, imageNode)
|
||||||
@@ -85,9 +83,8 @@ export const usePaste = () => {
|
|||||||
if (!audioNode) {
|
if (!audioNode) {
|
||||||
// No audio node selected: add a new one
|
// No audio node selected: add a new one
|
||||||
const newNode = LiteGraph.createNode('LoadAudio')
|
const newNode = LiteGraph.createNode('LoadAudio')
|
||||||
// @ts-expect-error array to Float32Array
|
newNode.pos = [canvas.graph_mouse[0], canvas.graph_mouse[1]]
|
||||||
newNode.pos = [...canvas.graph_mouse]
|
if (newNode) audioNode = graph?.add(newNode) ?? null
|
||||||
audioNode = graph?.add(newNode) ?? null
|
|
||||||
graph?.change()
|
graph?.change()
|
||||||
}
|
}
|
||||||
pasteItemOnNode(items, audioNode)
|
pasteItemOnNode(items, audioNode)
|
||||||
|
|||||||
Reference in New Issue
Block a user