PluginProbe
Extendify / 3.1.0
Extendify v3.1.0
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 / QuickEdit / lib / agent-block-descriptor.js

agent-block-descriptor.js in Extendify 3.1.0, at src/QuickEdit/lib/agent-block-descriptor.js

38 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 // Single source for the agent-block selection-descriptor shape so
2 // DOMHighlighter's click commit and ask-ai's pill click can't drift on
3 // which metadata flags exist or how they're detected.
4
5 const AGENT_ATTR = 'data-extendify-agent-block-id';
6 const PART_ID_ATTR = 'data-extendify-part-block-id';
7 const PART_ATTR = 'data-extendify-part';
8
9 export const buildAgentBlockDescriptor = (match) => {
10 if (!match) return null;
11 const templatePart = match.closest?.(`[${PART_ATTR}]`);
12 const details = {
13 id: match.getAttribute(AGENT_ATTR),
14 target: AGENT_ATTR,
15 hasNav:
16 !!match.querySelector('.wp-block-navigation') ||
17 match.classList.contains('wp-block-navigation'),
18 hasSiteTitle:
19 match.classList.contains('wp-block-site-title') ||
20 !!match.querySelector('.wp-block-site-title'),
21 hasSiteLogo:
22 match.classList.contains('wp-block-site-logo') ||
23 !!match.querySelector('.wp-block-site-logo'),
24 hasLinks: !!match.querySelector('a') || match.tagName === 'A',
25 hasImages:
26 !!match.querySelector('.wp-block-image') ||
27 match.classList.contains('wp-block-image') ||
28 !!match.querySelector('img'),
29 hasText: /\S/.test((match.textContent || '').replace(//g, '')),
30 };
31 if (templatePart) {
32 details.id = templatePart.getAttribute(PART_ID_ATTR);
33 details.target = PART_ID_ATTR;
34 details.template = templatePart.getAttribute(PART_ATTR);
35 }
36 return details;
37 };
38