by Wilson Page
(complexity + highLevel) === vendor.contention
No easy task!
Everyone agrees we need them
Couple of things to iron out...
HTMLElement
-> MyAwesomeElement
var el = document.querySelector('my-awesome-element');
el.constructor.name; //=> 'HTMLElement';
document.registerElement('my-awesome-element', ...);
el.constructor.name; //=> 'my-awesome-element';
var proto = Object.create(HTMLElement.prototype);
proto.createdCallback = function() { ... };
document.registerElement('x-foo', { prototype: proto });
There are five new proposals
class MyEl extends HTMLElement {
constructor() { ... }
}
class MyEl extends HTMLElement {
createdCallback() { ... }
}
document.registerElement('my-el', MyEl);
class MyEl extends HTMLElement {
constructor() { ... }
}
.cloneNode()
registerElement()
must run before parseclass MyEl extends HTMLElement {
createdCallback() { ... }
}
is
<input type="text" is="my-text-input">
Google wants it as a stop-gap
Mozilla and Apple want to ship quicker without polluting the platform
Focus on a better solution in a 'V2'
(the difficult part)
The projection of the host's content
into the shadow root
<content select="header"></content>
var shadow = host.createShadowRoot({
distribute: function(nodes) {
var slot = shadow.querySelector('content');
for (var i = 0; i < nodes.length; i++) {
slot.add(nodes[i]);
}
}
});
shadow.innerHTML = ' ';
// Call initially ...
shadow.distribute();
// then hook up to MutationObserver
myHost.appendChild(someElement);
someElement.offsetTop; //=> old value
// distribute on mutation observer callback (async)
someElement.offsetTop; //=> new value
Work on imperative API until July 2015
If impossible, back to declarative API negotiations
Open: el.shadowRoot.querySelector('.secrets')
Closed: el.shadowRoot === null
element.createShadowRoot({ mode: 'open' });
element.createShadowRoot({ mode: 'closed' });
We need the mode
feature
Parameter required, so no default value
x-foo /deep/ div { color: red }
x-foo::shadow div { color: red }
x-foo >>> div { color: red }
x-foo {
--background-color: red;
--something-else: black;
}
.internal-thing { background: var(--background-color); }
.other-bit { color: var(--something-else); }
@extend
.x-foo-part {
background-color: red;
border-radius: 4px;
}
.internal-part {
@extend .x-foo-part;
}
input[type=range]::-moz-range-thumb { ... }
x-foo::my-internal-part { ... }
Drop all piercing combinators (/deep/
et al)
My title
Some details
foo
var XDialog = require('x-dialog');
var proto = Object.create(XDialog.prototype);
proto.createdCallback = function() {
XDialog.prototype.createdCallback.call(this);
this.createShadowRoot(); // <= 2nd shadow root
this.shadowRoot.innerHTML = someHTML;
};
document.registerElement('x-dialog-alert', {
prototype: proto
});
Alert
Multiple shadow roots not part of 'V1'
var proto = Object.create(XDialog.prototype);
proto.createdCallback = function() {
XDialog.prototype.createdCallback.call(this);
var inner = this.shadowRoot.querySelector('.inner');
var h1 = document.createElement('h1');
h1.textContent = 'Alert';
inner.insertBefore(h1, inner.children[0]);
var button = document.createElement('button');
button.textContent = 'OK';
inner.appendChild(button);
...
};
document.registerElement('x-dialog-alert', {
prototype: proto
});
'closed'