Skip to content

Commit 45803a7

Browse files
committed
Added json tab to demo layouts
1 parent 6efa815 commit 45803a7

File tree

7 files changed

+109
-40
lines changed

7 files changed

+109
-40
lines changed

examples/demo/App.tsx

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
import * as React from "react";
2+
import * as Prism from "prismjs";
23
import { createRoot } from "react-dom/client";
34
import { Action, Actions, BorderNode, CLASSES, DockLocation, DragDrop, DropInfo, IJsonTabNode, ILayoutProps, ITabRenderValues, ITabSetRenderValues, Layout, Model, Node, TabNode, TabSetNode } from "../../src/index";
45
import { NewFeatures } from "./NewFeatures";
56
import { showPopup } from "./PopupMenu";
67
import { TabStorage } from "./TabStorage";
78
import { Utils } from "./Utils";
9+
import "prismjs/themes/prism-coy.css";
810

911
var fields = ["Name", "Field1", "Field2", "Field3", "Field4", "Field5"];
1012

1113
const 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>

examples/demo/layouts/default.layout

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,12 @@
6565
"name": "Terminal",
6666
"component": "grid",
6767
"icon":"images/terminal.svg"
68-
}
68+
},
69+
{
70+
"type": "tab",
71+
"name": "Layout JSON",
72+
"component": "json"
73+
}
6974
]
7075
},
7176
{

examples/demo/layouts/headers.layout

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,13 @@
1010
{
1111
"type": "tabset",
1212
"weight": 50,
13-
"name":"Navigation",
13+
"name":"Header 1",
1414
"selected": 0,
15-
"enableDrag":false,
16-
"enableDrop":false,
17-
"enableSplit":false,
1815
"children": [
1916
{
2017
"type": "tab",
21-
"name": "FX",
22-
"component":"grid",
23-
"config": {
24-
"id": "1"
25-
}
18+
"name": "One",
19+
"component":"grid"
2620
}
2721
]
2822
},
@@ -34,7 +28,7 @@
3428
"children": [
3529
{
3630
"type": "tab",
37-
"name": "FI",
31+
"name": "Two",
3832
"component":"grid",
3933
"config": {
4034
"id": "2"
@@ -45,19 +39,13 @@
4539
{
4640
"type": "tabset",
4741
"weight": 50,
48-
"name":"Blotters",
42+
"name":"Header 2",
4943
"selected": 0,
50-
"enableDrag":false,
51-
"enableDrop":false,
52-
"enableSplit":false,
5344
"children": [
5445
{
5546
"type": "tab",
56-
"name": "FX",
57-
"component":"grid",
58-
"config": {
59-
"id": "1"
60-
}
47+
"name": "Three",
48+
"component":"grid"
6149
}
6250
]
6351
}

examples/demo/layouts/newfeatures.layout

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@
6060
"enableClose":false,
6161
"name": "Terminal",
6262
"component": "grid"
63-
}
63+
},
64+
{
65+
"type": "tab",
66+
"name": "Layout JSON",
67+
"component": "json"
68+
}
6469
]
6570
},
6671
{
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"global": {},
3+
"borders": [],
4+
"layout": {
5+
"type": "row",
6+
"id": "1",
7+
"children": [
8+
{
9+
"type": "tabset",
10+
"id": "2",
11+
"weight": 50,
12+
"children": [
13+
{
14+
"type": "tab",
15+
"id": "3",
16+
"name": "Layout JSON",
17+
"component": "json"
18+
}
19+
],
20+
"active": true
21+
},
22+
{
23+
"type": "tabset",
24+
"id": "4",
25+
"weight": 50,
26+
"children": [
27+
{
28+
"type": "tab",
29+
"id": "5",
30+
"name": "Grid 1",
31+
"component": "grid",
32+
"icon": "images/article.svg"
33+
}
34+
]
35+
}
36+
]
37+
}
38+
}

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,18 @@
4343
"extends": "react-app"
4444
},
4545
"devDependencies": {
46-
"@types/react": "^18.0.5",
47-
"@types/react-dom": "^18.0.1",
4846
"@cypress/react": "^5.12.4",
4947
"@cypress/webpack-dev-server": "^1.8.4",
5048
"@types/node": "^17.0.24",
49+
"@types/prismjs": "^1.26.0",
50+
"@types/react": "^18.0.5",
51+
"@types/react-dom": "^18.0.1",
5152
"@types/uuid": "^8.3.3",
5253
"css-loader": "^6.7.1",
5354
"cypress": "^9.5.4",
5455
"html-webpack-plugin": "^5.5.0",
5556
"prettier": "^2.6.2",
57+
"prismjs": "^1.28.0",
5658
"react-scripts": "5.0.1",
5759
"sass": "^1.50.0",
5860
"source-map-loader": "^3.0.0",

yarn.lock

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1841,6 +1841,11 @@
18411841
resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-2.4.4.tgz#5d9b63132df54d8909fce1c3f8ca260fdd693e17"
18421842
integrity sha512-ReVR2rLTV1kvtlWFyuot+d1pkpG2Fw/XKE3PDAdj57rbM97ttSp9JZ2UsP+2EHTylra9cUf6JA7tGwW1INzUrA==
18431843

1844+
"@types/prismjs@^1.26.0":
1845+
version "1.26.0"
1846+
resolved "https://registry.yarnpkg.com/@types/prismjs/-/prismjs-1.26.0.tgz#a1c3809b0ad61c62cac6d4e0c56d610c910b7654"
1847+
integrity sha512-ZTaqn/qSqUuAq1YwvOFQfVW1AR/oQJlLSZVustdjwI+GZ8kr0MSHBj0tsXPW1EqHubx50gtBEjbPGsdZwQwCjQ==
1848+
18441849
"@types/prop-types@*":
18451850
version "15.7.4"
18461851
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.4.tgz#fcf7205c25dff795ee79af1e30da2c9790808f11"
@@ -7977,6 +7982,11 @@ pretty-format@^27.5.1:
79777982
ansi-styles "^5.0.0"
79787983
react-is "^17.0.1"
79797984

7985+
prismjs@^1.28.0:
7986+
version "1.28.0"
7987+
resolved "https://registry.yarnpkg.com/prismjs/-/prismjs-1.28.0.tgz#0d8f561fa0f7cf6ebca901747828b149147044b6"
7988+
integrity sha512-8aaXdYvl1F7iC7Xm1spqSaY/OJBpYW3v+KJ+F17iYxvdc8sfjW194COK5wVhMZX45tGteiBQgdvD/nhxcRwylw==
7989+
79807990
process-nextick-args@~2.0.0:
79817991
version "2.0.1"
79827992
resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2"
@@ -8138,13 +8148,13 @@ react-dev-utils@^12.0.1:
81388148
strip-ansi "^6.0.1"
81398149
text-table "^0.2.0"
81408150

8141-
react-dom@^18.0.0:
8142-
version "18.0.0"
8143-
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-18.0.0.tgz#26b88534f8f1dbb80853e1eabe752f24100d8023"
8144-
integrity sha512-XqX7uzmFo0pUceWFCt7Gff6IyIMzFUn7QMZrbrQfGxtaxXZIcGQzoNpRLE3fQLnS4XzLLPMZX2T9TRcSrasicw==
8151+
react-dom@^18.1.0:
8152+
version "18.1.0"
8153+
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-18.1.0.tgz#7f6dd84b706408adde05e1df575b3a024d7e8a2f"
8154+
integrity sha512-fU1Txz7Budmvamp7bshe4Zi32d0ll7ect+ccxNu9FlObT605GOEB8BfO4tmRJ39R5Zj831VCpvQ05QPBW5yb+w==
81458155
dependencies:
81468156
loose-envify "^1.1.0"
8147-
scheduler "^0.21.0"
8157+
scheduler "^0.22.0"
81488158

81498159
react-error-overlay@^6.0.11:
81508160
version "6.0.11"
@@ -8221,10 +8231,10 @@ [email protected]:
82218231
optionalDependencies:
82228232
fsevents "^2.3.2"
82238233

8224-
react@^18.0.0:
8225-
version "18.0.0"
8226-
resolved "https://registry.yarnpkg.com/react/-/react-18.0.0.tgz#b468736d1f4a5891f38585ba8e8fb29f91c3cb96"
8227-
integrity sha512-x+VL6wbT4JRVPm7EGxXhZ8w8LTROaxPXOqhlGyVSrv0sB1jkyFGgXxJ8LVoPRLvPR6/CIZGFmfzqUa2NYeMr2A==
8234+
react@^18.1.0:
8235+
version "18.1.0"
8236+
resolved "https://registry.yarnpkg.com/react/-/react-18.1.0.tgz#6f8620382decb17fdc5cc223a115e2adbf104890"
8237+
integrity sha512-4oL8ivCz5ZEPyclFQXaNksK3adutVS8l2xzZU0cqEFrE9Sb7fC0EFK5uEk74wIreL1DERyjvsU915j1pcT2uEQ==
82288238
dependencies:
82298239
loose-envify "^1.1.0"
82308240

@@ -8570,10 +8580,10 @@ saxes@^5.0.1:
85708580
dependencies:
85718581
xmlchars "^2.2.0"
85728582

8573-
scheduler@^0.21.0:
8574-
version "0.21.0"
8575-
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.21.0.tgz#6fd2532ff5a6d877b6edb12f00d8ab7e8f308820"
8576-
integrity sha512-1r87x5fz9MXqswA2ERLo0EbOAU74DpIUO090gIasYTqlVoJeMcl+Z1Rg7WHz+qtPujhS/hGIt9kxZOYBV3faRQ==
8583+
scheduler@^0.22.0:
8584+
version "0.22.0"
8585+
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.22.0.tgz#83a5d63594edf074add9a7198b1bae76c3db01b8"
8586+
integrity sha512-6QAm1BgQI88NPYymgGQLCZgvep4FyePDWFpXVK+zNSUgHwlqpJy8VEh8Et0KxTACS4VWwMousBElAZOH9nkkoQ==
85778587
dependencies:
85788588
loose-envify "^1.1.0"
85798589

0 commit comments

Comments
 (0)