44 </template >
55 <template v-else >
66 <div :class =" css" >
7- <input
8- type =" text"
9- ref =" editEl"
10- @click.stop
11- @focus =" onFocus"
12- @blur =" onBlur"
13- @mousedown.stop =" onMouseDown"
14- @keydown.enter =" onSubmit"
15- @keydown.esc =" onCancel" >
7+ <template v-if =" isEnumType " >
8+ <dropdown
9+ class =" enum-field-dropdown"
10+ :items =" enumItems"
11+ :auto_select_first =" false"
12+ v-model:active_item =" localValue"
13+ @update:active_item =" onEnumSelect"
14+ @click.stop >
15+ </dropdown >
16+ </template >
17+ <template v-else >
18+ <input
19+ type =" text"
20+ ref =" editEl"
21+ @click.stop
22+ @focus =" onFocus"
23+ @blur =" onBlur"
24+ @mousedown.stop =" onMouseDown"
25+ @keydown.enter =" onSubmit"
26+ @keydown.esc =" onCancel" >
27+ </template >
1628 </div >
1729 </template >
1830</template >
@@ -53,6 +65,9 @@ let dragging = {
5365const css = computed (() => {
5466 let classes = [" input-wrapper" , props .class ];
5567 classes .push (` value-${ props .type [0 ]} ` );
68+ if (isEnumType .value ) {
69+ classes .push (" value-dropdown" );
70+ }
5671
5772 if (props .readonly ) {
5873 classes .push (` ${ props .class } -readonly` );
@@ -68,8 +83,20 @@ const isNumberType = computed(() => {
6883 return props .type [0 ] === " float" || props .type [0 ] === " int" ;
6984});
7085
86+ const isEnumType = computed (() => {
87+ return Array .isArray (props .type ) && props .type [0 ] === " enum" ;
88+ });
89+
90+ const enumItems = computed (() => {
91+ if (! isEnumType .value ) {
92+ return [];
93+ }
94+ return props .type .slice (1 ).filter ((item ) => typeof item === " string" );
95+ });
96+
7197const unit = computed (() => {
72- if (props .type .length > 1 ) {
98+ if (Array .isArray (props .type ) && props .type .length > 1 &&
99+ typeof props .type [1 ] === " object" ) {
73100 return props .type [1 ];
74101 }
75102});
@@ -162,6 +189,13 @@ function onSubmit() {
162189 emit (" setValue" , {value: localValue .value });
163190}
164191
192+ function onEnumSelect (value ) {
193+ if (isEnumType .value ) {
194+ localValue .value = value;
195+ emit (" setValue" , {value: value});
196+ }
197+ }
198+
165199function onCancel () {
166200 editMode .value = " default" ;
167201 dragging .instance = null ;
@@ -241,16 +275,62 @@ div.value input {
241275 cursor : text ;
242276}
243277
278+ div .value :deep(div .enum-field-dropdown ) {
279+ width : 100% ;
280+ display : block ;
281+ box-sizing : border-box ;
282+ background-color : var (--bg-input );
283+ position : relative ;
284+ z-index : 10 ;
285+ }
286+
287+ div .value :deep(div .enum-field-dropdown :hover ) {
288+ background-color : var (--bg-button-hover );
289+ }
290+
291+ div .value-dropdown {
292+ overflow : visible ;
293+ }
294+
295+ div .value :deep(div .enum-field-dropdown div .dropdown-container ) {
296+ grid-template-columns : 1fr 32px ;
297+ }
298+
299+ div .value :deep(div .enum-field-dropdown div .dropdown-text ) {
300+ padding : 4px ;
301+ padding-left : 8px ;
302+ }
303+
304+ div .value :deep(div .enum-field-dropdown div .dropdown-button ) {
305+ padding : 4px ;
306+ text-align : right ;
307+ }
308+
309+ div .value :deep(div .enum-field-dropdown div .dropdown-list ) {
310+ top : calc (100% + 2px );
311+ left : 0 ;
312+ z-index : 999 ;
313+ }
314+
244315div .value-readonly input {
245316 /* background-color: var(--bg-input); */
246317 cursor : default ;
247318 opacity : 0.8 ;
248319}
249320
321+ div .value-readonly :deep(div .enum-field-dropdown ) {
322+ cursor : default ;
323+ opacity : 0.8 ;
324+ }
325+
250326div .value-compact input {
251327 white-space : nowrap ;
252328}
253329
330+ div .value-compact :deep(div .enum-field-dropdown div .dropdown-text ) {
331+ white-space : nowrap ;
332+ }
333+
254334div .value-bool , div .value-bool input {
255335 color : #4981B5 ;
256336}
@@ -272,7 +352,15 @@ div.value-entity, div.value-entity input {
272352}
273353
274354div .value-enum , div .value-enum input , div .value-bitmask , div .value-bitmask input {
275- color : #7D67B5 ;
355+ color : var (--light-green );
356+ }
357+
358+ div .value-enum :deep(span .dropdown-text-active ) {
359+ color : var (--light-green );
360+ }
361+
362+ div .value-enum :deep(li .dropdown-item ) {
363+ color : var (--primary-text );
276364}
277365
278366 </style >
@@ -285,4 +373,4 @@ html.cursor-ew * {
285373 cursor : inherit !important ;
286374}
287375
288- </style >
376+ </style >
0 commit comments