import { buildSubtreeManifest } from '@agent/lib/subtree-manifest'; import { useQuickEditStore } from '@quick-edit/state/store'; import { useMemo } from '@wordpress/element'; import { __, _n, sprintf } from '@wordpress/i18n'; import { close, Icon } from '@wordpress/icons'; import classNames from 'classnames'; export const PageDocument = ({ busy }) => { const setBlock = useQuickEditStore((s) => s.setAgentBlock); const block = useQuickEditStore((s) => s.agentBlock); const attr = block?.target || 'data-extendify-agent-block-id'; // The same manifest the agent works from, so the count matches what it // can actually address — not every node in the subtree. const count = useMemo(() => { if (!block?.id) return 1; const node = document.querySelector( `[${attr}="${CSS.escape(String(block.id))}"]`, ); return Math.max(node ? buildSubtreeManifest(node).length : 1, 1); }, [block, attr]); return ( // The input darkens to gray-300 while disabled; a gray-200 chip vanishes into it.
{sprintf( // translators: %d is the number of blocks the user selected on the page. _n( '%d block selected', '%d blocks selected', count, 'extendify-local', ), count, )} {/* Stays mounted while disabled: dropping it reflows the chip mid-run. */}
); };