fix: resolve issue with editor not detecting image paste in Firefox (#6693)

#### What type of PR is this?

/area ui
/kind bug
/milestone 2.20.x

#### What this PR does / why we need it:

修复在 FireFox 浏览器下的编辑器中无法通过粘贴文件上传的问题。

#### Which issue(s) this PR fixes:

Fixes #6684 

#### Special notes for your reviewer:

在 FireFox 浏览器中,复制一张本地的图片,尝试在编辑器中粘贴,观察是否上传成功。

#### Does this PR introduce a user-facing change?

```release-note
修复在 FireFox 浏览器下的编辑器中无法通过粘贴文件上传的问题。
```
pull/6703/head^2
Ryan Wang 2024-09-28 18:37:41 +08:00 committed by GitHub
parent 9305fd51d8
commit 774678fd65
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 2 deletions

View File

@ -4,7 +4,10 @@ import {
Plugin,
PluginKey,
} from "@halo-dev/richtext-editor";
import { handleFileEvent } from "../../utils/upload";
import {
containsFileClipboardIdentifier,
handleFileEvent,
} from "../../utils/upload";
export const Upload = Extension.create({
name: "upload",
@ -26,7 +29,8 @@ export const Upload = Extension.create({
}
const types = event.clipboardData.types;
if (!(types.length === 1 && types[0].toLowerCase() === "files")) {
if (!containsFileClipboardIdentifier(types)) {
return false;
}

View File

@ -142,3 +142,8 @@ export function fileToBase64(file: File): Promise<string> {
reader.readAsDataURL(file);
});
}
export function containsFileClipboardIdentifier(types: readonly string[]) {
const fileTypes = ["files", "application/x-moz-file", "public.file-url"];
return types.some((type) => fileTypes.includes(type.toLowerCase()));
}