applyBoundary method

  1. @override
void applyBoundary(
  1. ChildListRange range
)
override

Implementation

@override
void applyBoundary(ChildListRange range) {
  var curr = range.start.prev!;
  range.remove();
  var document = parse(template);
  var target = document.querySelector((element.component as TemplateDocument).attachTo)!;

  MarkupRenderObject? createTree(dom.Node node) {
    var n = element.parentRenderObjectElement!.renderObject.createChildRenderObject() as MarkupRenderObject;

    if (node is dom.Text) {
      if (node.text.trim().isEmpty) {
        return null;
      }
      n.updateText(node.text.trim(), true);
    } else if (node is dom.Comment) {
      n.updateText('<!--${node.data}-->', true);
    } else if (node is dom.Element) {
      n.updateElement(node.localName!, null, null, null, node.attributes.cast(), null);
    } else if (node is dom.DocumentType) {
      n.updateText(node.toString(), true);
    } else {
      throw UnsupportedError('Unsupported node type ${node.nodeType}');
    }

    if (node == target) {
      n.children.insertNodeAfter(range);
    } else {
      for (var c in node.nodes) {
        var o = createTree(c);
        if (o != null) {
          n.children.insertBefore(o);
        }
      }
    }

    return n;
  }

  for (var n in document.nodes) {
    var o = createTree(n);
    if (o != null) {
      var next = ChildNodeData(o);
      curr.insertNext(next);
      curr = next;
    }
  }
}