-
Notifications
You must be signed in to change notification settings - Fork 208
Expand file tree
/
Copy pathApp.tsx
More file actions
executable file
·644 lines (574 loc) · 27.7 KB
/
App.tsx
File metadata and controls
executable file
·644 lines (574 loc) · 27.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
import * as React from "react";
import { createRoot } from "react-dom/client";
import { Action, Actions, BorderNode, IJsonTabNode, ITabRenderValues, ITabSetRenderValues, Layout, Model, Node, TabNode, TabSetNode } from "../../src/index";
import { NewFeatures } from "./NewFeatures";
import { showPopup } from "./PopupMenu";
import { SimpleForm } from "./SimpleForm";
import { Utils } from "./Utils";
import { AGGridExample } from "./aggrid";
import { JsonView } from "./JsonView";
import MapComponent from "./openlayter";
import MUIComponent from "./MUIComponent";
import MUIDataGrid from "./MUIDataGrid";
import BarChart from "./chart";
import * as Prism from "prismjs";
import "prismjs/themes/prism-coy.css";
var fields = ["Name", "Field1", "Field2", "Field3", "Field4", "Field5"];
const ContextExample = React.createContext('');
function App() {
const [layoutFile, setLayoutFile] = React.useState<string | null>(null);
const [model, setModel] = React.useState<Model | null>(null);
const [, setJson] = React.useState<string>("");
const [, setFontSize] = React.useState<string>("medium");
const [realtimeResize, setRealtimeResize] = React.useState<boolean>(false);
const [showLayout, setShowLayout] = React.useState<boolean>(false);
const [popoutClassName, setPopoutClassName] = React.useState<string>("flexlayout__theme_light");
const loadingLayoutName = React.useRef<string | null>(null);
const nextGridIndex = React.useRef<number>(1);
const showingPopupMenu = React.useRef<boolean>(false);
const layoutRef = React.useRef<Layout | null>(null);
// latest values to prevent closure problems
const latestModel = React.useRef<Model>(model);
const latestLayoutFile = React.useRef<string>(layoutFile);
latestModel.current = model;
latestLayoutFile.current = layoutFile;
const save = () => {
var jsonStr = JSON.stringify(latestModel.current!.toJson(), null, "\t");
localStorage.setItem(latestLayoutFile.current!, jsonStr);
}
const load = (jsonText: string) => {
let json = JSON.parse(jsonText);
let model = Model.fromJson(json);
// model.setOnCreateTabSet((tabNode?: TabNode) => {
// console.log("onCreateTabSet " + tabNode);
// // return { type: "tabset", name: "Header Text" };
// return { type: "tabset" };
// });
// you can control where nodes can be dropped
//model.setOnAllowDrop(this.allowDrop);
const html = Prism.highlight(jsonText, Prism.languages.javascript, 'javascript');
// this.setState({ layoutFile: this.loadingLayoutName!, model: model, json: html });
setLayoutFile(loadingLayoutName!.current);
setModel(model);
setJson(html);
}
const loadLayout = (layoutName: string, reload?: boolean) => {
if (layoutFile !== null) {
save();
}
loadingLayoutName.current = layoutName;
let loaded = false;
if (!reload) {
var json = localStorage.getItem(layoutName);
if (json != null) {
load(json);
loaded = true;
}
}
if (!loaded) {
Utils.downloadFile("layouts/" + layoutName + ".layout", load, error);
}
}
React.useEffect(() => {
// save layout when unloading page
window.onbeforeunload = (event: Event) => {
save();
};
const url = new URL(window.location.href);
const params = new URLSearchParams(url.search);
const layout = params.get('layout') || "default";
loadLayout(layout, false);
// use to generate json typescript interfaces
// Model.toTypescriptInterfaces();
}, []);
// const allowDrop = (dragNode: (TabNode | TabSetNode), dropInfo: DropInfo) => {
// let dropNode = dropInfo.node;
// // prevent non-border tabs dropping into borders
// if (dropNode.getType() === "border" && (dragNode.getParent() == null || dragNode.getParent()!.getType() != "border"))
// return false;
// // prevent border tabs dropping into main layout
// if (dropNode.getType() !== "border" && (dragNode.getParent() != null && dragNode.getParent()!.getType() == "border"))
// return false;
// return true;
// }
const error = (reason: string) => {
alert("Error loading json config file: " + loadingLayoutName.current + "\n" + reason);
}
const onAddActiveClick = (event: React.MouseEvent) => {
if (layoutFile?.startsWith("test_")) {
(layoutRef!.current as Layout).addTabToActiveTabSet({
component: "testing",
name: "Text" + nextGridIndex.current++
});
} else {
(layoutRef!.current!).addTabToActiveTabSet({
component: "grid",
icon: "images/article.svg",
name: "Grid " + nextGridIndex.current++
});
}
// console.log("Added tab", addedTab);
}
const onAddToLeftEmptyTabset = (event: React.MouseEvent) => {
(layoutRef!.current!).addTabToTabSet("mwLeftTabSet", {
component: "grid",
icon: "images/article.svg",
name: "Grid " + nextGridIndex.current++
});
}
const onAddToRightEmptyTabset = (event: React.MouseEvent) => {
(layoutRef!.current!).addTabToTabSet("mwRightTabSet", {
component: "grid",
icon: "images/article.svg",
name: "Grid " + nextGridIndex.current++
});
}
const onAddFromTabSetButton = (node: TabSetNode | BorderNode) => {
const addedTab = (layoutRef!.current!).addTabToTabSet(node.getId(), {
component: "grid",
name: "Grid " + nextGridIndex.current++
});
console.log("Added tab", addedTab);
}
const onRealtimeResize = (event: React.ChangeEvent<HTMLInputElement>) => {
setRealtimeResize(event.target.checked);
}
const onShowLayout = (event: React.ChangeEvent<HTMLInputElement>) => {
setShowLayout(event.target.checked);
}
const onRenderDragRect = (content: React.ReactNode | undefined, node?: Node, json?: IJsonTabNode) => {
if (layoutFile === "newfeatures") {
return (<>
{content}
<div style={{ whiteSpace: "pre" }}>
<br />
This is a customized<br />
drag rectangle
</div>
</>
);
} else {
return undefined; // use default rendering
}
}
const onContextMenu = (node: TabNode | TabSetNode | BorderNode, event: React.MouseEvent<HTMLElement, MouseEvent>) => {
if (!showingPopupMenu.current) {
event.preventDefault();
event.stopPropagation();
// console.log(node, event);
showPopup(
node instanceof TabNode ? "Tab: " + node.getName() : "Type: " + node.getType(),
(layoutRef!.current!).getRootDiv()!,
event.clientX, event.clientY,
["Option 1", "Option 2"],
(item: string | undefined) => {
// console.log("selected: " + item);
showingPopupMenu.current = false;
});
showingPopupMenu.current = true;
}
}
const onAuxMouseClick = (node: TabNode | TabSetNode | BorderNode, event: React.MouseEvent<HTMLElement, MouseEvent>) => {
// console.log(node, event);
}
const onTableDragStart = (event: React.DragEvent<HTMLDivElement>, node: Node) => {
layoutRef.current!.moveTabWithDragAndDrop(event.nativeEvent, node as TabNode);
}
const onDragStart = (event: React.DragEvent<HTMLElement>) => {
event.stopPropagation();
if (layoutFile?.startsWith("test_")) {
const gridName = "Text" + nextGridIndex.current++;
event.dataTransfer.setData('text/plain', "FlexLayoutTab:" + JSON.stringify({ name: gridName }));
layoutRef.current!.setDragComponent(event.nativeEvent, gridName, 10, 10);
layoutRef.current!.addTabWithDragAndDrop(event.nativeEvent, { name: gridName, component: "testing", "icon": "images/article.svg" });
} else {
const gridName = "Grid " + nextGridIndex.current++;
event.dataTransfer.setData('text/plain', "FlexLayoutTab:" + JSON.stringify({ name: gridName }));
layoutRef.current!.setDragComponent(event.nativeEvent, gridName, 10, 10);
layoutRef.current!.addTabWithDragAndDrop(event.nativeEvent, { name: gridName, component: "grid", "icon": "images/article.svg" });
}
}
const onExternalDrag = (e: React.DragEvent<HTMLElement>) => {
// console.log("onExternaldrag ", e.dataTransfer.types);
// Check for supported content type
const validTypes = ["text/uri-list", "text/html", "text/plain"];
if (e.dataTransfer.types.find(t => validTypes.indexOf(t) !== -1) === undefined) return;
// Set dropEffect (icon)
e.dataTransfer.dropEffect = "link";
return {
json: {
type: "tab",
component: "multitype"
},
onDrop: (node?: Node, event?: React.DragEvent<HTMLElement>) => {
if (!node || !event) return; // aborted drag
if (node instanceof TabNode) {
if (event.dataTransfer) {
if (event.dataTransfer.types.indexOf("text/uri-list") !== -1) {
const data = event.dataTransfer!.getData("text/uri-list");
model!.doAction(Actions.updateNodeAttributes(node.getId(), { name: "Url", config: { data, type: "url" } }));
} else if (event.dataTransfer.types.indexOf("text/html") !== -1) {
const data = event.dataTransfer!.getData("text/html");
model!.doAction(Actions.updateNodeAttributes(node.getId(), { name: "Html", config: { data, type: "html" } }));
} else if (event.dataTransfer.types.indexOf("text/plain") !== -1) {
const data = event.dataTransfer!.getData("text/plain");
model!.doAction(Actions.updateNodeAttributes(node.getId(), { name: "Text", config: { data, type: "text" } }));
}
}
}
}
}
};
const onShowLayoutClick = (event: React.MouseEvent) => {
console.log(JSON.stringify(model!.toJson(), null, "\t"));
}
// const onNewWindow = (event: React.MouseEvent) => {
// model!.doAction(Actions.createWindow( {
// "type": "row",
// "children": [
// {
// "type": "tabset",
// "weight": 100,
// "active": true,
// "children": []
// }
// ]
// }, {x:100, y:100, width:600, height:400}));
// }
const onAction = (action: Action) => {
return action;
}
const factory = (node: TabNode) => {
// log lifecycle events
// node.setEventListener("resize", function(p){console.log("resize", node.getName(), p.rect);});
// node.setEventListener("visibility", function(p){console.log("visibility", node.getName(), p.visible);});
// node.setEventListener("close", function(p){console.log("close", node.getName());});
var component = node.getComponent();
if (component === "json") {
return (<JsonView model={latestModel.current!} />);
}
else if (component === "simpleform") {
return <SimpleForm />
}
else if (component === "mui") {
return <MUIComponent />
}
else if (component === "muigrid") {
return <MUIDataGrid />
}
else if (component === "aggrid") {
return <AGGridExample />
}
else if (component === "chart") {
return <BarChart />
}
else if (component === "map") {
return <MapComponent />
}
else if (component === "grid") {
if (node.getExtraData().data == null) {
// create data in node extra data first time accessed
node.getExtraData().data = makeFakeData();
}
return <SimpleTable fields={fields} data={node.getExtraData().data} node={node} onDragStart={onTableDragStart} />;
}
else if (component === "sub") {
var model = node.getExtraData().model;
if (model == null) {
node.getExtraData().model = Model.fromJson(node.getConfig().model);
model = node.getExtraData().model;
// save submodel on save event
node.setEventListener("save", (p: any) => {
latestModel.current!.doAction(Actions.updateNodeAttributes(node.getId(), { config: { model: node.getExtraData().model.toJson() } }));
// node.getConfig().model = node.getExtraData().model.toJson();
}
);
}
return <Layout model={model} factory={factory} />;
}
else if (component === "text") {
try {
return <div dangerouslySetInnerHTML={{ __html: node.getConfig().text }} />;
} catch (e) {
console.log(e);
}
}
else if (component === "newfeatures") {
return <NewFeatures />;
}
else if (component === "multitype") {
try {
const config = node.getConfig();
if (config.type === "url") {
return <iframe title={node.getId()} src={config.data} style={{ display: "block", border: "none", boxSizing: "border-box" }} width="100%" height="100%" />;
} else if (config.type === "html") {
return (<div dangerouslySetInnerHTML={{ __html: config.data }} />);
} else if (config.type === "text") {
return (
<textarea style={{ position: "absolute", width: "100%", height: "100%", resize: "none", boxSizing: "border-box", border: "none" }}
defaultValue={config.data}
/>);
}
} catch (e) {
return (<div>{String(e)}</div>);
}
} else if (component === "testing") {
return <div className="tab_content">{node.getName()}</div>;
}
return null;
}
const onSelectLayout = (event: React.FormEvent) => {
var target = event.target as HTMLSelectElement;
loadLayout(target.value);
}
const onReloadFromFile = (event: React.MouseEvent) => {
loadLayout(layoutFile!, true);
}
const onThemeChange = (event: React.FormEvent) => {
var target = event.target as HTMLSelectElement;
const themeClassName = "flexlayout__theme_" + target.value;
document.documentElement.className = themeClassName;
// need to set popout top level class name to new theme
setPopoutClassName(themeClassName);
}
const onFontSizeChange = (event: React.FormEvent) => {
var target = event.target as HTMLSelectElement;
setFontSize(target.value);
const flexLayoutElement = document.querySelector('.flexlayout__layout') as HTMLElement | null;
flexLayoutElement!.style.setProperty('--font-size', target.value);
}
const onRenderTab = (node: TabNode, renderValues: ITabRenderValues) => {
// renderValues.content = (<div>hello</div>);
// renderValues.content += " *";
// renderValues.leading = <img style={{width:"1em", height:"1em"}}src="images/folder.svg"/>;
// renderValues.name = "tab " + node.getId(); // name used in overflow menu
if (layoutFile === "newfeatures" && node.getComponent() === "newfeatures") {
renderValues.buttons.push(<img key="menu" title="added menu button" style={{ width: "1em", height: "1em" }} src="images/menu.svg" />);
}
// playwright testing
if (layoutFile?.startsWith("test_")) {
if (node.getId() === "onRenderTab1") {
renderValues.leading = <img src="images/settings.svg" key="1" style={{ width: "1em", height: "1em" }} />
renderValues.content = "onRenderTab1";
renderValues.buttons.push(<img src="images/folder.svg" key="1" style={{ width: "1em", height: "1em" }} />);
} else if (node.getId() === "onRenderTab2") {
renderValues.leading = <img src="images/settings.svg" key="1" style={{ width: "1em", height: "1em" }} />
renderValues.content = "onRenderTab2";
renderValues.buttons.push(<img src="images/folder.svg" key="1" style={{ width: "1em", height: "1em" }} />);
}
}
}
const onRenderTabSet = (node: (TabSetNode | BorderNode), renderValues: ITabSetRenderValues) => {
if (node instanceof TabSetNode) {
if (layoutFile === "newfeatures") {
renderValues.buttons.push(<img key="menu" title="added menu button" style={{ width: "1em", height: "1em" }} src="images/menu.svg" />);
} else if (layoutFile === "default") {
renderValues.stickyButtons.push(
<img src="images/add.svg"
alt="Add"
key="Add button"
title="Add Tab (using onRenderTabSet callback, see Demo)"
style={{ width: "1.1em", height: "1.1em" }}
className="flexlayout__tab_toolbar_button"
onClick={() => onAddFromTabSetButton(node)}
/>);
// put overflow button before + button (default is after)
// renderValues.overflowPosition=0
}
}
// playwright testing
if (layoutFile?.startsWith("test_")) {
if (node.getId() === "onRenderTabSet1") {
renderValues.buttons.push(<img src="images/folder.svg" key="1" />);
renderValues.buttons.push(<img src="images/settings.svg" key="2" />);
} else if (node.getId() === "onRenderTabSet2") {
renderValues.buttons.push(<img src="images/folder.svg" key="1" />);
renderValues.buttons.push(<img src="images/settings.svg" key="2" />);
} else if (node.getId() === "onRenderTabSet3") {
renderValues.stickyButtons.push(
<img src="images/add.svg"
alt="Add"
key="Add button"
title="Add Tab (using onRenderTabSet callback, see Demo)"
style={{ marginLeft: 5, width: 24, height: 24 }}
// onClick={() => this.onAddFromTabSetButton(node)}
/>);
} else if (node instanceof BorderNode) {
renderValues.buttons.push(<img src="images/folder.svg" key="1" />);
renderValues.buttons.push(<img src="images/settings.svg" key="2" />);
}
}
}
const onTabSetPlaceHolder = (node: TabSetNode) => {
return <div
key="placeholder"
style={{
display: "flex",
flexGrow: 1,
alignItems: "center",
justifyContent: "center"
}}>Drag tabs to this area</div>;
}
const makeFakeData = () => {
var data = [];
var r = Math.random() * 50;
for (var i = 0; i < r; i++) {
var rec: { [key: string]: any; } = {};
rec.Name = randomString(5, "BCDFGHJKLMNPQRSTVWXYZ");
for (var j = 1; j < fields.length; j++) {
rec[fields[j]] = (1.5 + Math.random() * 2).toFixed(2);
}
data.push(rec);
}
return data;
}
const randomString = (len: number, chars: string) => {
var a = [];
for (var i = 0; i < len; i++) {
a.push(chars[Math.floor(Math.random() * chars.length)]);
}
return a.join("");
}
let contents: React.ReactNode = "loading ...";
if (model !== null) {
contents = <Layout
ref={layoutRef}
model={model}
popoutClassName={popoutClassName}
popoutWindowName="Demo Popout"
factory={factory}
onAction={onAction}
onRenderTab={onRenderTab}
onRenderTabSet={onRenderTabSet}
onRenderDragRect={onRenderDragRect}
onExternalDrag={onExternalDrag}
realtimeResize={realtimeResize}
onContextMenu={layoutFile === "newfeatures" ? onContextMenu : undefined}
onAuxMouseClick={layoutFile === "newfeatures" ? onAuxMouseClick : undefined}
// icons={{
// more: (node: (TabSetNode | BorderNode), hiddenTabs: { node: TabNode; index: number }[]) => {
// return (<div style={{fontSize:".7em"}}>{hiddenTabs.length}</div>);
// }
// }}
onTabSetPlaceHolder={onTabSetPlaceHolder}
// classNameMapper={
// className => {
// console.log(className);
// if (className === "flexlayout__tab_button--selected") {
// className = "override__tab_button--selected";
// }
// return className;
// }
// }
// i18nMapper = {
// (id, param?) => {
// if (id === I18nLabel.Move_Tab) {
// return `move this tab: ${param}`;
// } else if (id === I18nLabel.Move_Tabset) {
// return `move this tabset`
// }
// return undefined;
// }
// }
/>;
}
return (
<React.StrictMode>
<ContextExample.Provider value="from context">
<div className="app">
<div className="toolbar" dir="ltr">
<select className="toolbar_control" onChange={onSelectLayout}>
<option value="default">Default</option>
<option value="newfeatures">New Features</option>
<option value="simple">Simple</option>
<option value="mosaic">Mosaic Style</option>
<option value="sub">SubLayout</option>
<option value="complex">Complex</option>
<option value="ecmind">ECMind</option>
</select>
<button key="reloadbutton" className="toolbar_control" onClick={onReloadFromFile} style={{ marginLeft: 5 }}>Reload</button>
<div style={{ flexGrow: 1 }}></div>
<span style={{ fontSize: "14px" }}>Realtime resize</span>
<input
name="realtimeResize"
type="checkbox"
checked={realtimeResize}
onChange={onRealtimeResize} />
<span style={{ marginLeft: 5, fontSize: "14px" }}>Show layout</span>
<input
name="show layout"
type="checkbox"
checked={showLayout}
onChange={onShowLayout} />
<select className="toolbar_control" style={{ marginLeft: 5 }}
onChange={onFontSizeChange}
defaultValue="medium">
<option value="xx-small">Size xx-small</option>
<option value="x-small">Size x-small</option>
<option value="small">Size small</option>
<option value="medium">Size medium</option>
<option value="large">Size large</option>
<option value="8px">Size 8px</option>
<option value="10px">Size 10px</option>
<option value="12px">Size 12px</option>
<option value="14px">Size 14px</option>
<option value="16px">Size 16px</option>
<option value="18px">Size 18px</option>
<option value="20px">Size 20px</option>
<option value="25px">Size 25px</option>
<option value="30px">Size 30px</option>
</select>
<select className="toolbar_control" style={{ marginLeft: 5 }} defaultValue="light" onChange={onThemeChange}>
<option value="light">Light</option>
<option value="underline">Underline</option>
<option value="gray">Gray</option>
<option value="dark">Dark</option>
<option value="rounded">Rounded</option>
</select>
{/* <button className="toolbar_control" style={{ marginLeft: 5 }} onClick={onNewWindow}>New Window</button> */}
<button className="toolbar_control" style={{ marginLeft: 5 }} onClick={onShowLayoutClick}>Show Layout JSON in Console</button>
<button className="toolbar_control drag-from" data-id="add-drag" draggable={true}
style={{ height: "30px", marginLeft: 5, border: "none", outline: "none" }}
title="Add tab by starting a drag on a draggable element"
onDragStart={onDragStart}>
Add Drag
</button>
<button className="toolbar_control" data-id="add-active" style={{ marginLeft: 5 }} title="Add using Layout.addTabToActiveTabSet" onClick={onAddActiveClick}>Add Active</button>
{layoutFile === "ecmind" &&
<div>
<button className="toolbar_control" data-id="add-active" style={{ marginLeft: 5 }} title="Add using Layout.addTabToEmptyTabSet" onClick={onAddToLeftEmptyTabset}>Add to left empty Tabset</button>
<button className="toolbar_control" data-id="add-active" style={{ marginLeft: 5 }} title="Add using Layout.addTabToEmptyTabSet" onClick={onAddToRightEmptyTabset}>Add to right empty Tabset</button>
</div>
}
</div>
<div className={"contents" + (showLayout ? " showLayout" : "")}>
{contents}
</div>
</div>
</ContextExample.Provider>
</React.StrictMode>
);
}
function SimpleTable(props: { fields: any, node: Node, data: any, onDragStart: (event: React.DragEvent<HTMLDivElement>, node: Node) => void }) {
// if (Math.random()>0.8) throw Error("oppps I crashed");
var headercells = props.fields.map(function (field: any) {
return <th key={field}>{field}</th>;
});
var rows = [];
for (var i = 0; i < props.data.length; i++) {
var row = props.fields.map((field: any) => <td key={field}>{props.data[i][field]}</td>);
rows.push(<tr key={i}>{row}</tr>);
}
return <table className="simple_table">
<tbody>
<tr>{headercells}</tr>
{rows}
</tbody>
</table>;
}
// function InnerComponent() {
// const value = React.useContext(ContextExample);
// return <span>{value}</span>;
// }
const root = createRoot(document.getElementById("container")!);
root.render(<App />)