import { PlateElement } from '@udecode/plate-common' import { forwardRef } from 'react' import { match } from 'ts-pattern' import type { MediaEmbedState } from './plugin' import { favicon, mediaEmbed, mediaEmbedWrapper, unknownMediaEmbed, unknownMediaEmbedContent, unknownMediaEmbedLink, unknownMediaEmbedTitle, youtubeThumbnail } from './element.css' import { addMissingCssUnit, getFaviconUrl } from '@editor/utils' export const MediaEmbedElement = forwardRef( ( props: React.ComponentPropsWithoutRef, ref: React.ElementRef, ) => { const { align, info, width, height, url: _url } = props.element as unknown as MediaEmbedState const url = new URL(_url) const embed = match(info) .with({ type: 'youtube' }, info => ( IMAGE ALT TEXT HERE {`favicon )) .otherwise(() => (
{`favicon
{info.title ?

{info.title}

: null} {url.href}
)) return ( {embed} {props.children} ) }, )