PluginProbe
Extendify / 3.2.1
Extendify v3.2.1
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.2.1, at src/QuickEdit/lib/agent-block-descriptor.js

50 lines 1.8 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 import { detectBlockType } from '@quick-edit/lib/dom';
6
7 const AGENT_ATTR = 'data-extendify-agent-block-id';
8 const PART_ID_ATTR = 'data-extendify-part-block-id';
9 const PART_ATTR = 'data-extendify-part';
10 const PART_SLUG_ATTR = 'data-extendify-part-slug';
11
12 export const buildAgentBlockDescriptor = (match) => {
13 if (!match) return null;
14 const templatePart = match.closest?.(`[${PART_ATTR}]`);
15 const details = {
16 id: match.getAttribute(AGENT_ATTR),
17 target: AGENT_ATTR,
18 // local-pick + classify-block-edit gate on this; without it every edit
19 // falls through to find-agent.
20 blockType: detectBlockType(match),
21 hasNav:
22 !!match.querySelector('.wp-block-navigation') ||
23 match.classList.contains('wp-block-navigation'),
24 hasSiteTitle:
25 match.classList.contains('wp-block-site-title') ||
26 !!match.querySelector('.wp-block-site-title'),
27 hasSiteLogo:
28 match.classList.contains('wp-block-site-logo') ||
29 !!match.querySelector('.wp-block-site-logo'),
30 hasLinks: !!match.querySelector('a') || match.tagName === 'A',
31 hasImages:
32 !!match.querySelector('.wp-block-image') ||
33 match.classList.contains('wp-block-image') ||
34 !!match.querySelector('img'),
35 hasText: /\S/.test((match.textContent || '').replace(//g, '')),
36 };
37 if (templatePart) {
38 details.id = templatePart.getAttribute(PART_ID_ATTR);
39 details.target = PART_ID_ATTR;
40 details.template = templatePart.getAttribute(PART_ATTR);
41 // Part ids number their own space; without the scope the agent's read
42 // and save land on the page post's block of the same number.
43 details.source = {
44 kind: 'template-part',
45 partSlug: templatePart.getAttribute(PART_SLUG_ATTR) || '',
46 };
47 }
48 return details;
49 };
50