import { NodeViewWrapper } from '@tiptap/react' import React, { useState, useRef, useEffect, useMemo } from 'react' import { Upload, Link as LinkIcon, GripVertical, GripHorizontal, AlignCenter, Cuboid, Code } from 'lucide-react' import { useEditorProvider } from '@components/Contexts/Editor/EditorContext' import { SiGithub, SiReplit, SiSpotify, SiLoom, SiGooglemaps, SiCodepen, SiCanva, SiNotion, SiGoogledocs, SiGitlab, SiX, SiFigma, SiGiphy } from '@icons-pack/react-simple-icons' import { useRouter } from 'next/navigation' import DOMPurify from 'dompurify' // Add new type for script-based embeds const SCRIPT_BASED_EMBEDS = { twitter: { src: 'https://platform.twitter.com/widgets.js', identifier: 'twitter-tweet' }, instagram: { src: 'https://www.instagram.com/embed.js', identifier: 'instagram-media' }, tiktok: { src: 'https://www.tiktok.com/embed.js', identifier: 'tiktok-embed' }, // Add more platforms as needed }; // Add new memoized component for the embed content const MemoizedEmbed = React.memo(({ embedUrl, sanitizedEmbedCode, embedType }: { embedUrl: string; sanitizedEmbedCode: string; embedType: 'url' | 'code'; }) => { useEffect(() => { if (embedType === 'code' && sanitizedEmbedCode) { // Check for any matching script-based embeds const matchingPlatform = Object.entries(SCRIPT_BASED_EMBEDS).find(([_, config]) => sanitizedEmbedCode.includes(config.identifier) ); if (matchingPlatform) { const [_, config] = matchingPlatform; const script = document.createElement('script'); script.src = config.src; script.async = true; script.charset = 'utf-8'; document.body.appendChild(script); return () => { document.body.removeChild(script); }; } } }, [embedType, sanitizedEmbedCode]); if (embedType === 'url' && embedUrl) { return (