(item: DataTransferItem, editor: EditorWrapper, mouse?: [number, number], insertParentId?: bigint, insertIndex?: number)
| 82 | export type UploadResult<T> = { filename: string; type: string; content: T }; |
| 83 | |
| 84 | export async function pasteFile(item: DataTransferItem, editor: EditorWrapper, mouse?: [number, number], insertParentId?: bigint, insertIndex?: number) { |
| 85 | const file = item.getAsFile(); |
| 86 | if (!file) return; |
| 87 | |
| 88 | if (file.type.startsWith("image/svg")) { |
| 89 | const svg = await file.text(); |
| 90 | editor.pasteSvg(file.name, svg, mouse?.[0], mouse?.[1], insertParentId, insertIndex); |
| 91 | } else if (file.type.startsWith("image/")) { |
| 92 | const imageData = await extractPixelData(file); |
| 93 | editor.pasteImage(file.name, new Uint8Array(imageData.data), imageData.width, imageData.height, mouse?.[0], mouse?.[1], insertParentId, insertIndex); |
| 94 | } else if (file.name.endsWith("." + editor.fileExtension())) { |
| 95 | // TODO: When we eventually have sub-documents, this should be changed to import the document as a node instead of opening it in a separate tab |
| 96 | editor.openFile(file.name, await file.bytes()); |
| 97 | } |
| 98 | } |
no test coverage detected