'use client'; import * as React from 'react'; 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 { MediaEmbedPlugin, useMediaState } from '@platejs/media/react'; import { ResizableProvider, useResizableValue } from '@platejs/resizable'; import { PlateElement, useFocused, useReadOnly, useSelected, withHOC } from 'platejs/react'; import { cn } from '@/lib/utils'; import { Caption, CaptionTextarea } from './CaptionNode'; import { MediaToolbar } from './MediaToolbar'; import { mediaResizeHandleVariants, Resizable, ResizeHandle } from './ResizeHandle'; import { Code3 } from '../../icons'; import { PopoverAnchor, PopoverBase, PopoverContent } from '../../popover'; import { useEffect, useState } from 'react'; import { Title } from '../../typography'; import { Input } from '../../inputs'; import { Button } from '../../buttons'; export const MediaEmbedElement = withHOC( ResizableProvider, function MediaEmbedElement(props: PlateElementProps) { const { align = 'center', embed, focused, isTweet, isVideo, isYoutube, readOnly, selected } = useMediaState({ urlParsers: [parseTwitterUrl, parseVideoUrl] }); const width = useResizableValue('width'); const provider = embed?.provider; const hasElement = !!embed?.url; if (!hasElement) { return ; } return (
{isVideo ? ( isYoutube ? ( _iframe]:absolute [&_>_iframe]:top-0 [&_>_iframe]:left-0 [&_>_iframe]:size-full', '[&_>_.lty-playbtn]:z-1 [&_>_.lty-playbtn]:h-[46px] [&_>_.lty-playbtn]:w-[70px] [&_>_.lty-playbtn]:rounded-[14%] [&_>_.lty-playbtn]:bg-[#212121] [&_>_.lty-playbtn]:opacity-80 [&_>_.lty-playbtn]:[transition:all_0.2s_cubic-bezier(0,_0,_0.2,_1)]', '[&:hover_>_.lty-playbtn]:bg-[red] [&:hover_>_.lty-playbtn]:opacity-100', '[&_>_.lty-playbtn]:before:border-y-[11px] [&_>_.lty-playbtn]:before:border-r-0 [&_>_.lty-playbtn]:before:border-l-[19px] [&_>_.lty-playbtn]:before:border-[transparent_transparent_transparent_#fff] [&_>_.lty-playbtn]:before:content-[""]', '[&_>_.lty-playbtn]:absolute [&_>_.lty-playbtn]:top-1/2 [&_>_.lty-playbtn]:left-1/2 [&_>_.lty-playbtn]:[transform:translate3d(-50%,-50%,0)]', '[&_>_.lty-playbtn]:before:absolute [&_>_.lty-playbtn]:before:top-1/2 [&_>_.lty-playbtn]:before:left-1/2 [&_>_.lty-playbtn]:before:[transform:translate3d(-50%,-50%,0)]', '[&.lyt-activated]:cursor-[unset]', '[&.lyt-activated]:before:pointer-events-none [&.lyt-activated]:before:opacity-0', '[&.lyt-activated_>_.lty-playbtn]:pointer-events-none [&.lyt-activated_>_.lty-playbtn]:opacity-0!' )} /> ) : (