@@ -19,18 +19,23 @@ var assign = require('object-assign');
1919var consts = require ( '../../agent/consts' ) ;
2020var previewComplex = require ( './previewComplex' ) ;
2121
22+ type Inspect = ( path : Array < string > , cb : ( ) = > void ) => void ;
23+ type ShowMenu = boolean | ( e : DOMEvent , val : any , path : Array < string > , name : string ) => void ;
24+
25+ type DataViewProps = {
26+ data : Object ,
27+ path : Array < string > ,
28+ inspect : Inspect ,
29+ showMenu : ShowMenu ,
30+ startOpen ?: boolean ,
31+ noSort ?: boolean ,
32+ readOnly ?: boolean ,
33+ } ;
34+
2235class DataView extends React . Component {
23- props : {
24- data : Object ,
25- path : Array < string > ,
26- inspect : ( path : Array < string > , cb : ( ) = > void ) => void ,
27- showMenu : ( e : DOMEvent , val : any , path : Array < string > , name : string ) = > void ,
28- startOpen : boolean ,
29- noSort ?: boolean ,
30- readOnly : boolean ,
31- } ;
36+ props : DataViewProps ;
3237
33- render ( ) : ReactElement {
38+ render ( ) {
3439 var data = this . props . data ;
3540 if ( ! data ) {
3641 return < div style = { styles . missing } > null</ div > ;
@@ -80,9 +85,22 @@ class DataView extends React.Component {
8085}
8186
8287class DataItem extends React . Component {
88+ props : {
89+ path : Array < string > ,
90+ inspect : Inspect ,
91+ showMenu : ShowMenu ,
92+ startOpen ?: boolean ,
93+ noSort ?: boolean ,
94+ readOnly ?: boolean ,
95+ name : string ,
96+ value : any ,
97+ } ;
98+ defaultProps: { } ;
99+ state: { open : boolean , loading : boolean } ;
100+
83101 constructor ( props ) {
84102 super ( props ) ;
85- this . state = { open : this . props . startOpen , loading : false } ;
103+ this . state = { open : ! ! this . props . startOpen , loading : false } ;
86104 }
87105
88106 componentDidMount ( ) {
@@ -182,7 +200,11 @@ class DataItem extends React.Component {
182200 { this . props . name } :
183201 </ div >
184202 < div
185- onContextMenu = { e => this . props . showMenu ( e , this . props . value , this . props . path , this . props . name ) }
203+ onContextMenu = { e => {
204+ if ( typeof this . props . showMenu === 'function' ) {
205+ return this . props . showMenu ( e , this . props . value , this . props . path , this . props . name ) ;
206+ }
207+ } }
186208 style = { styles . preview }
187209 >
188210 { preview }
0 commit comments