import { useState } from 'react'; import { safeCall, toast } from '../lib/app'; import { renderTsMarkup } from '../lib/tsMarkup'; import { Modal } from './Modal'; import { t } from '../i18n'; // Announce composer with a live TS6-markdown/BBCode preview (item 14). // Replaces the old prompt(). A small toolbar wraps the selection in common // formatting tags; the preview renders exactly what subscribers will see. const TOOLBAR: Array<{ label: string; before: string; after: string }> = [ { label: 'B', before: '**', after: '**' }, { label: 'I', before: '*', after: '*' }, { label: 'U', before: '[u]', after: '[/u]' }, { label: 'S', before: '~~', after: '~~' }, { label: '', before: '`', after: '`' }, { label: '🔗', before: '[', after: '](https://)' }, { label: 'H', before: '# ', after: '' }, { label: '❝', before: '> ', after: '' }, ]; export function AnnounceModal({ onClose }: { onClose: () => void }) { const [text, setText] = useState(''); const [sending, setSending] = useState(false); let ref: HTMLTextAreaElement | null = null; const wrap = (before: string, after: string) => { const el = ref; if (!el) return; const start = el.selectionStart; const end = el.selectionEnd; const selected = text.slice(start, end); const next = text.slice(0, start) + before + selected + after + text.slice(end); setText(next); // Restore focus with the caret after the inserted opening tag. queueMicrotask(() => { el.focus(); const pos = start + before.length + selected.length; el.setSelectionRange(pos, pos); }); }; return ( } >
{TOOLBAR.map((b) => ( ))}