@@ -6,7 +6,7 @@ import * as React from 'react';
66
77import { JSONSchema4 } from 'json-schema' ;
88import { SchemaTree , SchemaTreeOptions , SchemaTreePopulateHandler , SchemaTreeRefDereferenceFn } from '../tree/tree' ;
9- import { GoToRefHandler , RowRenderer } from '../types' ;
9+ import { GoToRefHandler , RowRenderer , ViewMode } from '../types' ;
1010import { isSchemaViewerEmpty } from '../utils/isSchemaViewerEmpty' ;
1111import { SchemaTree as SchemaTreeComponent } from './SchemaTree' ;
1212
@@ -27,8 +27,12 @@ export interface IJsonSchemaViewer {
2727 onTreePopulate ?: SchemaTreePopulateHandler ;
2828 resolveRef ?: SchemaTreeRefDereferenceFn ;
2929 shouldResolveEagerly ?: boolean ;
30+ viewMode ?: ViewMode ;
3031}
3132
33+ export const ViewModeContext = React . createContext < ViewMode > ( 'standalone' ) ;
34+ ViewModeContext . displayName = 'ViewModeContext' ;
35+
3236export class JsonSchemaViewerComponent extends React . PureComponent < IJsonSchemaViewer & ErrorBoundaryForwardedProps > {
3337 protected readonly treeStore : TreeStore ;
3438 protected readonly tree : SchemaTree ;
@@ -51,6 +55,7 @@ export class JsonSchemaViewerComponent extends React.PureComponent<IJsonSchemaVi
5155 resolveRef : this . props . resolveRef ,
5256 shouldResolveEagerly : ! ! this . props . shouldResolveEagerly ,
5357 onPopulate : this . props . onTreePopulate ,
58+ viewMode : this . props . viewMode ,
5459 } ;
5560 }
5661
@@ -96,7 +101,8 @@ export class JsonSchemaViewerComponent extends React.PureComponent<IJsonSchemaVi
96101 this . treeStore . defaultExpandedDepth !== this . expandedDepth ||
97102 prevProps . schema !== this . props . schema ||
98103 prevProps . mergeAllOf !== this . props . mergeAllOf ||
99- prevProps . shouldResolveEagerly !== this . props . shouldResolveEagerly
104+ prevProps . shouldResolveEagerly !== this . props . shouldResolveEagerly ||
105+ prevProps . viewMode !== this . props . viewMode
100106 ) {
101107 this . treeStore . defaultExpandedDepth = this . expandedDepth ;
102108 this . tree . treeOptions = this . treeOptions ;
@@ -117,7 +123,9 @@ export class JsonSchemaViewerComponent extends React.PureComponent<IJsonSchemaVi
117123
118124 return (
119125 < div className = { cn ( className , 'JsonSchemaViewer flex flex-col relative' ) } >
120- < SchemaTreeComponent expanded = { expanded } name = { name } schema = { schema } treeStore = { this . treeStore } { ...props } />
126+ < ViewModeContext . Provider value = { this . props . viewMode ?? 'standalone' } >
127+ < SchemaTreeComponent expanded = { expanded } name = { name } schema = { schema } treeStore = { this . treeStore } { ...props } />
128+ </ ViewModeContext . Provider >
121129 </ div >
122130 ) ;
123131 }
0 commit comments