| @@ -1,4 +1,5 @@ | ||
| 1 | +import { findBlockEl, scopeOf } from '@agent/lib/block-el'; | |
| 1 | 2 | import { buildSubtreeManifest } from '@agent/lib/subtree-manifest'; |
| 2 | 3 | import { useQuickEditStore } from '@quick-edit/state/store'; |
| 3 | 4 | import { useMemo } from '@wordpress/element'; |
| 4 | 5 | import { __, _n, sprintf } from '@wordpress/i18n'; |
| @@ -7,19 +8,16 @@ | ||
| 7 | 8 | |
| 8 | 9 | export const PageDocument = ({ busy }) => { |
| 9 | 10 | const setBlock = useQuickEditStore((s) => s.setAgentBlock); |
| 10 | 11 | const block = useQuickEditStore((s) => s.agentBlock); |
| 11 | - const attr = block?.target || 'data-extendify-agent-block-id'; | |
| 12 | 12 | |
| 13 | 13 | // The same manifest the agent works from, so the count matches what it |
| 14 | 14 | // can actually address — not every node in the subtree. |
| 15 | 15 | const count = useMemo(() => { |
| 16 | 16 | if (!block?.id) return 1; |
| 17 | - const node = document.querySelector( | |
| 18 | - `[${attr}="${CSS.escape(String(block.id))}"]`, | |
| 19 | - ); | |
| 17 | + const node = findBlockEl(block.id, document, scopeOf(block)); | |
| 20 | 18 | return Math.max(node ? buildSubtreeManifest(node).length : 1, 1); |
| 21 | - }, [block, attr]); | |
| 19 | + }, [block]); | |
| 22 | 20 | |
| 23 | 21 | return ( |
| 24 | 22 | // The input darkens to gray-300 while disabled; a gray-200 chip vanishes into it. |
| 25 | 23 | <div |