11import { ErrorBoundaryForwardedProps , FallbackComponent , withErrorBoundary } from '@stoplight/react-error-boundary' ;
2- import { Tree , TreeState , TreeStore } from '@stoplight/tree-list' ;
2+ import { TreeState , TreeStore } from '@stoplight/tree-list' ;
33import { Intent , Spinner } from '@stoplight/ui-kit' ;
44import cn from 'classnames' ;
55import { action , runInAction } from 'mobx' ;
66import * as React from 'react' ;
7- import SchemaWorker , { WebWorker } from 'web-worker:../workers/schema.ts' ;
87
98import { JSONSchema4 } from 'json-schema' ;
10- import { populateTree } from '../tree/populateTree ' ;
9+ import { SchemaTree } from '../tree/tree ' ;
1110import { GoToRefHandler , RowRenderer } from '../types' ;
1211import { isSchemaViewerEmpty } from '../utils/isSchemaViewerEmpty' ;
1312import { ComputeSchemaMessageData , isRenderedSchemaMessage } from '../workers/messages' ;
14- import { SchemaTree } from './SchemaTree' ;
13+ import { SchemaTree as SchemaTreeComponent } from './SchemaTree' ;
1514
1615export interface IJsonSchemaViewer {
1716 schema : JSONSchema4 ;
@@ -32,9 +31,10 @@ export interface IJsonSchemaViewer {
3231
3332export class JsonSchemaViewerComponent extends React . PureComponent < IJsonSchemaViewer & ErrorBoundaryForwardedProps > {
3433 protected readonly treeStore : TreeStore ;
35- protected readonly tree : Tree ;
34+ protected readonly tree : SchemaTree ;
35+ protected readonly treeState : TreeState ;
3636 protected readonly instanceId : string ;
37- public static schemaWorker ?: WebWorker ;
37+ // public static schemaWorker?: WebWorker;
3838
3939 public state = {
4040 computing : false ,
@@ -43,8 +43,9 @@ export class JsonSchemaViewerComponent extends React.PureComponent<IJsonSchemaVi
4343 constructor ( props : IJsonSchemaViewer & ErrorBoundaryForwardedProps ) {
4444 super ( props ) ;
4545
46- this . tree = new Tree ( Tree . createArtificialRoot ( ) ) ;
47- this . treeStore = new TreeStore ( this . tree , new TreeState ( ) , {
46+ this . treeState = new TreeState ( ) ;
47+ this . tree = new SchemaTree ( this . schema , this . treeState , this . expandedDepth ) ;
48+ this . treeStore = new TreeStore ( this . tree , this . treeState , {
4849 defaultExpandedDepth : this . expandedDepth ,
4950 } ) ;
5051
@@ -130,35 +131,33 @@ export class JsonSchemaViewerComponent extends React.PureComponent<IJsonSchemaVi
130131 // }
131132
132133 protected renderSchema ( ) {
133- populateTree ( this . schema , this . tree . root , 0 , [ ] , null ) ;
134- this . tree . root = this . tree . root . children [ 0 ] ;
135- this . tree . invalidate ( ) ;
134+ this . tree . populate ( ) ;
136135 // const needsFullRendering = true;
137136 // this.prerenderSchema();
138137 // if (!needsFullRendering) {
139138 // return;
140139 // }
141140
142- const message : ComputeSchemaMessageData = {
143- instanceId : this . instanceId ,
144- schema : this . schema ,
145- mergeAllOf : this . props . mergeAllOf !== false ,
146- } ;
147-
148- if ( JsonSchemaViewerComponent . schemaWorker !== void 0 ) {
149- JsonSchemaViewerComponent . schemaWorker . postMessage ( message ) ;
150- }
141+ // const message: ComputeSchemaMessageData = {
142+ // instanceId: this.instanceId,
143+ // schema: this.schema,
144+ // mergeAllOf: this.props.mergeAllOf !== false,
145+ // };
146+ //
147+ // if (JsonSchemaViewerComponent.schemaWorker !== void 0) {
148+ // JsonSchemaViewerComponent.schemaWorker.postMessage(message);
149+ // }
151150
152151 this . setState ( { computing : false } ) ;
153152 }
154153
155154 public componentDidMount ( ) {
156155 // let's initialize it lazily
157- if ( JsonSchemaViewerComponent . schemaWorker === void 0 ) {
158- JsonSchemaViewerComponent . schemaWorker = new SchemaWorker ( ) ;
159- }
156+ // if (JsonSchemaViewerComponent.schemaWorker === void 0) {
157+ // JsonSchemaViewerComponent.schemaWorker = new SchemaWorker();
158+ // }
160159
161- JsonSchemaViewerComponent . schemaWorker . addEventListener ( 'message' , this . handleWorkerMessage ) ;
160+ // JsonSchemaViewerComponent.schemaWorker.addEventListener('message', this.handleWorkerMessage);
162161 this . renderSchema ( ) ;
163162 }
164163
@@ -197,7 +196,7 @@ export class JsonSchemaViewerComponent extends React.PureComponent<IJsonSchemaVi
197196 < Spinner className = "relative" intent = { Intent . PRIMARY } size = { Spinner . SIZE_LARGE } />
198197 </ div >
199198 ) }
200- < SchemaTree expanded = { expanded } name = { name } schema = { schema } treeStore = { this . treeStore } { ...props } />
199+ < SchemaTreeComponent expanded = { expanded } name = { name } schema = { schema } treeStore = { this . treeStore } { ...props } />
201200 </ div >
202201 ) ;
203202 }
0 commit comments