Skip to content

Commit 4d610c9

Browse files
author
Avaer Kazmer
committed
Clean up xr-site root element
1 parent b3a8308 commit 4d610c9

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

app.html

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<script src="file-type.js"></script>
2222
</head>
2323
<body>
24-
<xr-site id=root></xr-site>
24+
<xr-site></xr-site>
2525
<script type=module>
2626
(async () => {
2727

@@ -3180,6 +3180,18 @@
31803180
childList: true,
31813181
});
31823182
}
3183+
getHTML() {
3184+
return html_beautify(this.outerHTML);
3185+
}
3186+
setHTML(htmlString) {
3187+
const dom = new DOMParser().parseFromString(htmlString, 'text/html');
3188+
if (dom.body.childNodes.length === 1 && dom.body.childNodes[0].nodeName === 'XR-SITE') {
3189+
this.innerHTML = dom.body.childNodes[0].innerHTML;
3190+
return true;
3191+
} else {
3192+
return false;
3193+
}
3194+
}
31833195
update() {
31843196
this.handleMutations(this.observer.takeRecords());
31853197
}
@@ -3229,7 +3241,7 @@
32293241
}
32303242
}
32313243
customElements.define('xr-site', XRSite);
3232-
const root = document.getElementById('root');
3244+
const root = document.querySelector('xr-site');
32333245

32343246
const uiSize = 2048;
32353247
let renderIds = 0;
@@ -3599,16 +3611,14 @@
35993611
root.removeChild(root.firstChild);
36003612
}
36013613
} else if (id === 'action-copy-scene') {
3602-
const s = html_beautify(root.outerHTML.replace(/^(<xr-site) id="root"/, '$1'));
3614+
const s = root.getHTML();
36033615
console.log('copy', s);
36043616
clipboard.copy(s);
36053617
} else if (id === 'action-paste-scene') {
36063618
const s = await clipboard.paste();
3607-
const dom = new DOMParser().parseFromString(s, 'text/html');
3608-
console.log('paste', s, dom.body.childNodes[0].nodeName);
3609-
if (dom.body.childNodes.length === 1 && dom.body.childNodes[0].nodeName === 'XR-SITE') {
3619+
console.log('paste', s);
3620+
if (root.setHTML(s)) {
36103621
console.log('paste ok');
3611-
root.innerHTML = dom.body.childNodes[0].innerHTML;
36123622
} else {
36133623
console.log('paste fail');
36143624
}

0 commit comments

Comments
 (0)