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