11import * as React from "react" ;
2+ import * as Prism from "prismjs" ;
23import { createRoot } from "react-dom/client" ;
34import { Action , Actions , BorderNode , CLASSES , DockLocation , DragDrop , DropInfo , IJsonTabNode , ILayoutProps , ITabRenderValues , ITabSetRenderValues , Layout , Model , Node , TabNode , TabSetNode } from "../../src/index" ;
45import { NewFeatures } from "./NewFeatures" ;
56import { showPopup } from "./PopupMenu" ;
67import { TabStorage } from "./TabStorage" ;
78import { Utils } from "./Utils" ;
9+ import "prismjs/themes/prism-coy.css" ;
810
911var fields = [ "Name" , "Field1" , "Field2" , "Field3" , "Field4" , "Field5" ] ;
1012
1113const ContextExample = React . createContext ( '' ) ;
1214
13- class App extends React . Component < any , { layoutFile : string | null , model : Model | null , adding : boolean , fontSize : string , realtimeResize : boolean } > {
15+ class App extends React . Component < any , { layoutFile : string | null , model : Model | null , json ?: string , adding : boolean , fontSize : string , realtimeResize : boolean } > {
1416
1517 loadingLayoutName ?: string ;
1618 nextGridIndex : number = 1 ;
1719 showingPopupMenu : boolean = false ;
20+ htmlTimer ?: any = null ;
1821
1922 constructor ( props : any ) {
2023 super ( props ) ;
@@ -40,6 +43,18 @@ class App extends React.Component<any, { layoutFile: string | null, model: Model
4043 // Model.toTypescriptInterfaces();
4144 }
4245
46+ onModelChange = ( ) => {
47+ if ( this . htmlTimer ) {
48+ clearTimeout ( this . htmlTimer ) ;
49+ }
50+ this . htmlTimer = setTimeout ( ( ) => {
51+ const jsonText = JSON . stringify ( this . state . model ! . toJson ( ) , null , "\t" ) ;
52+ const html = Prism . highlight ( jsonText , Prism . languages . javascript , 'javascript' ) ;
53+ this . setState ( { json : html } ) ;
54+ this . htmlTimer = null ;
55+ } , 500 ) ;
56+ }
57+
4358 save ( ) {
4459 var jsonStr = JSON . stringify ( this . state . model ! . toJson ( ) , null , "\t" ) ;
4560 localStorage . setItem ( this . state . layoutFile ! , jsonStr ) ;
@@ -77,7 +92,8 @@ class App extends React.Component<any, { layoutFile: string | null, model: Model
7792 // you can control where nodes can be dropped
7893 //model.setOnAllowDrop(this.allowDrop);
7994
80- this . setState ( { layoutFile : this . loadingLayoutName ! , model : model } ) ;
95+ const html = Prism . highlight ( jsonText , Prism . languages . javascript , 'javascript' ) ;
96+ this . setState ( { layoutFile : this . loadingLayoutName ! , model : model , json : html } ) ;
8197 }
8298
8399 allowDrop = ( dragNode : ( TabNode | TabSetNode ) , dropInfo : DropInfo ) => {
@@ -253,7 +269,7 @@ class App extends React.Component<any, { layoutFile: string | null, model: Model
253269
254270 // const n = this.state.model?.getNodeById("#750f823f-8eda-44b7-a887-f8b287ace2c8");
255271 // (this.refs.layout as Layout).moveTabWithDragAndDrop(n as TabSetNode, "move tabset");
256-
272+
257273 // (this.refs.layout as Layout).moveTabWithDragAndDrop(node as TabNode);
258274 }
259275
@@ -269,7 +285,10 @@ class App extends React.Component<any, { layoutFile: string | null, model: Model
269285
270286 var component = node . getComponent ( ) ;
271287
272- if ( component === "grid" ) {
288+ if ( component === "json" ) {
289+ return ( < pre style = { { tabSize : "20px" } } dangerouslySetInnerHTML = { { __html : this . state . json ! } } /> ) ;
290+ }
291+ else if ( component === "grid" ) {
273292 if ( node . getExtraData ( ) . data == null ) {
274293 // create data in node extra data first time accessed
275294 node . getExtraData ( ) . data = this . makeFakeData ( ) ;
@@ -408,6 +427,7 @@ class App extends React.Component<any, { layoutFile: string | null, model: Model
408427 factory = { this . factory }
409428 font = { { size : this . state . fontSize } }
410429 onAction = { this . onAction }
430+ onModelChange = { this . onModelChange }
411431 titleFactory = { this . titleFactory }
412432 iconFactory = { this . iconFactory }
413433 onRenderTab = { this . onRenderTab }
@@ -455,6 +475,7 @@ class App extends React.Component<any, { layoutFile: string | null, model: Model
455475 < select className = "toolbar_control" onChange = { this . onSelectLayout } >
456476 < option value = "default" > Default</ option >
457477 < option value = "newfeatures" > New Features</ option >
478+ < option value = "simple" > Simple</ option >
458479 < option value = "sub" > SubLayout</ option >
459480 < option value = "complex" > Complex</ option >
460481 < option value = "headers" > Headers</ option >
0 commit comments