@@ -42,7 +42,12 @@ class DeclaritiveBaseCustomWebcomponent extends BaseCustomWebComponentNoAttached
4242 if ( this . properties [ 0 ] === '{' ) {
4343 const obj = JSON . parse ( this . properties ) ;
4444 for ( let i in obj ) {
45- props [ i ] = window [ obj [ i ] ] ;
45+ if ( typeof obj [ i ] === 'string' )
46+ props [ i ] = window [ obj [ i ] ] ;
47+ else {
48+ props [ i ] = obj [ i ] ;
49+ props [ i ] . type = obj [ i ] . type ? window [ obj [ i ] . type ] : String ;
50+ }
4651 }
4752 } else {
4853 props = this . properties . split ( / [ \s , ; ] + / ) . reduce ( ( a , v ) => ( { ...a , [ v ] : String } ) , { } ) ;
@@ -70,6 +75,20 @@ class DeclaritiveBaseCustomWebcomponent extends BaseCustomWebComponentNoAttached
7075 set ( newValue ) {
7176 if ( this [ '_' + p ] !== newValue ) {
7277 this [ '_' + p ] = newValue ;
78+
79+ if ( props [ p ] . reflect ) {
80+ if ( props [ p ] . type === Boolean ) {
81+ if ( newValue === true )
82+ this . setAttribute ( props [ p ] . attribute ?? camelToDashCase ( p ) , '' ) ;
83+ else
84+ this . removeAttribute ( props [ p ] . attribute ?? camelToDashCase ( p ) ) ;
85+ } else {
86+ if ( props [ p ] . type === Object || props [ p ] . type === Array )
87+ this . setAttribute ( props [ p ] . attribute ?? camelToDashCase ( p ) , JSON . stringify ( newValue ) ) ;
88+ else
89+ this . setAttribute ( props [ p ] . attribute ?? camelToDashCase ( p ) , newValue ) ;
90+ }
91+ }
7392 //@ts -ignore
7493 if ( this . constructor . _enableBindings )
7594 this . _bindingsRefresh ( p ) ;
@@ -98,4 +117,22 @@ class DeclaritiveBaseCustomWebcomponent extends BaseCustomWebComponentNoAttached
98117 }
99118}
100119
101- customElements . define ( "node-projects-dce" , DeclaritiveBaseCustomWebcomponent ) ;
120+ customElements . define ( "node-projects-dce" , DeclaritiveBaseCustomWebcomponent ) ;
121+
122+ /*
123+ <node-projects-dce name="simple-dce-demo" properties='{"list":"Array", "list2":"Array"}' enable-bindings >
124+ <template>
125+ <style>h1 {color: red}</style>
126+ <h1>Hello World</h1>
127+ <template repeat:myitem="[[this.list]]">
128+ <button>[[myitem.toUpperCase()]] - <b>[[myitem.toLowerCase()]]</b> - [[index]]</button>
129+ <ul>
130+ <template repeat:myitem2="[[this.list2]]" repeat-index="inneridx">
131+ <button>[[myitem.toUpperCase()]] - <b>[[myitem2.toLowerCase()]]</b> - [[inneridx * 100]]</button>
132+ </template>
133+ </ul>
134+ </template>
135+ </template>
136+ </node-projects-dce>
137+ <simple-dce-demo list='["aa","bb","cc"]' list2='["hello", "you"]' style="position:absolute;left:184px;top:-53px;"></simple-dce-demo>
138+ */
0 commit comments