2020-07-18 04:24:20 +02:00
|
|
|
import {React, DOM} from "modules";
|
2019-06-15 04:11:19 +02:00
|
|
|
|
|
|
|
import FloatingWindow from "./window";
|
|
|
|
|
|
|
|
class FloatingWindowContainer extends React.Component {
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {windows: []};
|
|
|
|
}
|
|
|
|
|
2020-07-16 23:17:02 +02:00
|
|
|
get minY() {
|
2020-07-18 04:24:20 +02:00
|
|
|
const appContainer = DOM.query(`#app-mount > div[class*="app-"]`);
|
2020-07-16 23:17:02 +02:00
|
|
|
if (appContainer) return appContainer.offsetTop;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-06-15 04:11:19 +02:00
|
|
|
render() {
|
2019-06-19 21:24:05 +02:00
|
|
|
return this.state.windows.map(window =>
|
2020-07-16 23:17:02 +02:00
|
|
|
<FloatingWindow {...window} close={this.close.bind(this, window.id)} minY={this.minY}>
|
2019-06-15 04:11:19 +02:00
|
|
|
{window.children}
|
2019-06-19 21:24:05 +02:00
|
|
|
</FloatingWindow>
|
2019-06-15 04:11:19 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
open(window) {
|
|
|
|
this.setState({
|
|
|
|
windows: [...this.state.windows, window]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
close(id) {
|
|
|
|
this.setState({
|
|
|
|
windows: this.state.windows.filter(w => {
|
|
|
|
if (w.id == id && w.onClose) w.onClose();
|
|
|
|
return w.id != id;
|
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
static get id() {return "floating-windows";}
|
|
|
|
static get root() {
|
|
|
|
if (this._root) return this._root;
|
|
|
|
const container = document.createElement("div");
|
|
|
|
container.id = this.id;
|
|
|
|
document.body.append(container);
|
|
|
|
return this._root = container;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-18 04:24:20 +02:00
|
|
|
export default FloatingWindowContainer;
|