11import { h , cloneElement , render , hydrate } from 'preact' ;
22
3- export default function register ( Component , tagName , propNames ) {
3+ export default function register ( Component , tagName , propNames , options ) {
44 function PreactElement ( ) {
55 const inst = Reflect . construct ( HTMLElement , [ ] , PreactElement ) ;
66 inst . _vdomComponent = Component ;
7+ inst . _root = options && options . shadow ? inst . attachShadow ( { mode : 'open' } ) : inst ;
78 return inst ;
89 }
910 PreactElement . prototype = Object . create ( HTMLElement . prototype ) ;
@@ -21,19 +22,19 @@ export default function register(Component, tagName, propNames) {
2122
2223function connectedCallback ( ) {
2324 this . _vdom = toVdom ( this , this . _vdomComponent ) ;
24- ( this . hasAttribute ( 'hydrate' ) ? hydrate : render ) ( this . _vdom , this ) ;
25+ ( this . hasAttribute ( 'hydrate' ) ? hydrate : render ) ( this . _vdom , this . _root ) ;
2526}
2627
2728function attributeChangedCallback ( name , oldValue , newValue ) {
2829 if ( ! this . _vdom ) return ;
2930 const props = { } ;
3031 props [ name ] = newValue ;
3132 this . _vdom = cloneElement ( this . _vdom , props ) ;
32- render ( this . _vdom , this ) ;
33+ render ( this . _vdom , this . _root ) ;
3334}
3435
3536function detachedCallback ( ) {
36- render ( this . _vdom = null , this ) ;
37+ render ( this . _vdom = null , this . _root ) ;
3738}
3839
3940function toVdom ( element , nodeName ) {
0 commit comments