UNPKG

@antv/x6

Version:

JavaScript diagramming library that uses SVG and HTML for rendering.

145 lines 6.02 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.PanningManager = void 0; var types_1 = require("../types"); var util_1 = require("../util"); var base_1 = require("./base"); var PanningManager = /** @class */ (function (_super) { __extends(PanningManager, _super); function PanningManager() { return _super !== null && _super.apply(this, arguments) || this; } Object.defineProperty(PanningManager.prototype, "widgetOptions", { get: function () { return this.options.panning; }, enumerable: false, configurable: true }); Object.defineProperty(PanningManager.prototype, "pannable", { get: function () { return this.widgetOptions && this.widgetOptions.enabled === true; }, enumerable: false, configurable: true }); PanningManager.prototype.init = function () { this.startListening(); this.updateClassName(); }; PanningManager.prototype.startListening = function () { this.graph.on('blank:mousedown', this.preparePanning, this); this.graph.on('node:unhandled:mousedown', this.preparePanning, this); this.graph.on('edge:unhandled:mousedown', this.preparePanning, this); }; PanningManager.prototype.stopListening = function () { this.graph.off('blank:mousedown', this.preparePanning, this); this.graph.off('node:unhandled:mousedown', this.preparePanning, this); this.graph.off('edge:unhandled:mousedown', this.preparePanning, this); }; PanningManager.prototype.preparePanning = function (_a) { var e = _a.e; if (this.allowPanning(e, true) || (this.allowPanning(e) && !this.graph.selection.allowRubberband(e, true))) { this.startPanning(e); } }; PanningManager.prototype.allowPanning = function (e, strict) { return (this.pannable && types_1.ModifierKey.isMatch(e, this.widgetOptions.modifiers, strict) && this.graph.hook.allowPanning(e)); }; PanningManager.prototype.startPanning = function (evt) { var e = this.view.normalizeEvent(evt); this.clientX = e.clientX; this.clientY = e.clientY; this.panning = true; this.updateClassName(); this.view.$(document.body).on({ 'mousemove.panning touchmove.panning': this.pan.bind(this), 'mouseup.panning touchend.panning': this.stopPanning.bind(this), }); this.view.$(window).on('mouseup.panning', this.stopPanning.bind(this)); }; PanningManager.prototype.pan = function (evt) { var e = this.view.normalizeEvent(evt); var dx = e.clientX - this.clientX; var dy = e.clientY - this.clientY; this.clientX = e.clientX; this.clientY = e.clientY; this.graph.translateBy(dx, dy); }; PanningManager.prototype.stopPanning = function (e) { this.panning = false; this.updateClassName(); this.view.$(document.body).off('.panning'); this.view.$(window).off('.panning'); }; PanningManager.prototype.updateClassName = function () { var container = this.view.container; var panning = this.view.prefixClassName('graph-panning'); var pannable = this.view.prefixClassName('graph-pannable'); if (this.pannable) { if (this.panning) { util_1.Dom.addClass(container, panning); util_1.Dom.removeClass(container, pannable); } else { util_1.Dom.removeClass(container, panning); util_1.Dom.addClass(container, pannable); } } else { util_1.Dom.removeClass(container, panning); util_1.Dom.removeClass(container, pannable); } }; PanningManager.prototype.enablePanning = function () { if (!this.pannable) { this.widgetOptions.enabled = true; this.updateClassName(); // if ( // ModifierKey.equals( // this.graph.options.panning.modifiers, // this.graph.options.selecting.modifiers, // ) // ) { // this.graph.selection.disableRubberband() // } } }; PanningManager.prototype.disablePanning = function () { if (this.pannable) { this.widgetOptions.enabled = false; this.updateClassName(); } }; PanningManager.prototype.dispose = function () { this.stopListening(); }; __decorate([ base_1.Base.dispose() ], PanningManager.prototype, "dispose", null); return PanningManager; }(base_1.Base)); exports.PanningManager = PanningManager; //# sourceMappingURL=panning.js.map