/** * Styles */ import './style.scss'; /** * WordPress dependencies */ import { useRef, useEffect, RawHTML, memo } from '@wordpress/element'; const AIResponse = memo( function AIResponse({ response, loading }) { const responseRef = useRef(); useEffect(() => { if (!responseRef.current) { return; } const popupContent = responseRef.current.closest( '.mind-popup-content' ); if (!popupContent) { return; } // Smooth scroll to bottom of response. const { scrollHeight, clientHeight } = popupContent; // Only auto-scroll for shorter contents. const shouldScroll = scrollHeight - clientHeight < 1000; if (shouldScroll) { popupContent.scrollTo({ top: scrollHeight, behavior: 'smooth', }); } }, [response]); if (!response && !loading) { return null; } return (