@@ -21,7 +21,7 @@ export type SchemaTreeRefDereferenceFn = (
2121 schema : JSONSchema4 ,
2222) => Optional < JSONSchema4 > ;
2323
24- export type SchemaTreePopulateHandler = ( node : TreeListParentNode ) => void ;
24+ export type SchemaTreePopulateHandler = ( tree : SchemaTree , node : TreeListParentNode ) => void ;
2525
2626export type SchemaTreeOptions = {
2727 expandedDepth : number ;
@@ -37,7 +37,11 @@ export class SchemaTree extends Tree {
3737 public treeOptions : SchemaTreeOptions ;
3838
3939 constructor ( public schema : JSONSchema4 , public state : TreeState , opts : SchemaTreeOptions ) {
40- super ( ) ;
40+ super ( {
41+ expanded : node =>
42+ ( ! ( node . id in state . expanded ) && SchemaTree . getLevel ( node ) <= opts . expandedDepth ) ||
43+ state . expanded [ node . id ] === true ,
44+ } ) ;
4145
4246 this . treeOptions = opts ;
4347 }
@@ -66,7 +70,7 @@ export class SchemaTree extends Tree {
6670 } ) ;
6771 this . state . expanded = expanded ;
6872 this . invalidate ( ) ;
69- this . treeOptions . onPopulate ?.( this . root ) ;
73+ this . treeOptions . onPopulate ?.( this , this . root ) ;
7074 }
7175
7276 public populateTreeFragment ( parent : TreeListParentNode , schema : JSONSchema4 , path : JsonPath , stepIn : boolean ) {
@@ -88,7 +92,7 @@ export class SchemaTree extends Tree {
8892
8993 this . insertTreeFragment ( stepIn ? this . stepIn ( artificialRoot , parent ) : artificialRoot . children , parent ) ;
9094
91- this . treeOptions . onPopulate ?.( parent ) ;
95+ this . treeOptions . onPopulate ?.( this , parent ) ;
9296 }
9397
9498 protected insertErrorNode ( parent : TreeListParentNode , error : string ) {
@@ -121,7 +125,7 @@ export class SchemaTree extends Tree {
121125 } else if ( hasRefItems ( schemaNode ) ) {
122126 this . populateRefFragment ( node , [ ...path , 'items' ] , schemaNode . items . $ref ) ;
123127 } else {
124- throw new Error ( `I do know not how not expand node ${ path . join ( '.' ) } ` ) ;
128+ throw new Error ( `I do know not how to expand this node ${ path . join ( '.' ) } ` ) ;
125129 }
126130 } catch ( ex ) {
127131 this . insertErrorNode ( node , ex . message ) ;
0 commit comments