buildField method presentation ✓ 94.4%

Last updated: 2026-03-04T23:21:38.384Z

Metrics

LOC: 61 Complexity: 25 Params: 1 Coverage: 94.4% (17/18 lines, 25x executed)

Signature

buildField(wrapper: HTMLElement): : FormField

Architecture violations

View all

  • [warning] max-cyclomatic-complexity: 'buildField' has cyclomatic complexity 25 (max 10)

Source Code

  buildField(wrapper: HTMLElement): FormField {
    const input = wrapper.querySelector<HTMLInputElement | HTMLTextAreaElement>(
      "input, textarea",
    );

    // ant-input-number always wraps a numeric spinbutton — classify it directly
    // so downstream classifiers never misidentify it as select or text.
    const isInputNumber = wrapper.classList.contains("ant-input-number");

    const nativeType =
      input instanceof HTMLInputElement ? input.type : undefined;
    const autocomplete =
      input instanceof HTMLInputElement
        ? (input.getAttribute("autocomplete") ?? undefined)
        : undefined;

    // Only resolve fieldType for unambiguous native HTML types (confidence 1.0).
    // Everything else stays "unknown" so TF.js / keyword / Chrome-AI classifiers
    // can use contextSignals (label + name + placeholder + autocomplete) properly.
    const resolvedFieldType = ((): FormField["fieldType"] => {
      if (isInputNumber) return "number";
      if (nativeType === "email") return "email";
      if (nativeType === "tel") return "phone";
      if (nativeType === "url") return "website";
      if (nativeType === "password") return "password";
      if (nativeType === "number") return "number";
      if (nativeType === "date") return "date";
      if (
        nativeType &&
        ["time", "datetime-local", "month", "week"].includes(nativeType)
      )
        return "date";
      return "unknown";
    })();

    const field: FormField = {
      element: wrapper,
      selector: getAntdSelector(wrapper),
      category: "unknown",
      fieldType: resolvedFieldType,
      adapterName: "antd-input",
      label: findAntLabel(wrapper),
      name: findAntName(wrapper) ?? input?.name ?? undefined,
      id: findAntId(wrapper) ?? input?.id ?? undefined,
      placeholder: input?.placeholder || undefined,
      // Expose autocomplete so buildSignals includes it in contextSignals,
      // giving TF.js / keyword classifier a strong classification signal.
      autocomplete: autocomplete || undefined,
      required: isAntRequired(wrapper),
      inputType: nativeType,
      pattern:
        input instanceof HTMLInputElement && input.pattern
          ? input.pattern
          : undefined,
      maxLength: input && input.maxLength > 0 ? input.maxLength : undefined,
      minLength: input && input.minLength > 0 ? input.minLength : undefined,
    };

    field.contextSignals = buildSignals(field);
    return field;
  },

Dependencies (Outgoing)

graph LR buildField["buildField"] getAntdSelector["getAntdSelector"] findAntLabel["findAntLabel"] findAntName["findAntName"] findAntId["findAntId"] isAntRequired["isAntRequired"] buildField -->|calls| getAntdSelector buildField -->|calls| findAntLabel buildField -->|calls| findAntName buildField -->|calls| findAntId buildField -->|calls| isAntRequired style buildField fill:#dbeafe,stroke:#2563eb,stroke-width:2px click buildField "a7124eb38369f9ed.html" click getAntdSelector "707eae1ed4437c8e.html" click findAntLabel "4446526a4a01afd7.html" click findAntName "5e51cc1f95724859.html" click findAntId "5d7c366d4d585434.html" click isAntRequired "909385c51f5eb930.html"
TargetType
getAntdSelector calls
findAntLabel calls
findAntName calls
findAntId calls
isAntRequired calls

No incoming dependencies.