import { Button, ColorPalette, Popover } from '@wordpress/components'; import { useDispatch, useSelect } from '@wordpress/data'; import { useRef, useState } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; import { applyColorFormat, captureDomRichTextSelection, } from '../../lib/rich-text-color'; export function ColorButton({ kind, label, iconClassName }) { const [open, setOpen] = useState(false); const wrapRef = useRef(null); const frozenSel = useRef(null); const sel = useSelect((select) => { const editor = select('core/block-editor'); const start = editor.getSelectionStart(); const end = editor.getSelectionEnd(); if (!start || !start.clientId) return null; const block = editor.getBlock(start.clientId); if (!block) return null; const settings = editor.getSettings() || {}; return { start, end, block, palette: settings.colors || [] }; }, []); // React-context registry dispatch; the outer wp.data.dispatch can't see this block. const dispatch = useDispatch('core/block-editor'); return (