From e4b655e5613e16e7771ab2d9fea39c232c30601a Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Fri, 24 Feb 2023 17:48:20 +0800 Subject: [PATCH] perf: disable the editor from pasting excel tables as pictures (#873) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? /kind improvement #### What this PR does / why we need it: 禁止在编辑器粘贴 Excel 表格时,将表格转为图片的形式上传。 #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/3348 #### Screenshots: before: image after: image #### Special notes for your reviewer: 测试方式: 1. 使用 Excel 或者 macOS 下的 Numbers 创建一个表格。 2. 复制整个表格或者某几个单元格,并粘贴到 Halo 的编辑器。 3. 观察是否有将内容转为图片并上传。 #### Does this PR introduce a user-facing change? ```release-note Console 端禁止在编辑器粘贴 Excel 表格以图片的形式上传。 ``` --- src/components/editor/DefaultEditor.vue | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/components/editor/DefaultEditor.vue b/src/components/editor/DefaultEditor.vue index 879e7584..e5a2ba33 100644 --- a/src/components/editor/DefaultEditor.vue +++ b/src/components/editor/DefaultEditor.vue @@ -301,6 +301,12 @@ const editor = useEditor({ return false; }, handlePaste: (view, event: ClipboardEvent) => { + const types = Array.from(event.clipboardData?.types || []); + + if (["text/plain", "text/html"].includes(types[0])) { + return; + } + const images = Array.from(event.clipboardData?.items || []) .map((item) => { return item.getAsFile();