MCPcopy Create free account
hub / github.com/GraphiteEditor/Graphite / pasteFile

Function pasteFile

frontend/src/utility-functions/files.ts:84–98  ·  view source on GitHub ↗
(item: DataTransferItem, editor: EditorWrapper, mouse?: [number, number], insertParentId?: bigint, insertIndex?: number)

Source from the content-addressed store, hash-verified

82export type UploadResult<T> = { filename: string; type: string; content: T };
83
84export 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}

Callers 1

onPasteFunction · 0.90

Calls 2

extractPixelDataFunction · 0.90
textMethod · 0.45

Tested by

no test coverage detected