From fedbda3747ca65048f6969b09aced05350f036e7 Mon Sep 17 00:00:00 2001 From: iskaktoltay Date: Tue, 10 Dec 2024 18:06:30 +0500 Subject: [PATCH] returned web embed, and media block types to link dropdown menu --- .../LinkMenu/defaultLinkMenuItems.tsx | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/frontend/apps/desktop/src/editor/blocknote/core/extensions/LinkMenu/defaultLinkMenuItems.tsx b/frontend/apps/desktop/src/editor/blocknote/core/extensions/LinkMenu/defaultLinkMenuItems.tsx index e7fd634f7..d1f73f015 100644 --- a/frontend/apps/desktop/src/editor/blocknote/core/extensions/LinkMenu/defaultLinkMenuItems.tsx +++ b/frontend/apps/desktop/src/editor/blocknote/core/extensions/LinkMenu/defaultLinkMenuItems.tsx @@ -209,35 +209,33 @@ export function getLinkMenuItems({ ...linkMenuItems, ] } - } else if (false) { - // DISABLE TWITTER/X EMBEDS BECAUSE IT DOES NOT WORK ON WEB + } else if (media) { const mediaItem = { - name: `Convert to ${ + name: media === 'twitter' ? 'X Post embed' - : media.charAt(0).toUpperCase() + media.slice(1) - }`, + : media.charAt(0).toUpperCase() + media.slice(1), disabled: false, icon: media === 'twitter' ? ( ) : undefined, - execute: (editor: BlockNoteEditor, ref: string) => { + execute: (editor: BlockNoteEditor, link: string) => { const {state, schema} = editor._tiptapEditor const {selection} = state if (!selection.empty) return let embedUrl = '' if (media === 'video') { - let videoUrl = '' - if (ref.includes('youtu.be') || ref.includes('youtube')) { - let ytId = youtubeParser(ref) + let videoUrl = link ? link : sourceUrl ? sourceUrl : '' + if (videoUrl.includes('youtu.be') || videoUrl.includes('youtube')) { + let ytId = youtubeParser(videoUrl) if (ytId) { videoUrl = `https://www.youtube.com/embed/${ytId}` } else { videoUrl = '' } - } else if (ref.includes('vimeo')) { - const urlArray = ref.split('/') + } else if (videoUrl.includes('vimeo')) { + const urlArray = videoUrl.split('/') videoUrl = 'https://player.vimeo.com/video/' + urlArray[urlArray.length - 1] @@ -248,14 +246,14 @@ export function getLinkMenuItems({ media !== 'twitter' ? schema.nodes[media].create({ url: embedUrl ? embedUrl : '', - src: embedUrl ? '' : ref, + src: embedUrl ? '' : link, name: fileName ? fileName : '', }) : schema.nodes['web-embed'].create({ - url: ref, + url: link ? link : sourceUrl, }) - insertNode(editor, sourceUrl ? sourceUrl : ref, node) + insertNode(editor, link ? link : sourceUrl ? sourceUrl : '', node) }, }