buildExternalElement method

T? buildExternalElement(
  1. DOMElement? domParent,
  2. T? parent,
  3. ExternalElementNode domElement,
  4. DOMTreeMap<T> treeMap,
  5. DOMContext<T>? context,
)

Implementation

T? buildExternalElement(
    DOMElement? domParent,
    T? parent,
    ExternalElementNode domElement,
    DOMTreeMap<T> treeMap,
    DOMContext<T>? context) {
  if (domParent != null) {
    domElement.parent = domParent;
  }

  var externalElement = domElement.externalElement;

  if (!canHandleExternalElement(externalElement)) {
    var parsedElement = _parseExternalElement(
        domParent, parent, domElement, externalElement, treeMap, context);
    if (parsedElement != null) {
      if (parent != null && !containsNode(parent, parsedElement)) {
        addChildToElement(parent, parsedElement);
      }

      domElement.notifyElementGenerated(parsedElement);

      return parsedElement;
    }
  }

  if (parent != null) {
    var children = addExternalElementToElement(parent, externalElement);
    if (isEmptyObject(children)) return null;
    var node = children!.first;
    treeMap.map(domElement, node);

    domElement.notifyElementGenerated(node);

    return node;
  } else if (externalElement is T) {
    treeMap.map(domElement, externalElement);
    addChildToElement(parent, externalElement);

    domElement.notifyElementGenerated(externalElement);

    return externalElement;
  }

  return null;
}