chore: bump @halo-dev/richtext-editor to supports more feature about media (#834)

#### What type of PR is this?

/kind feature

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

升级默认编辑器版本,改动请查阅:

1. https://github.com/halo-sigs/richtext-editor/pull/4
2. https://github.com/halo-sigs/richtext-editor/pull/3
3. https://github.com/halo-sigs/richtext-editor/pull/2

#### Special notes for your reviewer:

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

```release-note
升级 Console 端默认编辑器版本,以支持图片位置和大小设置、插入音视频等功能。
```
pull/825/head^2
Ryan Wang 2023-01-31 22:10:09 +08:00 committed by GitHub
parent 21530d309e
commit d51713ec27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 677 additions and 657 deletions

1
.npmrc
View File

@ -1 +1,2 @@
strict-peer-dependencies=false strict-peer-dependencies=false
auto-install-peers=true

View File

@ -44,7 +44,7 @@
"@halo-dev/api-client": "0.0.71", "@halo-dev/api-client": "0.0.71",
"@halo-dev/components": "workspace:*", "@halo-dev/components": "workspace:*",
"@halo-dev/console-shared": "workspace:*", "@halo-dev/console-shared": "workspace:*",
"@halo-dev/richtext-editor": "^0.0.0-alpha.17", "@halo-dev/richtext-editor": "0.0.0-alpha.19",
"@tiptap/extension-character-count": "^2.0.0-beta.202", "@tiptap/extension-character-count": "^2.0.0-beta.202",
"@uppy/core": "^3.0.4", "@uppy/core": "^3.0.4",
"@uppy/dashboard": "^3.2.0", "@uppy/dashboard": "^3.2.0",

File diff suppressed because it is too large Load Diff

View File

@ -33,6 +33,8 @@ import {
ExtensionHighlight, ExtensionHighlight,
ExtensionCommands, ExtensionCommands,
ExtensionIframe, ExtensionIframe,
ExtensionVideo,
ExtensionAudio,
CommandsSuggestion, CommandsSuggestion,
CommentParagraph, CommentParagraph,
CommandHeader1, CommandHeader1,
@ -43,6 +45,8 @@ import {
CommandHeader6, CommandHeader6,
CommandCodeBlock, CommandCodeBlock,
CommandIframe, CommandIframe,
CommandVideo,
CommandAudio,
CommandTable, CommandTable,
CommandBulletList, CommandBulletList,
CommandOrderedList, CommandOrderedList,
@ -205,6 +209,8 @@ const editor = useEditor({
CommandOrderedList, CommandOrderedList,
CommandTaskList, CommandTaskList,
CommandIframe, CommandIframe,
CommandVideo,
CommandAudio,
].filter((item) => ].filter((item) =>
[...item.keywords, item.title].some((keyword) => [...item.keywords, item.title].some((keyword) =>
keyword.includes(query) keyword.includes(query)
@ -217,6 +223,8 @@ const editor = useEditor({
lowlight, lowlight,
}), }),
ExtensionIframe, ExtensionIframe,
ExtensionVideo,
ExtensionAudio,
ExtensionCharacterCount, ExtensionCharacterCount,
Extension.create({ Extension.create({
addGlobalAttributes() { addGlobalAttributes() {

View File

@ -285,32 +285,63 @@ export function useAttachmentSelect(
editor: Ref<Editor | undefined> editor: Ref<Editor | undefined>
): useAttachmentSelectReturn { ): useAttachmentSelectReturn {
const onAttachmentSelect = (attachments: AttachmentLike[]) => { const onAttachmentSelect = (attachments: AttachmentLike[]) => {
const images: Content[] = attachments.map((attachment) => { const contents: Content[] = attachments
const attrs: { src?: string; alt?: string } = {}; .map((attachment) => {
if (typeof attachment === "string") { if (typeof attachment === "string") {
attrs.src = attachment; return {
return { type: "image",
type: "image", attrs: {
attrs, src: attachment,
}; },
} };
if ("url" in attachment) { }
attrs.src = attachment.url; if ("url" in attachment) {
attrs.alt = attachment.type; return {
} type: "image",
if ("spec" in attachment) { attrs: {
attrs.src = attachment.status?.permalink; src: attachment.url,
attrs.alt = attachment.spec.displayName; alt: attachment.type,
} },
return { };
type: "image", }
attrs, if ("spec" in attachment) {
}; const { mediaType, displayName } = attachment.spec;
}); const { permalink } = attachment.status || {};
if (mediaType?.startsWith("image/")) {
return {
type: "image",
attrs: {
src: permalink,
alt: displayName,
},
};
}
if (mediaType?.startsWith("video/")) {
return {
type: "video",
attrs: {
src: permalink,
},
};
}
if (mediaType?.startsWith("audio/")) {
return {
type: "audio",
attrs: {
src: permalink,
},
};
}
}
})
.filter(Boolean) as Content[];
console.log(contents);
editor.value editor.value
?.chain() ?.chain()
.focus() .focus()
.insertContent([...images, { type: "paragraph", content: "" }]) .insertContent([...contents, { type: "paragraph", content: "" }])
.run(); .run();
}; };