@@ -6,6 +6,22 @@ import GeometryTypes from '../data/geometry.js';
66import TextureTypes from '../data/textures.js' ;
77import { getEntityName } from '../utils.js' ;
88
9+ // https://stackoverflow.com/a/6491621
10+ const propByString = function ( o , s ) {
11+ s = s . replace ( / \[ ( \w + ) \] / g, '.$1' ) ; // convert indexes to properties
12+ s = s . replace ( / ^ \. / , '' ) ; // strip a leading dot
13+ var a = s . split ( '.' ) ;
14+ for ( var i = 0 , n = a . length ; i < n ; ++ i ) {
15+ var k = a [ i ] ;
16+ if ( k in o ) {
17+ o = o [ k ] ;
18+ } else {
19+ return ;
20+ }
21+ }
22+ return o ;
23+ }
24+
925const $onRefresh = Symbol ( 'onRefresh' ) ;
1026const commonProps = [ {
1127 name : 'Type' ,
@@ -41,20 +57,12 @@ function propsToElements(entity, elements, props, entities) {
4157 </ accordion-view > ` ) ;
4258 continue ;
4359 } else {
44- const { name, type, prop : propName , default : def } = prop ;
45- let path = propName . split ( '.' ) ;
46- let target = entity ;
47- let key = path . shift ( ) ;
48- // Support nested properties, like 'data.attributes'
49- while ( path . length ) {
50- if ( ! ( key in target ) ) {
51- break ;
52- }
53- target = target [ key ] ;
54- key = path . shift ( ) ;
55- }
60+ const { name, type, prop : propName , enumType, default : def } = prop ;
5661
57- const value = ( key in target ) ? target [ key ] : def ;
62+ let value = propByString ( entity , propName ) ;
63+ if ( value === undefined ) {
64+ value = def ;
65+ }
5866
5967 // For number/int types
6068 let min = 'min' in prop ? prop . min : - Infinity ;
@@ -76,6 +84,7 @@ function propsToElements(entity, elements, props, entities) {
7684 .value="${ value } "
7785 type="${ type } "
7886 property="${ propName } "
87+ enumType="${ enumType || '' } "
7988 .min="${ min } "
8089 .max="${ max } "
8190 .step="${ step } "
0 commit comments