From f7c0fd5762ca22758847b3f924ba275d5d098acc Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Fri, 24 Feb 2023 17:46:21 +0800 Subject: [PATCH] feat: editor supports selecting attachments to be inserted as links (#863) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? /kind feature #### What this PR does / why we need it: 编辑器支持选择附件作为链接插入。目前在附件库选择附件时,如果非图片、视频、音频,那么就会作为链接插入。 #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/2673 #### Screenshots: ![2023-02-17 21 02 43](https://user-images.githubusercontent.com/21301288/219660123-b910a4d5-32e6-4606-813e-c081720556d5.gif) #### Special notes for your reviewer: 测试方式: 1. 测试从附件库选择非图片、视频、音频的时候是否会作为链接插入即可。 #### Does this PR introduce a user-facing change? ```release-note Console 端默认编辑器支持以链接的形式插入非图片、音视频的附件。 ``` --- .../attachments/composables/use-attachment.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/modules/contents/attachments/composables/use-attachment.ts b/src/modules/contents/attachments/composables/use-attachment.ts index 122a9381..4c0ac176 100644 --- a/src/modules/contents/attachments/composables/use-attachment.ts +++ b/src/modules/contents/attachments/composables/use-attachment.ts @@ -256,6 +256,7 @@ export function useAttachmentSelect( }, }; } + if ("url" in attachment) { return { type: "image", @@ -265,6 +266,7 @@ export function useAttachmentSelect( }, }; } + if ("spec" in attachment) { const { mediaType, displayName } = attachment.spec; const { permalink } = attachment.status || {}; @@ -295,9 +297,23 @@ export function useAttachmentSelect( }, }; } + + return { + type: "text", + marks: [ + { + type: "link", + attrs: { + href: permalink, + }, + }, + ], + text: displayName, + }; } }) .filter(Boolean) as Content[]; + editor.value ?.chain() .focus()