File tree Expand file tree Collapse file tree 1 file changed +17
-7
lines changed
Expand file tree Collapse file tree 1 file changed +17
-7
lines changed Original file line number Diff line number Diff line change 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
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 }
32293241 }
32303242}
32313243customElements . define ( 'xr-site' , XRSite ) ;
3232- const root = document . getElementById ( 'root ') ;
3244+ const root = document . querySelector ( 'xr-site ') ;
32333245
32343246const uiSize = 2048 ;
32353247let renderIds = 0 ;
35993611 root . removeChild ( root . firstChild ) ;
36003612 }
36013613 } else if ( id === 'action-copy-scene' ) {
3602- const s = html_beautify ( root . outerHTML . replace ( / ^ ( < x r - s i t e ) i d = " r o o t " / , '$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 }
You can’t perform that action at this time.
0 commit comments