File: //home/ksonpoau/www/wp-content/plugins/extendify/src/QuickEdit/lib/agent-block-descriptor.js
// Single source for the agent-block selection-descriptor shape so
// DOMHighlighter's click commit and ask-ai's pill click can't drift on
// which metadata flags exist or how they're detected.
const AGENT_ATTR = 'data-extendify-agent-block-id';
const PART_ID_ATTR = 'data-extendify-part-block-id';
const PART_ATTR = 'data-extendify-part';
export const buildAgentBlockDescriptor = (match) => {
if (!match) return null;
const templatePart = match.closest?.(`[${PART_ATTR}]`);
const details = {
id: match.getAttribute(AGENT_ATTR),
target: AGENT_ATTR,
hasNav:
!!match.querySelector('.wp-block-navigation') ||
match.classList.contains('wp-block-navigation'),
hasSiteTitle:
match.classList.contains('wp-block-site-title') ||
!!match.querySelector('.wp-block-site-title'),
hasSiteLogo:
match.classList.contains('wp-block-site-logo') ||
!!match.querySelector('.wp-block-site-logo'),
hasLinks: !!match.querySelector('a') || match.tagName === 'A',
hasImages:
!!match.querySelector('.wp-block-image') ||
match.classList.contains('wp-block-image') ||
!!match.querySelector('img'),
hasText: /\S/.test((match.textContent || '').replace(//g, '')),
};
if (templatePart) {
details.id = templatePart.getAttribute(PART_ID_ATTR);
details.target = PART_ID_ATTR;
details.template = templatePart.getAttribute(PART_ATTR);
}
return details;
};