1+ import { BaseCustomWebComponentConstructorAppend , BaseCustomWebComponentNoAttachedTemplate , css } from "./BaseCustomWebComponent.js" ;
2+
3+ function camelToDashCase ( text : string ) {
4+ return text . replace ( / ( [ A - Z ] ) / g, ( g ) => `-${ g [ 0 ] . toLowerCase ( ) } ` ) ;
5+ }
6+
7+ class BaseDeclaritiveWebcomponent extends BaseCustomWebComponentConstructorAppend {
8+ constructor ( ) {
9+ super ( ) ;
10+ this . _bindingsParse ( null , true ) ;
11+ }
12+
13+ async connectedCallback ( ) {
14+ this . _parseAttributesToProperties ( ) ;
15+ this . _bindingsRefresh ( ) ;
16+ }
17+ }
18+
19+ class DeclaritiveBaseCustomWebcomponent extends BaseCustomWebComponentNoAttachedTemplate {
20+
21+ public static style = css `: host {dis play: none;}` ;
22+
23+ public name : string ;
24+ public enableBindings : boolean ;
25+ public properties : string ;
26+
27+ public static readonly properties = {
28+ name : String ,
29+ enableBindings : Boolean ,
30+ properties : String
31+ }
32+
33+ constructor ( ) {
34+ super ( ) ;
35+ this . _parseAttributesToProperties ( ) ;
36+ const template = this . querySelector ( 'template' ) ;
37+ let props = { } ;
38+ if ( this . properties ) {
39+ if ( this . properties [ 0 ] === '{' ) {
40+ const obj = JSON . parse ( this . properties ) ;
41+ for ( let i in obj ) {
42+ props [ i ] = window [ obj [ i ] ] ;
43+ }
44+ } else {
45+ props = this . properties . split ( / [ \s , ; ] + / ) . reduce ( ( a , v ) => ( { ...a , [ v ] : String } ) , { } ) ;
46+ }
47+ }
48+ const name = this . name ;
49+ window [ name ] = function ( ) {
50+ const instance = Reflect . construct ( BaseDeclaritiveWebcomponent , [ ] , window [ name ] ) ;
51+
52+ for ( let p in props ) {
53+ Object . defineProperty ( instance , p , {
54+ get ( ) {
55+ return this [ '_' + p ] ;
56+ } ,
57+ set ( newValue ) {
58+ if ( this [ '_' + p ] !== newValue ) {
59+ this [ '_' + p ] = newValue ;
60+ this . _bindingsRefresh ( p ) ;
61+ instance . dispatchEvent ( new CustomEvent ( camelToDashCase ( p ) + '-changed' , { detail : { newValue } } ) ) ;
62+ }
63+ } ,
64+ enumerable : true ,
65+ configurable : true ,
66+ } ) ;
67+ if ( props [ p ] . default ) {
68+ instance [ '_' + p ] = props [ p ] . default ;
69+ }
70+ }
71+ return instance ;
72+ }
73+
74+
75+ window [ name ] . template = template ;
76+ //window[name].style = style;
77+ window [ name ] . properties = props ;
78+ window [ name ] . _propertiesDictionary = null ;
79+ window [ name ] . prototype = Object . create ( BaseDeclaritiveWebcomponent . prototype , { constructor : { value : window [ name ] } } )
80+ if ( ! customElements . get ( name ) )
81+ customElements . define ( name , window [ name ] ) ;
82+ }
83+ }
84+
85+ customElements . define ( "node-projects-dce" , DeclaritiveBaseCustomWebcomponent ) ;
0 commit comments