import { store as blockEditorStore } from '@wordpress/block-editor'; import { Button } from '@wordpress/components'; import { useDispatch } from '@wordpress/data'; import { useEffect, useState } from '@wordpress/element'; import { __, isRTL } from '@wordpress/i18n'; import { Icon, edit, trash } from '@wordpress/icons'; import { useSelectedText } from '@draft/hooks/useSelectedText'; export const SelectedText = ({ loading }) => { const [text, setText] = useState(); const { clearSelectedBlock } = useDispatch(blockEditorStore); const { selectedText } = useSelectedText(); useEffect(() => { setText(selectedText); }, [setText, selectedText]); if (!text) return; const truncatedText = () => { const preformat = text.split(' '); if (preformat.length <= 20) return text; return `${text.split(' ', 14).join(' ')}... ${text.slice( text.lastIndexOf(' ') - 14, )}`; }; return (