11import { LitElement , html } from '../../../../web_modules/lit-element.js'
2- import { cssStringToHexNumber , hexNumberToCSSString } from '../../utils.js' ;
2+ import { getEntityName , cssStringToHexNumber , hexNumberToCSSString } from '../../utils.js' ;
33
44const $onChange = Symbol ( 'onChange' ) ;
5+ const $onDependencyClick = Symbol ( 'onDependencyClick' ) ;
56const anchor = document . createElement ( 'a' ) ;
67let kvIterator = 0 ;
78
@@ -20,6 +21,8 @@ export default class KeyValueElement extends LitElement {
2021 max : { type : Number , reflect : true } ,
2122 step : { type : Number , reflect : true } ,
2223 precision : { type : Number , reflect : true } ,
24+ // Optional data for data types (material, geometry)
25+ data : { type : Object } ,
2326 }
2427 }
2528
@@ -55,70 +58,71 @@ export default class KeyValueElement extends LitElement {
5558
5659 let valueElement ;
5760
58- switch ( this . type ) {
59- case 'array' :
60- if ( this . value ) {
61- valueElement = html `
62- < a href ="# " @click =${ e => this . onDataURLClick ( e ) } >
63- array
64- </ a > ` ;
65- }
66- else {
67- valueElement = html `[]` ;
68- }
69- break ;
70- case 'enum' :
71- valueElement = html `< enum-value .uuid ="${ this . uuid } " .type ="${ this . property } " .value ="${ this . value } "> </ enum-value > ` ;
72- break ;
73- case 'vec2' :
74- case 'vec3' :
75- case 'vec4' :
76- const arity = this . type === 'vec2' ? 2 :
77- this . type === 'vec3' ? 3 : 4 ;
78- valueElement = [ ...new Array ( arity ) ] . map ( ( _ , i ) => html `< number-input
79- .id ="${ i === 0 ? this . _id : '' } "
80- axis ="${ i === 0 ? 'x' : i === 1 ? 'y' : i === 2 ? 'z' : 'w' } "
81- .value ="${ this . value [ i ] } "
82- .min ="${ this . min } "
83- .max ="${ this . max } "
84- .step ="${ this . step } "
85- .precision ="${ this . precision } "
86- /> ` ) ;
87- break ;
88- case 'image' :
89- valueElement = html `< image-value .uuid ="${ this . value } "> </ image-value > ` ;
90- break ;
91- case 'texture' :
92- valueElement = html `< texture-value .uuid ="${ this . value } "> </ texture-value > ` ;
93- break ;
94- case 'material' :
95- valueElement = html `< material-value .uuid ="${ this . value } "> </ material-value > ` ;
96- break ;
97- case 'geometry' :
98- valueElement = html `< geometry-value .uuid ="${ this . value } "> </ geometry-value > ` ;
99- break ;
100- case 'color' :
101- valueElement = html `< input id ="${ this . _id } " type ="color " .value ="${ hexNumberToCSSString ( + this . value ) } " /> ` ;
102- break ;
103- case 'boolean' :
104- valueElement = html `< input id ="${ this . _id } " type ="checkbox " .checked ="${ this . value } " /> ` ;
105- break ;
106- case 'number' :
107- case 'int' :
108- valueElement = html `< number-input
109- .id ="${ this . _id } "
110- .value ="${ this . value } "
111- .min ="${ this . min } "
112- .max ="${ this . max } "
113- .step ="${ this . step } "
114- .precision ="${ this . precision } "
115- /> ` ;
116- break ;
117- case 'string' :
118- valueElement = this . value ;
119- break ;
120- default :
121- valueElement = this . value ;
61+ if ( this . value == null ) {
62+ valueElement = html `` ;
63+ } else {
64+ switch ( this . type ) {
65+ case 'array' :
66+ if ( this . value ) {
67+ valueElement = html `
68+ < a href ="# " @click =${ e => this . onDataURLClick ( e ) } >
69+ array
70+ </ a > ` ;
71+ }
72+ else {
73+ valueElement = html `[]` ;
74+ }
75+ break ;
76+ case 'enum' :
77+ valueElement = html `< enum-value .uuid ="${ this . uuid } " .type ="${ this . property } " .value ="${ this . value } "> </ enum-value > ` ;
78+ break ;
79+ case 'vec2' :
80+ case 'vec3' :
81+ case 'vec4' :
82+ const arity = this . type === 'vec2' ? 2 :
83+ this . type === 'vec3' ? 3 : 4 ;
84+ valueElement = [ ...new Array ( arity ) ] . map ( ( _ , i ) => html `< number-input
85+ .id ="${ i === 0 ? this . _id : '' } "
86+ axis ="${ i === 0 ? 'x' : i === 1 ? 'y' : i === 2 ? 'z' : 'w' } "
87+ .value ="${ this . value [ i ] } "
88+ .min ="${ this . min } "
89+ .max ="${ this . max } "
90+ .step ="${ this . step } "
91+ .precision ="${ this . precision } "
92+ /> ` ) ;
93+ break ;
94+ case 'image' :
95+ case 'texture' :
96+ case 'material' :
97+ case 'geometry' :
98+ if ( this . data ) {
99+ const name = getEntityName ( this . data ) ;
100+ valueElement = html `< div class ="badge " data-uuid ="${ this . value } " @click ="${ this [ $onDependencyClick ] } "> ${ name } </ div > ` ;
101+ }
102+ break ;
103+ case 'color' :
104+ valueElement = html `< input id ="${ this . _id } " type ="color " .value ="${ hexNumberToCSSString ( + this . value ) } " /> ` ;
105+ break ;
106+ case 'boolean' :
107+ valueElement = html `< input id ="${ this . _id } " type ="checkbox " .checked ="${ this . value } " /> ` ;
108+ break ;
109+ case 'number' :
110+ case 'int' :
111+ valueElement = html `< number-input
112+ .id ="${ this . _id } "
113+ .value ="${ this . value } "
114+ .min ="${ this . min } "
115+ .max ="${ this . max } "
116+ .step ="${ this . step } "
117+ .precision ="${ this . precision } "
118+ /> ` ;
119+ break ;
120+ case 'string' :
121+ valueElement = this . value ;
122+ break ;
123+ default :
124+ valueElement = this . value ;
125+ }
122126 }
123127
124128 return html `
@@ -153,6 +157,7 @@ export default class KeyValueElement extends LitElement {
153157 padding-left : var (--key-value-padding-left , 10px );
154158 }
155159
160+ # value
156161 # value [type = "vec4" ] number-input {
157162 width : 25% ;
158163 }
@@ -162,6 +167,10 @@ export default class KeyValueElement extends LitElement {
162167 # value [type = "vec2" ] number-input {
163168 width : 50% ;
164169 }
170+ .badge {
171+ background-color : var (--tab-selected-bg-color );
172+ padding : 1px 5px ;
173+ }
165174
166175</ style >
167176< label for ="${ this . _id } "> ${ this . keyName } </ label >
@@ -171,6 +180,20 @@ export default class KeyValueElement extends LitElement {
171180` ;
172181 }
173182
183+ [ $onDependencyClick ] ( e ) {
184+ const target = e . composedPath ( ) [ 0 ] ;
185+ const uuid = target . getAttribute ( 'data-uuid' ) ;
186+ if ( uuid !== null ) {
187+ this . dispatchEvent ( new CustomEvent ( 'command' , { detail : {
188+ type : 'select-entity' ,
189+ uuid,
190+ } ,
191+ bubbles : true ,
192+ composed : true ,
193+ } ) ) ;
194+ }
195+ }
196+
174197 [ $onChange ] ( e ) {
175198
176199 const target = e . composedPath ( ) [ 0 ] ;
0 commit comments