embedHostComponent.tsx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import * as React from "react";
  2. import { HeaderComponent } from "../headerComponent";
  3. import Resizable from "re-resizable";
  4. import { SceneExplorerComponent } from "../sceneExplorer/sceneExplorerComponent";
  5. import { ActionTabsComponent } from "../actionTabs/actionTabsComponent";
  6. import { Scene } from "babylonjs/scene";
  7. import { GlobalState } from "../../components/globalState";
  8. import { IExplorerExtensibilityGroup, DebugLayerTab } from 'babylonjs/Debug/debugLayer';
  9. const Split = require('split.js').default;
  10. require("./embedHost.scss");
  11. interface IEmbedHostComponentProps {
  12. scene: Scene,
  13. globalState: GlobalState,
  14. popupMode: boolean,
  15. noClose?: boolean,
  16. noExpand?: boolean,
  17. onClose: () => void,
  18. onPopup: () => void,
  19. extensibilityGroups?: IExplorerExtensibilityGroup[],
  20. initialTab?: DebugLayerTab
  21. }
  22. export class EmbedHostComponent extends React.Component<IEmbedHostComponentProps> {
  23. private _once = true;
  24. private splitRef: React.RefObject<HTMLDivElement>;
  25. private topPartRef: React.RefObject<HTMLDivElement>;
  26. private bottomPartRef: React.RefObject<HTMLDivElement>;
  27. constructor(props: IEmbedHostComponentProps) {
  28. super(props);
  29. this.splitRef = React.createRef();
  30. this.topPartRef = React.createRef();
  31. this.bottomPartRef = React.createRef();
  32. }
  33. componentDidMount() {
  34. const container = this.splitRef.current;
  35. if (!container) {
  36. return;
  37. }
  38. Split([this.topPartRef.current, this.bottomPartRef.current], {
  39. direction: "vertical",
  40. minSize: [200, 200],
  41. gutterSize: 4
  42. });
  43. }
  44. renderContent() {
  45. if (this.props.popupMode) {
  46. return (
  47. <div id="split" className="splitPopup">
  48. <div id="topPart">
  49. <SceneExplorerComponent scene={this.props.scene}
  50. extensibilityGroups={this.props.extensibilityGroups}
  51. popupMode={true}
  52. globalState={this.props.globalState} noHeader={true} />
  53. </div>
  54. <div id="separator" />
  55. <div id="bottomPart" style={{ marginTop: "4px", overflow: "hidden" }}>
  56. <ActionTabsComponent scene={this.props.scene}
  57. popupMode={true}
  58. globalState={this.props.globalState} noHeader={true}
  59. initialTab={this.props.initialTab} />
  60. </div>
  61. </div>
  62. )
  63. }
  64. return (
  65. <div ref={this.splitRef} id="split" className="noPopup">
  66. <div id="topPart" ref={this.topPartRef}>
  67. <SceneExplorerComponent scene={this.props.scene}
  68. extensibilityGroups={this.props.extensibilityGroups}
  69. globalState={this.props.globalState}
  70. popupMode={true}
  71. noHeader={true} />
  72. </div>
  73. <div id="bottomPart" ref={this.bottomPartRef} style={{ marginTop: "4px", overflow: "hidden" }}>
  74. <ActionTabsComponent scene={this.props.scene}
  75. globalState={this.props.globalState}
  76. popupMode={true}
  77. noHeader={true}
  78. initialTab={this.props.initialTab} />
  79. </div>
  80. </div>
  81. );
  82. }
  83. render() {
  84. if (this.props.popupMode) {
  85. return (
  86. <div id="embed">
  87. <HeaderComponent title="INSPECTOR" noClose={this.props.noClose} noExpand={this.props.noExpand} handleBack={true} onClose={() => this.props.onClose()} onPopup={() => this.props.onPopup()} onSelectionChangedObservable={this.props.globalState.onSelectionChangedObservable} />
  88. {this.renderContent()}
  89. </div>
  90. );
  91. }
  92. if (this._once) {
  93. this._once = false;
  94. // A bit hacky but no other way to force the initial width to 300px and not auto
  95. setTimeout(() => {
  96. const element = document.getElementById("embed");
  97. if (!element) {
  98. return;
  99. }
  100. element.style.width = "300px";
  101. }, 150);
  102. }
  103. return (
  104. <Resizable id="embed" minWidth={300} maxWidth={600} size={{ height: "100%" }} minHeight="100%" enable={{ top: false, right: false, bottom: false, left: true, topRight: false, bottomRight: false, bottomLeft: false, topLeft: false }}>
  105. <HeaderComponent title="INSPECTOR" noClose={this.props.noClose} noExpand={this.props.noExpand} handleBack={true} onClose={() => this.props.onClose()} onPopup={() => this.props.onPopup()} onSelectionChangedObservable={this.props.globalState.onSelectionChangedObservable} />
  106. {this.renderContent()}
  107. </Resizable>
  108. );
  109. }
  110. }