| @@ -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', |
| @@ -10,21 +9,31 @@ | ||
| 10 | 9 | 'core/list', |
| 11 | 10 | 'core/quote', |
| 12 | 11 | ]); |
| 13 | 12 | |
| 13 | +// core/accordion-item locks these in place (templateLock 'all'), so the op takes the item. | |
| 14 | +const LOCKED_PARTS = new Set([ | |
| 15 | + 'core/accordion-heading', | |
| 16 | + 'core/accordion-panel', | |
| 17 | +]); | |
| 18 | + | |
| 14 | 19 | // The wrapper never reaches the model (dropped from the manifest), so "delete this |
| 15 | 20 | // 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}"]`); | |
| 21 | +export const resolveDeleteTarget = (blockId, scope = null) => { | |
| 22 | + const el = findBlockEl(blockId, document, scope); | |
| 18 | 23 | if (!el) return blockId; |
| 19 | 24 | let targetId = blockId; |
| 20 | - let parent = el.parentElement?.closest(`[${BLOCK_ID_ATTR}]`); | |
| 25 | + let parent = el.parentElement?.closest(BLOCK_ID_SEL); | |
| 26 | + if (parent && LOCKED_PARTS.has(detectBlockType(el))) { | |
| 27 | + targetId = blockIdOf(parent); | |
| 28 | + parent = parent.parentElement?.closest(BLOCK_ID_SEL); | |
| 29 | + } | |
| 21 | 30 | while ( |
| 22 | 31 | parent && |
| 23 | 32 | LIST_WRAPPERS.has(detectBlockType(parent)) && |
| 24 | - parent.querySelectorAll(`[${BLOCK_ID_ATTR}]`).length === 1 | |
| 33 | + parent.querySelectorAll(BLOCK_ID_SEL).length === 1 | |
| 25 | 34 | ) { |
| 26 | - targetId = parent.getAttribute(BLOCK_ID_ATTR); | |
| 27 | - parent = parent.parentElement?.closest(`[${BLOCK_ID_ATTR}]`); | |
| 35 | + targetId = blockIdOf(parent); | |
| 36 | + parent = parent.parentElement?.closest(BLOCK_ID_SEL); | |
| 28 | 37 | } |
| 29 | 38 | return targetId; |
| 30 | 39 | }; |