detectCustomComponents function presentation exported ✓ 100.0%
Last updated: 2026-03-04T23:21:38.378Z
Metrics
LOC: 29
Complexity: 7
Params: 0
Coverage: 100.0% (16/16 lines, 5x executed)
Signature
detectCustomComponents(): : FormField[]
Summary
Scans the page for all custom components across registered adapters. Returns FormField stubs (fieldType = "unknown") ready for classification. Each element is claimed by the first matching adapter only (no duplicates).
Source Code
export function detectCustomComponents(): FormField[] {
if (ADAPTER_REGISTRY.length === 0) return [];
const claimed = new WeakSet<HTMLElement>();
const fields: FormField[] = [];
for (const adapter of ADAPTER_REGISTRY) {
const candidates = document.querySelectorAll<HTMLElement>(adapter.selector);
for (const el of candidates) {
if (claimed.has(el)) continue;
if (!adapter.matches(el)) continue;
claimed.add(el);
try {
const field = adapter.buildField(el);
fields.push(field);
log.debug(`[${adapter.name}] campo detectado: ${field.selector}`);
} catch (err) {
log.warn(`[${adapter.name}] Erro ao construir campo:`, err);
}
}
}
log.info(`${fields.length} componente(s) customizado(s) detectado(s)`);
return fields;
}
No outgoing dependencies.
Impact (Incoming)
| Source | Type |
|---|---|
| detectAllFields | calls |
| detectAllFieldsAsync | calls |
| detectFormFields | calls |
| makeField | uses |
| makeAdapter | uses |