mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-01-30 21:09:53 +00:00
## Summary Indicate to the user that we're hard at work parsing their JSON behind the scenes. ## Changes - **What**: Turn on the loading spinner while processing a workflow - **What else**: Refactored the code around figuring out how to grab the data from the file to make this easier ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-6464-WIP-Loading-state-for-dropped-workflows-29c6d73d3650812dba66f2a7d27a777c) by [Unito](https://www.unito.io) --------- Co-authored-by: GitHub Action <action@github.com>
28 lines
796 B
TypeScript
28 lines
796 B
TypeScript
export async function extractFileFromDragEvent(
|
|
event: DragEvent
|
|
): Promise<File | undefined> {
|
|
if (!event.dataTransfer) return
|
|
|
|
// Dragging from Chrome->Firefox there is a file but its a bmp, so ignore that
|
|
if (
|
|
event.dataTransfer.files.length &&
|
|
event.dataTransfer.files[0].type !== 'image/bmp'
|
|
) {
|
|
return event.dataTransfer.files[0]
|
|
}
|
|
|
|
// Try loading the first URI in the transfer list
|
|
const validTypes = ['text/uri-list', 'text/x-moz-url']
|
|
const match = [...event.dataTransfer.types].find((t) =>
|
|
validTypes.includes(t)
|
|
)
|
|
if (!match) return
|
|
|
|
const uri = event.dataTransfer.getData(match)?.split('\n')?.[0]
|
|
if (!uri) return
|
|
|
|
const response = await fetch(uri)
|
|
const blob = await response.blob()
|
|
return new File([blob], uri, { type: blob.type })
|
|
}
|