embedHostComponent.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. const Split = require('split.js').default;
  9. require("./embedHost.scss");
  10. interface IEmbedHostComponentProps {
  11. scene: Scene,
  12. globalState: GlobalState,
  13. popupMode: boolean,
  14. noClose?: boolean,
  15. noExpand?: boolean,
  16. onClose: () => void,
  17. onPopup: () => void
  18. }
  19. export class EmbedHostComponent extends React.Component<IEmbedHostComponentProps> {
  20. private _once = true;
  21. constructor(props: IEmbedHostComponentProps) {
  22. super(props);
  23. }
  24. componentDidMount() {
  25. const container = this.refs.split;
  26. if (!container) {
  27. return;
  28. }
  29. Split([this.refs.topPart, this.refs.bottomPart], {
  30. direction: "vertical",
  31. minSize: [200, 200],
  32. gutterSize: 4
  33. })
  34. }
  35. renderContent() {
  36. if (this.props.popupMode) {
  37. return (
  38. <div id="split" className="splitPopup">
  39. <div id="topPart">
  40. <SceneExplorerComponent scene={this.props.scene}
  41. popupMode={true}
  42. globalState={this.props.globalState} noHeader={true} />
  43. </div>
  44. <div id="separator" />
  45. <div id="bottomPart" style={{ marginTop: "4px", overflow: "hidden" }}>
  46. <ActionTabsComponent scene={this.props.scene}
  47. popupMode={true}
  48. globalState={this.props.globalState} noHeader={true} />
  49. </div>
  50. </div>
  51. )
  52. }
  53. return (
  54. <div ref="split" id="split" className="noPopup">
  55. <div id="topPart" ref="topPart">
  56. <SceneExplorerComponent scene={this.props.scene}
  57. globalState={this.props.globalState}
  58. popupMode={true}
  59. noHeader={true} />
  60. </div>
  61. <div id="bottomPart" ref="bottomPart" style={{ marginTop: "4px", overflow: "hidden" }}>
  62. <ActionTabsComponent scene={this.props.scene}
  63. globalState={this.props.globalState}
  64. popupMode={true}
  65. noHeader={true} />
  66. </div>
  67. </div>
  68. )
  69. }
  70. render() {
  71. if (this.props.popupMode) {
  72. return (
  73. <div id="embed">
  74. <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} />
  75. {this.renderContent()}
  76. </div>
  77. );
  78. }
  79. if (this._once) {
  80. this._once = false;
  81. // A bit hacky but no other way to force the initial width to 300px and not auto
  82. setTimeout(() => {
  83. const element = document.getElementById("embed");
  84. if (!element) {
  85. return;
  86. }
  87. element.style.width = "300px";
  88. }, 150);
  89. }
  90. return (
  91. <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 }}>
  92. <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} />
  93. {this.renderContent()}
  94. </Resizable>
  95. );
  96. }
  97. }