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)

graph LR detectCustomComponents["detectCustomComponents"] detectAllFields["detectAllFields"] detectAllFieldsAsync["detectAllFieldsAsync"] detectFormFields["detectFormFields"] makeField["makeField"] makeAdapter["makeAdapter"] detectAllFields -->|calls| detectCustomComponents detectAllFieldsAsync -->|calls| detectCustomComponents detectFormFields -->|calls| detectCustomComponents makeField -->|uses| detectCustomComponents makeAdapter -->|uses| detectCustomComponents style detectCustomComponents fill:#dbeafe,stroke:#2563eb,stroke-width:2px click detectCustomComponents "e93e9888463f9367.html" click detectAllFields "394718c982f136bb.html" click detectAllFieldsAsync "1b422b3353cdbe22.html" click detectFormFields "f533b30bd49ac06c.html" click makeField "a5977875ae7cda10.html" click makeAdapter "7cbe03be6bdb4b2d.html"