fix: pasting not working in firefox (#9947)

This commit is contained in:
David Luzar
2025-09-06 22:51:23 +02:00
committed by GitHub
parent 3bdaafe4b5
commit b9d27d308e
14 changed files with 445 additions and 261 deletions
+13 -12
View File
@@ -47,42 +47,43 @@ class DataTransferItem {
}
}
class DataTransferList {
items: DataTransferItem[] = [];
class DataTransferItemList extends Array<DataTransferItem> {
add(data: string | File, type: string = ""): void {
if (typeof data === "string") {
this.items.push(new DataTransferItem("string", type, data));
this.push(new DataTransferItem("string", type, data));
} else if (data instanceof File) {
this.items.push(new DataTransferItem("file", type, data));
this.push(new DataTransferItem("file", type, data));
}
}
clear(): void {
this.items = [];
this.clear();
}
}
class DataTransfer {
public items: DataTransferList = new DataTransferList();
private _types: Record<string, string> = {};
public items: DataTransferItemList = new DataTransferItemList();
get files() {
return this.items.items
return this.items
.filter((item) => item.kind === "file")
.map((item) => item.getAsFile()!);
}
add(data: string | File, type: string = ""): void {
this.items.add(data, type);
if (typeof data === "string") {
this.items.add(data, type);
} else {
this.items.add(data);
}
}
setData(type: string, value: string) {
this._types[type] = value;
this.items.add(value, type);
}
getData(type: string) {
return this._types[type] || "";
return this.items.find((item) => item.type === type)?.data || "";
}
}