| @@ -1,8 +1,7 @@ | ||
| 1 | +import { BLOCK_ID_SEL, blockIdOf, findBlockEl } from './block-el'; | |
| 1 | 2 | import { detectBlockType } from './block-type'; |
| 2 | 3 | |
| 3 | -const BLOCK_ID_ATTR = 'data-extendify-agent-block-id'; | |
| 4 | - | |
| 5 | 4 | // Wrappers that are broken markup without their last item — the op takes the |
| 6 | 5 | // wrapper. Not group/columns: an empty one still renders a box worth keeping. |
| 7 | 6 | const LIST_WRAPPERS = new Set([ |
| 8 | 7 | 'core/buttons', |
| @@ -12,19 +11,19 @@ | ||
| 12 | 11 | ]); |
| 13 | 12 | |
| 14 | 13 | // The wrapper never reaches the model (dropped from the manifest), so "delete this |
| 15 | 14 | // button" can only name the button — walk up to the wrapper when it's the last item. |
| 16 | -export const resolveDeleteTarget = (blockId) => { | |
| 17 | - const el = document.querySelector(`[${BLOCK_ID_ATTR}="${blockId}"]`); | |
| 15 | +export const resolveDeleteTarget = (blockId, scope = null) => { | |
| 16 | + const el = findBlockEl(blockId, document, scope); | |
| 18 | 17 | if (!el) return blockId; |
| 19 | 18 | let targetId = blockId; |
| 20 | - let parent = el.parentElement?.closest(`[${BLOCK_ID_ATTR}]`); | |
| 19 | + let parent = el.parentElement?.closest(BLOCK_ID_SEL); | |
| 21 | 20 | while ( |
| 22 | 21 | parent && |
| 23 | 22 | LIST_WRAPPERS.has(detectBlockType(parent)) && |
| 24 | - parent.querySelectorAll(`[${BLOCK_ID_ATTR}]`).length === 1 | |
| 23 | + parent.querySelectorAll(BLOCK_ID_SEL).length === 1 | |
| 25 | 24 | ) { |
| 26 | - targetId = parent.getAttribute(BLOCK_ID_ATTR); | |
| 27 | - parent = parent.parentElement?.closest(`[${BLOCK_ID_ATTR}]`); | |
| 25 | + targetId = blockIdOf(parent); | |
| 26 | + parent = parent.parentElement?.closest(BLOCK_ID_SEL); | |
| 28 | 27 | } |
| 29 | 28 | return targetId; |
| 30 | 29 | }; |