2018-10-10 07:56:23 -04:00
|
|
|
import { observes } from "ember-addons/ember-computed-decorators";
|
2016-12-01 13:54:21 -05:00
|
|
|
|
|
|
|
export default Ember.Component.extend({
|
2018-10-10 07:56:23 -04:00
|
|
|
@observes("hideSchema")
|
2016-12-01 13:54:21 -05:00
|
|
|
_onHideSchema() {
|
2018-10-10 07:56:23 -04:00
|
|
|
this.appEvents.trigger("ace:resize");
|
2016-12-01 13:54:21 -05:00
|
|
|
},
|
|
|
|
|
2018-10-10 07:56:23 -04:00
|
|
|
@observes("everEditing")
|
2016-12-01 13:54:21 -05:00
|
|
|
_onInsertEditor() {
|
2018-10-10 07:56:23 -04:00
|
|
|
Ember.run.schedule("afterRender", this, () => this._bindControls());
|
2016-12-01 13:54:21 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_bindControls() {
|
|
|
|
if (this._state !== "inDOM") {
|
|
|
|
return;
|
|
|
|
}
|
2019-04-07 02:05:43 -04:00
|
|
|
const $editPane = this.$(".query-editor");
|
2016-12-01 13:54:21 -05:00
|
|
|
if (!$editPane.length) {
|
|
|
|
return;
|
|
|
|
}
|
2019-04-07 02:05:43 -04:00
|
|
|
|
2018-10-10 07:56:23 -04:00
|
|
|
const oldGrippie = this.get("grippie");
|
2016-12-01 13:54:21 -05:00
|
|
|
if (oldGrippie) {
|
2018-10-10 07:56:23 -04:00
|
|
|
oldGrippie.off("mousedown mousemove mouseup");
|
2016-12-01 13:54:21 -05:00
|
|
|
}
|
|
|
|
|
2018-10-10 07:56:23 -04:00
|
|
|
const $grippie = $editPane.find(".grippie");
|
2019-04-07 02:05:43 -04:00
|
|
|
const $target = $editPane.find(".panels-flex");
|
|
|
|
const $document = Ember.$(document);
|
|
|
|
|
|
|
|
const minWidth = $target.width();
|
|
|
|
const minHeight = $target.height();
|
2016-12-01 13:54:21 -05:00
|
|
|
|
2018-10-10 07:56:23 -04:00
|
|
|
this.set("grippie", $grippie);
|
2016-12-01 13:54:21 -05:00
|
|
|
|
2019-04-07 02:05:43 -04:00
|
|
|
const mousemove = e => {
|
|
|
|
const diffY = this.get("startY") - e.screenY;
|
|
|
|
const diffX = this.get("startX") - e.screenX;
|
2016-12-01 13:54:21 -05:00
|
|
|
|
2019-04-07 02:05:43 -04:00
|
|
|
const newHeight = Math.max(minHeight, this.get("startHeight") - diffY);
|
|
|
|
const newWidth = Math.max(minWidth, this.get("startWidth") - diffX);
|
|
|
|
|
|
|
|
$target.height(newHeight);
|
|
|
|
$target.width(newWidth);
|
|
|
|
$grippie.width(newWidth);
|
|
|
|
this.appEvents.trigger("ace:resize");
|
2016-12-01 13:54:21 -05:00
|
|
|
};
|
|
|
|
|
2019-04-07 02:05:43 -04:00
|
|
|
const throttledMousemove = (event => {
|
|
|
|
event.preventDefault();
|
|
|
|
Ember.run.throttle(this, mousemove, event, 20);
|
|
|
|
}).bind(this);
|
|
|
|
|
|
|
|
const mouseup = (e => {
|
|
|
|
$document.off("mousemove", throttledMousemove);
|
|
|
|
$document.off("mouseup", mouseup);
|
|
|
|
this.setProperties({
|
|
|
|
startY: null,
|
|
|
|
startX: null,
|
|
|
|
startHeight: null,
|
|
|
|
startWidth: null
|
|
|
|
});
|
|
|
|
}).bind(this);
|
|
|
|
|
|
|
|
$grippie.on("mousedown", e => {
|
|
|
|
this.setProperties({
|
|
|
|
startY: e.screenY,
|
|
|
|
startX: e.screenX,
|
|
|
|
startHeight: $target.height(),
|
|
|
|
startWidth: $target.width()
|
|
|
|
});
|
2016-12-01 13:54:21 -05:00
|
|
|
|
2019-04-07 02:05:43 -04:00
|
|
|
$document.on("mousemove", throttledMousemove);
|
|
|
|
$document.on("mouseup", mouseup);
|
2016-12-01 13:54:21 -05:00
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
didInsertElement() {
|
|
|
|
this._super();
|
|
|
|
this._bindControls();
|
|
|
|
},
|
|
|
|
|
|
|
|
willDestroyElement() {
|
|
|
|
this._super();
|
2018-10-10 07:56:23 -04:00
|
|
|
if (this.get("everEditing")) {
|
|
|
|
this.get("grippie").off("mousedown");
|
|
|
|
this.set("grippie", null);
|
2016-12-01 13:54:21 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|