moved slotting to compile step

pull/4348/head
Cris Ward 6 years ago
parent 2a48105463
commit d032451b87

@ -484,6 +484,68 @@ export default function dom(
});
}
if(lightDom){
declaration.body.body.push({
type: 'MethodDefinition',
kind: 'method',
static: false,
computed: false,
key: { type: 'Identifier', name: '_copycontent' },
value: x`function() {
if(this.children){
this._content = Array.from(this.childNodes)
while (this.firstChild) {
this.removeChild(this.firstChild)
}
}
}` as FunctionExpression
});
declaration.body.body.push({
type: 'MethodDefinition',
kind: 'method',
static: false,
computed: false,
key: { type: 'Identifier', name: '_slotcontent' },
value: x`function() {
if(this.slotting) return; // prevent running in parallel
this.slotting = true;
if(this._content){
let namedslots = Array.from(this.querySelectorAll("slot[name]"))
let defaultslot = this.querySelector("slot:not([name])")
let named = {}
if(!namedslots.length && !defaultslot) return(this.slotting=false);
let slotted = []
this._content.filter((node)=> node.slot ).forEach((node)=> named[node.slot] = node )
namedslots.forEach(slot =>{
this._content.forEach(node =>{ //append all named slots
if(named[node.slot] && slot.getAttribute("name") == node.slot){
if(!slot.hasAttribute("hasupdated")){
slot.appendChild(named[node.slot]);
slot.setAttribute("hasupdated","")
}
slotted.push(node)
}
})
})
if(!defaultslot) return(this.slotting=false);
// put what evers left info default slot
this._content
.filter(node => slotted.indexOf(node)==-1)
.forEach(node => {
if(!defaultslot.hasAttribute("hasupdated")){
defaultslot.appendChild(node)
}
})
defaultslot.setAttribute("hasupdated","")
}
this.slotting = false
}
}` as FunctionExpression
});
}
declaration.body.body.push(...accessors);
body.push(declaration);

@ -179,51 +179,6 @@ if (typeof HTMLElement === 'function') {
}
}
_copycontent(){
if(this.children){
this._content = Array.from(this.childNodes)
while (this.firstChild) {
this.removeChild(this.firstChild)
}
}
}
_slotcontent(){
if(this.slotting) return;
this.slotting = true;
if(this._content){
let namedslots = Array.from(this.querySelectorAll("slot[name]"))
let defaultslot = this.querySelector("slot:not([name])")
let named = {}
if(!namedslots.length && !defaultslot) return(this.slotting=false);
let slotted = []
this._content.filter((node : HTMLElement)=> node.slot ).forEach((node : HTMLElement)=> named[node.slot] = node )
namedslots.forEach(slot =>{
this._content.forEach(node =>{ //append all named slots
if(named[node.slot] && slot.getAttribute("name")==node.slot){
if(!slot.hasAttribute("hasupdated")){
slot.appendChild(named[node.slot]);
slot.setAttribute("hasupdated","")
}
slotted.push(node)
}
})
})
if(!defaultslot) return(this.slotting=false);
// put what evers left info default slot
this._content
.filter(node => slotted.indexOf(node)==-1)
.forEach(node => {
if(!defaultslot.hasAttribute("hasupdated")){
defaultslot.appendChild(node)
}
})
defaultslot.setAttribute("hasupdated","")
}
this.slotting = false
}
attributeChangedCallback(attr, _oldValue, newValue) {
this[attr] = newValue;
}

Loading…
Cancel
Save