PluginProbe
Extendify / 3.2.2
Extendify v3.2.2
3.2.2 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 All 128 releases
extendify / src / Agent / lib / delete-target.js

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

40 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { BLOCK_ID_SEL, blockIdOf, findBlockEl } from './block-el';
2 import { detectBlockType } from './block-type';
3
4 // Wrappers that are broken markup without their last item — the op takes the
5 // wrapper. Not group/columns: an empty one still renders a box worth keeping.
6 const LIST_WRAPPERS = new Set([
7 'core/buttons',
8 'core/social-links',
9 'core/list',
10 'core/quote',
11 ]);
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
19 // The wrapper never reaches the model (dropped from the manifest), so "delete this
20 // button" can only name the button — walk up to the wrapper when it's the last item.
21 export const resolveDeleteTarget = (blockId, scope = null) => {
22 const el = findBlockEl(blockId, document, scope);
23 if (!el) return blockId;
24 let targetId = blockId;
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 }
30 while (
31 parent &&
32 LIST_WRAPPERS.has(detectBlockType(parent)) &&
33 parent.querySelectorAll(BLOCK_ID_SEL).length === 1
34 ) {
35 targetId = blockIdOf(parent);
36 parent = parent.parentElement?.closest(BLOCK_ID_SEL);
37 }
38 return targetId;
39 };
40