mirror of https://github.com/halo-dev/halo
feat: editor supports selecting attachments to be inserted as links (halo-dev/console#863)
#### 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:  #### Special notes for your reviewer: 测试方式: 1. 测试从附件库选择非图片、视频、音频的时候是否会作为链接插入即可。 #### Does this PR introduce a user-facing change? ```release-note Console 端默认编辑器支持以链接的形式插入非图片、音视频的附件。 ```pull/3445/head
parent
9ae08cdd9b
commit
e547540e3a
|
@ -256,6 +256,7 @@ export function useAttachmentSelect(
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("url" in attachment) {
|
if ("url" in attachment) {
|
||||||
return {
|
return {
|
||||||
type: "image",
|
type: "image",
|
||||||
|
@ -265,6 +266,7 @@ export function useAttachmentSelect(
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("spec" in attachment) {
|
if ("spec" in attachment) {
|
||||||
const { mediaType, displayName } = attachment.spec;
|
const { mediaType, displayName } = attachment.spec;
|
||||||
const { permalink } = attachment.status || {};
|
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[];
|
.filter(Boolean) as Content[];
|
||||||
|
|
||||||
editor.value
|
editor.value
|
||||||
?.chain()
|
?.chain()
|
||||||
.focus()
|
.focus()
|
||||||
|
|
Loading…
Reference in New Issue