feat(dart/transform): Implement `Html5LibDomAdapter` methods.
Adding support for some additional `DomAdapter` methods necessary to run `Complier` in the Dart transformer.
This commit is contained in:
parent
1676e3161b
commit
5d502d4093
|
@ -28,8 +28,7 @@ class BrowserDomAdapter extends GenericBrowserDomAdapter {
|
|||
|
||||
query(String selector) => document.querySelector(selector);
|
||||
|
||||
Element querySelector(el, String selector) =>
|
||||
el.querySelector(selector);
|
||||
Element querySelector(el, String selector) => el.querySelector(selector);
|
||||
|
||||
ElementList querySelectorAll(el, String selector) =>
|
||||
el.querySelectorAll(selector);
|
||||
|
@ -44,8 +43,7 @@ class BrowserDomAdapter extends GenericBrowserDomAdapter {
|
|||
}
|
||||
MouseEvent createMouseEvent(String eventType) =>
|
||||
new MouseEvent(eventType, canBubble: true);
|
||||
createEvent(eventType) =>
|
||||
new Event(eventType, canBubble: true);
|
||||
createEvent(eventType) => new Event(eventType, canBubble: true);
|
||||
String getInnerHTML(Element el) => el.innerHtml;
|
||||
String getOuterHTML(Element el) => el.outerHtml;
|
||||
void setInnerHTML(Element el, String value) {
|
||||
|
@ -134,19 +132,19 @@ class BrowserDomAdapter extends GenericBrowserDomAdapter {
|
|||
element.classes.add(classname);
|
||||
}
|
||||
void removeClass(Element element, String classname) {
|
||||
element.classes.remove(classname);
|
||||
element.classes.remove(classname);
|
||||
}
|
||||
bool hasClass(Element element, String classname) =>
|
||||
element.classes.contains(classname);
|
||||
|
||||
setStyle(Element element, String stylename, String stylevalue) {
|
||||
element.style.setProperty(stylename, stylevalue);
|
||||
element.style.setProperty(stylename, stylevalue);
|
||||
}
|
||||
removeStyle(Element element, String stylename) {
|
||||
element.style.removeProperty(stylename);
|
||||
element.style.removeProperty(stylename);
|
||||
}
|
||||
getStyle(Element element, String stylename) {
|
||||
return element.style.getPropertyValue(stylename);
|
||||
return element.style.getPropertyValue(stylename);
|
||||
}
|
||||
|
||||
String tagName(Element element) => element.tagName;
|
||||
|
@ -163,13 +161,12 @@ class BrowserDomAdapter extends GenericBrowserDomAdapter {
|
|||
}
|
||||
|
||||
void removeAttribute(Element element, String name) {
|
||||
//there is no removeAttribute method as of now in Dart:
|
||||
//https://code.google.com/p/dart/issues/detail?id=19934
|
||||
element.attributes.remove(name);
|
||||
//there is no removeAttribute method as of now in Dart:
|
||||
//https://code.google.com/p/dart/issues/detail?id=19934
|
||||
element.attributes.remove(name);
|
||||
}
|
||||
|
||||
Node templateAwareRoot(Element el) =>
|
||||
el is TemplateElement ? el.content : el;
|
||||
Node templateAwareRoot(Element el) => el is TemplateElement ? el.content : el;
|
||||
|
||||
HtmlDocument createHtmlDocument() =>
|
||||
document.implementation.createHtmlDocument('fakeTitle');
|
||||
|
@ -181,13 +178,10 @@ class BrowserDomAdapter extends GenericBrowserDomAdapter {
|
|||
}
|
||||
bool elementMatches(n, String selector) =>
|
||||
n is Element && n.matches(selector);
|
||||
bool isTemplateElement(Element el) =>
|
||||
el is TemplateElement;
|
||||
bool isTextNode(Node node) =>
|
||||
node.nodeType == Node.TEXT_NODE;
|
||||
bool isTemplateElement(Element el) => el is TemplateElement;
|
||||
bool isTextNode(Node node) => node.nodeType == Node.TEXT_NODE;
|
||||
bool isCommentNode(Node node) => node.nodeType == Node.COMMENT_NODE;
|
||||
bool isElementNode(Node node) =>
|
||||
node.nodeType == Node.ELEMENT_NODE;
|
||||
bool isElementNode(Node node) => node.nodeType == Node.ELEMENT_NODE;
|
||||
bool hasShadowRoot(Node node) {
|
||||
return node is Element && node.shadowRoot != null;
|
||||
}
|
||||
|
|
|
@ -40,9 +40,7 @@ class Html5LibDomAdapter implements DomAdapter {
|
|||
String nodeName(node) {
|
||||
throw 'not implemented';
|
||||
}
|
||||
String nodeValue(node) {
|
||||
throw 'not implemented';
|
||||
}
|
||||
String nodeValue(node) => node.data;
|
||||
String type(node) {
|
||||
throw 'not implemented';
|
||||
}
|
||||
|
@ -50,9 +48,7 @@ class Html5LibDomAdapter implements DomAdapter {
|
|||
throw 'not implemented';
|
||||
}
|
||||
|
||||
firstChild(el) => el is NodeList
|
||||
? el.first
|
||||
: el.firstChild;
|
||||
firstChild(el) => el is NodeList ? el.first : el.firstChild;
|
||||
|
||||
nextSibling(el) {
|
||||
final parentNode = el.parentNode;
|
||||
|
@ -68,12 +64,8 @@ class Html5LibDomAdapter implements DomAdapter {
|
|||
parentElement(el) {
|
||||
throw 'not implemented';
|
||||
}
|
||||
List childNodes(el) {
|
||||
throw 'not implemented';
|
||||
}
|
||||
List childNodesAsList(el) {
|
||||
throw 'not implemented';
|
||||
}
|
||||
List childNodes(el) => el.nodes;
|
||||
List childNodesAsList(el) => el.nodes;
|
||||
clearNodes(el) {
|
||||
throw 'not implemented';
|
||||
}
|
||||
|
@ -101,9 +93,8 @@ class Html5LibDomAdapter implements DomAdapter {
|
|||
getText(el) {
|
||||
throw 'not implemented';
|
||||
}
|
||||
setText(el, String value) {
|
||||
throw 'not implemented';
|
||||
}
|
||||
setText(el, String value) => el.text = value;
|
||||
|
||||
getValue(el) {
|
||||
throw 'not implemented';
|
||||
}
|
||||
|
@ -116,10 +107,7 @@ class Html5LibDomAdapter implements DomAdapter {
|
|||
setChecked(el, bool value) {
|
||||
throw 'not implemented';
|
||||
}
|
||||
createTemplate(html) {
|
||||
return createElement('template')
|
||||
..innerHtml = html;
|
||||
}
|
||||
createTemplate(html) => createElement('template')..innerHtml = html;
|
||||
createElement(tagName, [doc]) {
|
||||
return new Element.tag(tagName);
|
||||
}
|
||||
|
@ -154,8 +142,7 @@ class Html5LibDomAdapter implements DomAdapter {
|
|||
throw 'not implemented';
|
||||
}
|
||||
|
||||
hasClass(element, String classname) =>
|
||||
element.classes.contains(classname);
|
||||
hasClass(element, String classname) => element.classes.contains(classname);
|
||||
|
||||
setStyle(element, String stylename, String stylevalue) {
|
||||
throw 'not implemented';
|
||||
|
@ -169,7 +156,14 @@ class Html5LibDomAdapter implements DomAdapter {
|
|||
|
||||
String tagName(element) => element.localName;
|
||||
|
||||
attributeMap(element) => element.attributes;
|
||||
attributeMap(element) {
|
||||
// `attributes` keys can be [AttributeName]s.
|
||||
var map = <String, String>{};
|
||||
element.attributes.forEach((key, value) {
|
||||
map['$key'] = value;
|
||||
});
|
||||
return map;
|
||||
}
|
||||
getAttribute(element, String attribute) {
|
||||
throw 'not implemented';
|
||||
}
|
||||
|
@ -180,9 +174,7 @@ class Html5LibDomAdapter implements DomAdapter {
|
|||
throw 'not implemented';
|
||||
}
|
||||
|
||||
templateAwareRoot(el) => isTemplateElement(el)
|
||||
? el.nodes
|
||||
: el;
|
||||
templateAwareRoot(el) => el;
|
||||
|
||||
createHtmlDocument() {
|
||||
throw 'not implemented';
|
||||
|
@ -199,14 +191,10 @@ class Html5LibDomAdapter implements DomAdapter {
|
|||
bool isTemplateElement(Element el) {
|
||||
return el != null && el.localName.toLowerCase() == 'template';
|
||||
}
|
||||
bool isTextNode(node) {
|
||||
throw 'not implemented';
|
||||
}
|
||||
bool isCommentNode(node) {
|
||||
throw 'not implemented';
|
||||
}
|
||||
bool isTextNode(node) => node.nodeType == Node.TEXT_NODE;
|
||||
bool isCommentNode(node) => node.nodeType == Node.COMMENT_NODE;
|
||||
|
||||
bool isElementNode(node) => node is Element;
|
||||
bool isElementNode(node) => node.nodeType == Node.ELEMENT_NODE;
|
||||
|
||||
bool hasShadowRoot(node) {
|
||||
throw 'not implemented';
|
||||
|
|
Loading…
Reference in New Issue