@sequent-org/moodboard 1.4.12 → 1.4.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -40,6 +40,49 @@ export class KeyboardClipboardImagePaste {
|
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
async handleFileUpload(file, fileName) {
|
|
44
|
+
try {
|
|
45
|
+
if (!(this.core && this.core.fileUploadService)) {
|
|
46
|
+
alert('Сервис загрузки файлов недоступен. Файл не добавлен.');
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const uploadResult = await this.core.fileUploadService.uploadFile(file, fileName);
|
|
51
|
+
const world = this.core?.pixi?.worldLayer || this.core?.pixi?.app?.stage;
|
|
52
|
+
const view = this.core?.pixi?.app?.view;
|
|
53
|
+
const s = world?.scale?.x || 1;
|
|
54
|
+
const hasCursor = Number.isFinite(this.core?._cursor?.x) && Number.isFinite(this.core?._cursor?.y);
|
|
55
|
+
|
|
56
|
+
const screenX = hasCursor ? this.core._cursor.x : (view?.clientWidth || 0) / 2;
|
|
57
|
+
const screenY = hasCursor ? this.core._cursor.y : (view?.clientHeight || 0) / 2;
|
|
58
|
+
const worldX = (screenX - (world?.x || 0)) / s;
|
|
59
|
+
const worldY = (screenY - (world?.y || 0)) / s;
|
|
60
|
+
|
|
61
|
+
const width = 120;
|
|
62
|
+
const height = 140;
|
|
63
|
+
this.eventBus.emit(Events.UI.ToolbarAction, {
|
|
64
|
+
type: 'file',
|
|
65
|
+
id: 'file',
|
|
66
|
+
position: {
|
|
67
|
+
x: Math.round(worldX - width / 2),
|
|
68
|
+
y: Math.round(worldY - height / 2)
|
|
69
|
+
},
|
|
70
|
+
properties: {
|
|
71
|
+
fileName: uploadResult.name,
|
|
72
|
+
fileSize: uploadResult.size,
|
|
73
|
+
mimeType: uploadResult.mimeType,
|
|
74
|
+
formattedSize: uploadResult.formattedSize,
|
|
75
|
+
src: uploadResult.src,
|
|
76
|
+
width,
|
|
77
|
+
height
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
} catch (error) {
|
|
81
|
+
console.error('Ошибка загрузки файла:', error);
|
|
82
|
+
alert('Ошибка загрузки файла на сервер. Файл не добавлен.');
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
43
86
|
createPasteHandler() {
|
|
44
87
|
return async (e) => {
|
|
45
88
|
try {
|
|
@@ -66,6 +109,12 @@ export class KeyboardClipboardImagePaste {
|
|
|
66
109
|
await this.handleImageFileUpload(imgFile, imgFile.name || 'clipboard-image.png');
|
|
67
110
|
return;
|
|
68
111
|
}
|
|
112
|
+
const plainFile = files.find(f => !(f.type && f.type.startsWith('image/')));
|
|
113
|
+
if (plainFile) {
|
|
114
|
+
e.preventDefault();
|
|
115
|
+
await this.handleFileUpload(plainFile, plainFile.name || 'clipboard-file');
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
69
118
|
|
|
70
119
|
const html = cd.getData && cd.getData('text/html');
|
|
71
120
|
if (html && html.includes('<img')) {
|