-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsol-demo.js
39 lines (35 loc) · 1.2 KB
/
sol-demo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
export class SolDemo extends HTMLElement {
constructor() {
super();
}
async connectedCallback(){
let nodes = Array.from(this.querySelectorAll('*'))
nodes = nodes.filter(n => n.tagName.toLowerCase().startsWith('sol-'));
this.innerHTML="";
for(let node of nodes){
const data = demo(node);
this.innerHTML += data;
}
}
}
customElements.define("sol-demo",SolDemo);
function demo(element){
let codeView = "";
let tagName = element.tagName || element.getAttribute('tagName');
codeView += `<<b>${tagName.toLowerCase()}</b>\n`;
for(let attr of element.attributes){
if(attr.name==='demo') continue;
if(attr.name==='class') continue;
if(attr.name==='style') continue;
codeView += ` <b>${attr.name}</b>="${attr.value}"\n`;
}
codeView += `></${tagName.toLowerCase()}>\n`;
codeView = codeView.replace(/=""/,'');
codeView = `
<div class="sol-codeview" style="margin-left:1.4rem;">
<pre style="background:#eef;padding:0.5rem;"><code>${codeView}</code></pre>
<div class="sol-codeResults" style="width:fit-content">${element.outerHTML}</div>
</div>
`;
return codeView;
}