PluginProbe
Extendify / 3.1.5
Extendify v3.1.5
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / src / Agent / lib / delete-target.js

delete-target.js in Extendify 3.1.5, at src/Agent/lib/delete-target.js

31 lines 1.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { detectBlockType } from './block-type';
2
3 const BLOCK_ID_ATTR = 'data-extendify-agent-block-id';
4
5 // Wrappers that are broken markup without their last item — the op takes the
6 // wrapper. Not group/columns: an empty one still renders a box worth keeping.
7 const LIST_WRAPPERS = new Set([
8 'core/buttons',
9 'core/social-links',
10 'core/list',
11 'core/quote',
12 ]);
13
14 // The wrapper never reaches the model (dropped from the manifest), so "delete this
15 // 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}"]`);
18 if (!el) return blockId;
19 let targetId = blockId;
20 let parent = el.parentElement?.closest(`[${BLOCK_ID_ATTR}]`);
21 while (
22 parent &&
23 LIST_WRAPPERS.has(detectBlockType(parent)) &&
24 parent.querySelectorAll(`[${BLOCK_ID_ATTR}]`).length === 1
25 ) {
26 targetId = parent.getAttribute(BLOCK_ID_ATTR);
27 parent = parent.parentElement?.closest(`[${BLOCK_ID_ATTR}]`);
28 }
29 return targetId;
30 };
31