@visactor/vgrammar-core
Version:
VGrammar is a visual grammar library
50 lines (45 loc) • 2.02 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: !0
}), exports.ViewDrag = void 0;
const vutils_1 = require("@visactor/vutils"), view_navigation_base_1 = require("./view-navigation-base");
class ViewDrag extends view_navigation_base_1.ViewNavigationBase {
constructor(view, option) {
super(view, Object.assign({}, ViewDrag.defaultOptions, option)), this.type = ViewDrag.type,
this.handleStart = e => {
!e || this.options.shouldStart && !this.options.shouldStart(e) || (this._isStarted = !0,
this._inited || this._initGrammars(), this.updateView("start", this.handleDragStart(e, this._state, {
reversed: this.options.reversed
}), "drag", e));
}, this.handleUpdateInner = e => {
this._isStarted && e && (!this.options.shouldUpdate || this.options.shouldUpdate(e)) && this.updateView("update", this.handleDragUpdate(e, this._state, {
reversed: this.options.reversed
}), "drag", e);
}, this.handleEnd = e => {
this._isStarted && e && (!this.options.shouldEnd || this.options.shouldEnd(e)) && (this.updateView("end", this.handleDragEnd(e, this._state, {
reversed: this.options.reversed
}), "drag", e), this._isStarted = !1);
}, this.handleUpdate = (0, vutils_1.throttle)(this.handleUpdateInner, this.options.throttle);
}
getEvents() {
return [ {
type: this.options.trigger,
handler: this.handleStart
}, {
type: this.options.endTrigger,
handler: this.handleEnd
}, {
type: this.options.updateTrigger,
handler: this.handleUpdate
} ];
}
}
exports.ViewDrag = ViewDrag, ViewDrag.type = "view-drag", ViewDrag.defaultOptions = {
realtime: !0,
reversed: !1,
trigger: "pointerdown",
updateTrigger: "pointermove",
endTrigger: "pointerup",
throttle: 100
};
//# sourceMappingURL=view-drag.js.map