mirror of
https://github.com/MultiMote/niimblue
synced 2026-01-19 19:37:11 +03:00
Fix image file drop
This commit is contained in:
6
package-lock.json
generated
6
package-lock.json
generated
@@ -3054,9 +3054,9 @@
|
||||
"optional": true
|
||||
},
|
||||
"node_modules/vite": {
|
||||
"version": "5.4.19",
|
||||
"resolved": "https://registry.npmjs.org/vite/-/vite-5.4.19.tgz",
|
||||
"integrity": "sha512-qO3aKv3HoQC8QKiNSTuUM1l9o/XX3+c+VTgLHbJWHZGeTPVAg2XwazI9UWzoxjIJCGCV2zU60uqMzjeLZuULqA==",
|
||||
"version": "5.4.20",
|
||||
"resolved": "https://registry.npmjs.org/vite/-/vite-5.4.20.tgz",
|
||||
"integrity": "sha512-j3lYzGC3P+B5Yfy/pfKNgVEg4+UtcIJcVRt2cDjIOmhLourAqPqf8P7acgxeiSgUB7E3p2P8/3gNIgDLpwzs4g==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
|
||||
@@ -324,15 +324,28 @@
|
||||
selectedCount = 0;
|
||||
});
|
||||
|
||||
fabricCanvas.on("drop", (e): void => {
|
||||
fabricCanvas.on("dragover", (e): void => {
|
||||
e.e.preventDefault();
|
||||
});
|
||||
|
||||
fabricCanvas.on("drop:after", async (e): Promise<void> => {
|
||||
const dragEvt = e.e as DragEvent;
|
||||
dragEvt.preventDefault();
|
||||
|
||||
let dropped = false;
|
||||
|
||||
if (dragEvt.dataTransfer?.files) {
|
||||
[...dragEvt.dataTransfer.files].forEach((file: File) => {
|
||||
LabelDesignerObjectHelper.addImageFile(fabricCanvas, file);
|
||||
for (const file of dragEvt.dataTransfer.files) {
|
||||
try {
|
||||
await LabelDesignerObjectHelper.addImageFile(fabricCanvas, file).catch();
|
||||
} catch (e) {
|
||||
Toasts.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
if (dropped) {
|
||||
undo.push(fabricCanvas, labelProps);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import { OBJECT_DEFAULTS, OBJECT_DEFAULTS_TEXT, OBJECT_DEFAULTS_VECTOR, OBJECT_S
|
||||
import Barcode from "../fabric-object/barcode";
|
||||
import { QRCode } from "../fabric-object/qrcode";
|
||||
import type { OjectType } from "../types";
|
||||
import { Toasts } from "./toasts";
|
||||
|
||||
export class LabelDesignerObjectHelper {
|
||||
static async addSvg(canvas: fabric.Canvas, svgCode: string): Promise<fabric.FabricObject | fabric.Group> {
|
||||
@@ -51,6 +52,8 @@ export class LabelDesignerObjectHelper {
|
||||
console.error(readerEvt);
|
||||
reject(new Error("File read error"));
|
||||
};
|
||||
} else {
|
||||
reject(new Error("Unsupported image"));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -64,7 +67,8 @@ export class LabelDesignerObjectHelper {
|
||||
input.onchange = (e: Event) => {
|
||||
const target = e.target as HTMLInputElement;
|
||||
if (target.files !== null) {
|
||||
this.addImageFile(fabricCanvas, target.files[0]).then(resolve);
|
||||
// fixme: catch error in other place
|
||||
this.addImageFile(fabricCanvas, target.files[0]).then(resolve).catch(Toasts.error);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user