Add drag-and-drop and copy-paste file importing/opening throughout the UI (#2012)

* Add file importing by dragging and dropping throughout the UI

* Disable comment-profiling-changes.yaml

* Fix CI
This commit is contained in:
Keavon Chambers
2024-09-28 00:19:43 -07:00
committed by GitHub
parent 20470b566b
commit 904cf09c79
35 changed files with 578 additions and 259 deletions
+3 -5
View File
@@ -92,11 +92,9 @@ export function createDocumentState(editor: Editor) {
});
editor.subscriptions.subscribeJsMessage(TriggerDelayedZoomCanvasToFitAll, () => {
// TODO: This is horribly hacky
setTimeout(() => editor.handle.zoomCanvasToFitAll(), 0);
setTimeout(() => editor.handle.zoomCanvasToFitAll(), 1);
setTimeout(() => editor.handle.zoomCanvasToFitAll(), 10);
setTimeout(() => editor.handle.zoomCanvasToFitAll(), 50);
setTimeout(() => editor.handle.zoomCanvasToFitAll(), 100);
[0, 1, 10, 50, 100, 200, 300, 400, 500].forEach((delay) => {
setTimeout(() => editor.handle.zoomCanvasToFitAll(), delay);
});
});
return {
+11 -6
View File
@@ -65,17 +65,22 @@ export function createPortfolioState(editor: Editor) {
editor.handle.openDocumentFile(data.filename, data.content);
});
editor.subscriptions.subscribeJsMessage(TriggerImport, async () => {
const data = await upload("image/*", "data");
const data = await upload("image/*", "both");
if (data.type.includes("svg")) {
const svg = new TextDecoder().decode(data.content);
editor.handle.pasteSvg(svg);
const svg = new TextDecoder().decode(data.content.data);
editor.handle.pasteSvg(data.filename, svg);
return;
}
const imageData = await extractPixelData(new Blob([data.content], { type: data.type }));
editor.handle.pasteImage(new Uint8Array(imageData.data), imageData.width, imageData.height);
// In case the user accidentally uploads a Graphite file, open it instead of failing to import it
if (data.filename.endsWith(".graphite")) {
editor.handle.openDocumentFile(data.filename, data.content.text);
return;
}
const imageData = await extractPixelData(new Blob([data.content.data], { type: data.type }));
editor.handle.pasteImage(data.filename, new Uint8Array(imageData.data), imageData.width, imageData.height);
});
editor.subscriptions.subscribeJsMessage(TriggerDownloadTextFile, (triggerFileDownload) => {
downloadFileText(triggerFileDownload.name, triggerFileDownload.document);