diff --git a/apps/web/src/components/ui/report/elements/MediaEmbedNode.tsx b/apps/web/src/components/ui/report/elements/MediaEmbedNode.tsx index a0c9d3362..fd07aa0c7 100644 --- a/apps/web/src/components/ui/report/elements/MediaEmbedNode.tsx +++ b/apps/web/src/components/ui/report/elements/MediaEmbedNode.tsx @@ -6,12 +6,19 @@ import LiteYouTubeEmbed from 'react-lite-youtube-embed'; import type { TMediaEmbedElement } from 'platejs'; import type { PlateElementProps } from 'platejs/react'; -import { parseTwitterUrl, parseVideoUrl } from '@platejs/media'; +import { + parseTwitterUrl, + parseVideoUrl, + parseIframeUrl, + parseMediaUrl, + type EmbedUrlParser +} from '@platejs/media'; import { MediaEmbedPlugin, useMediaState } from '@platejs/media/react'; import { ResizableProvider, useResizableValue } from '@platejs/resizable'; import { PlateElement, useEditorRef, + useElement, useFocused, useReadOnly, useSelected, @@ -25,17 +32,27 @@ import { MediaToolbar } from './MediaToolbar'; import { mediaResizeHandleVariants, Resizable, ResizeHandle } from './ResizeHandle'; import { Code3 } from '../../icons'; import { PopoverAnchor, PopoverBase, PopoverContent } from '../../popover'; -import { Title, Text } from '../../typography'; +import { Text } from '../../typography'; import { Input } from '../../inputs'; import { Button } from '../../buttons'; import { Separator } from '../../separator'; import { useBusterNotifications } from '@/context/BusterNotifications'; import { useEffect } from 'react'; -import { useMount } from '@/hooks'; +import { useClickAway } from '@/hooks/useClickAway'; + +const parseGenericUrl: EmbedUrlParser = (url: string) => { + return { + url, + provider: 'generic' + }; +}; + +const urlParsers: EmbedUrlParser[] = [parseTwitterUrl, parseVideoUrl, parseGenericUrl]; export const MediaEmbedElement = withHOC( ResizableProvider, function MediaEmbedElement(props: PlateElementProps) { + const url = props.element.url; const { align = 'center', embed, @@ -44,13 +61,14 @@ export const MediaEmbedElement = withHOC( isVideo, isYoutube, readOnly, - selected + selected, + ...rest } = useMediaState({ - urlParsers: [parseTwitterUrl, parseVideoUrl] + urlParsers }); const width = useResizableValue('width'); const provider = embed?.provider; - const hasElement = !!embed?.url; + const hasElement = !!url; if (!hasElement) { return ; @@ -115,7 +133,19 @@ export const MediaEmbedElement = withHOC( /> ) - ) : null} + ) : ( +
+