@kieler/klighd-core
Version:
Core KLighD diagram visualization with Sprotty
174 lines • 9.55 kB
JavaScript
;
/*
* KIELER - Kiel Integrated Environment for Layout Eclipse RichClient
*
* http://rtsys.informatik.uni-kiel.de/kieler
*
* Copyright 2022-2024 by
* + Kiel University
* + Department of Computer Science
* + Real-Time and Embedded Systems Group
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*/
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;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ProxyViewActionHandler = exports.SendProxyViewAction = exports.ShowProxyViewAction = void 0;
// We follow Sprotty's way of redeclaring the interface and its create function, so disable this lint check for this file.
/* eslint-disable no-redeclare */
const constraint_classes_1 = require("@kieler/klighd-interactive/lib/constraint-classes");
const inversify_1 = require("inversify");
const sprotty_1 = require("sprotty");
const sprotty_protocol_1 = require("sprotty-protocol");
const actions_1 = require("../actions/actions");
const di_symbols_1 = require("../di.symbols");
const options_registry_1 = require("../options/options-registry");
const render_options_registry_1 = require("../options/render-options-registry");
const syntheses_registry_1 = require("../syntheses/syntheses-registry");
const proxy_view_1 = require("./proxy-view");
const proxy_view_options_1 = require("./proxy-view-options");
const proxy_view_util_1 = require("./proxy-view-util");
var ShowProxyViewAction;
(function (ShowProxyViewAction) {
function create() {
return sprotty_1.SetUIExtensionVisibilityAction.create({
extensionId: proxy_view_1.ProxyView.ID,
visible: true,
});
}
ShowProxyViewAction.create = create;
})(ShowProxyViewAction || (exports.ShowProxyViewAction = ShowProxyViewAction = {}));
var SendProxyViewAction;
(function (SendProxyViewAction) {
SendProxyViewAction.KIND = 'sendProxyViewAction';
function create(proxyView) {
return {
kind: SendProxyViewAction.KIND,
proxyView,
};
}
SendProxyViewAction.create = create;
})(SendProxyViewAction || (exports.SendProxyViewAction = SendProxyViewAction = {}));
/** Handles all actions and mouse events regarding the {@link ProxyView}. */
let ProxyViewActionHandler = class ProxyViewActionHandler extends sprotty_1.MouseListener {
constructor() {
super(...arguments);
this.mouseMoved = false;
}
/// / Mouse events ////
mouseDown(_target, event) {
this.mouseMoved = false;
if (this.proxyView) {
this.proxyView.setMouseDown(event);
}
return [];
}
mouseMove() {
this.mouseMoved = true;
return [];
}
mouseUp(target, event) {
let action;
if (!this.mouseMoved &&
target instanceof constraint_classes_1.KNode &&
event.target instanceof SVGElement &&
(0, proxy_view_util_1.isProxyRendering)(event.target, target.id)) {
// TODO: Use the FitToScreenAction if the node is larger than the canvas.
// Center on node when proxy is clicked
// if (target.bounds.width > canvas.width || target.bounds.height > canvas.height) {
// // Node is larger than canvas, zoom out so the node is fully on-screen
// action = FitToScreenAction.create([getNodeId(target.id)], { animate: true, padding: 10 })
// } else {
// // Retain the zoom, e.g. don't zoom in
action = sprotty_protocol_1.CenterAction.create([(0, proxy_view_util_1.getNodeId)(target.id)], { animate: true, retainZoom: true });
// }
}
if (this.proxyView) {
this.proxyView.setMouseUp();
}
return action ? [action] : [];
}
/// / Actions ////
init() {
// Register options
// Proxy-view
this.renderOptionsRegistry.registerAll(proxy_view_options_1.ProxyViewCategory, proxy_view_options_1.ProxyViewEnabled, proxy_view_options_1.ProxyViewSize, proxy_view_options_1.ProxyViewDecreaseProxyClutter, proxy_view_options_1.ProxyViewEnableEdgeProxies, proxy_view_options_1.ProxyViewDrawEdgesAboveNodes, proxy_view_options_1.ProxyViewEnableSegmentProxies, proxy_view_options_1.ProxyViewInteractiveProxies, proxy_view_options_1.ProxyViewTitleScaling);
// Proxy-view debug
this.renderOptionsRegistry.registerAll(proxy_view_options_1.ProxyViewDebugCategory, proxy_view_options_1.ProxyViewHighlightSelected, proxy_view_options_1.ProxyViewOpacityBySelected, proxy_view_options_1.ProxyViewUseSynthesisProxyRendering, proxy_view_options_1.ProxyViewSimpleAlongBorderRouting, proxy_view_options_1.ProxyViewCapProxyToParent, proxy_view_options_1.ProxyViewShowProxiesImmediately, proxy_view_options_1.ProxyViewShowProxiesEarly, proxy_view_options_1.ProxyViewShowProxiesEarlyNumber, proxy_view_options_1.ProxyViewStackingOrderByDistance, proxy_view_options_1.ProxyViewStackingOrderByOpacity, proxy_view_options_1.ProxyViewStackingOrderBySelected, proxy_view_options_1.ProxyViewUseDetailLevel, proxy_view_options_1.ProxyViewEdgesToOffScreenPoint, proxy_view_options_1.ProxyViewTransparentEdges, proxy_view_options_1.ProxyViewOriginalNodeScale, proxy_view_options_1.ProxyViewCapScaleToOne, proxy_view_options_1.ProxyViewClusterTransparent, proxy_view_options_1.ProxyViewClusteringCascading, proxy_view_options_1.ProxyViewClusteringSweepLine);
}
handle(action) {
if (action.kind === SendProxyViewAction.KIND) {
// Save the proxy-view instance
const sPVAction = action;
this.proxyView = sPVAction.proxyView;
// Register to receive updates on registry changes
// Do this here instead of in init() to ensure proxyView isn't undefined
if (!this.onChangeRegistered) {
// Make sure the rendering cache is cleared when the renderings change
this.synthesesRegistry.onChange(() => this.proxyView.reset());
this.optionsRegistry.onChange(() => this.proxyView.clearRenderings());
// Make sure to be notified when rendering options are changed
this.renderOptionsRegistry.onChange(() => this.proxyView.updateOptions(this.renderOptionsRegistry));
// Initialize the proxy view with all current options.
this.proxyView.updateOptions(this.renderOptionsRegistry);
this.onChangeRegistered = true;
}
}
else if (this.proxyView) {
if (action.kind === actions_1.SendModelContextAction.KIND) {
// Redirect the content to the proxy-view
const { model, context } = action;
this.proxyView.update(model, context);
}
else if ([sprotty_protocol_1.SetModelAction.KIND, sprotty_protocol_1.UpdateModelAction.KIND].includes(action.kind)) {
// Layout has changed, new model
this.proxyView.reset();
}
}
}
initialize(registry) {
// Register as a handler to receive the actions
registry.register(actions_1.SendModelContextAction.KIND, this);
registry.register(SendProxyViewAction.KIND, this);
// Layout changes
registry.register(sprotty_protocol_1.SetModelAction.KIND, this);
registry.register(sprotty_protocol_1.UpdateModelAction.KIND, this);
}
};
exports.ProxyViewActionHandler = ProxyViewActionHandler;
__decorate([
(0, inversify_1.inject)(di_symbols_1.DISymbol.SynthesesRegistry),
__metadata("design:type", syntheses_registry_1.SynthesesRegistry)
], ProxyViewActionHandler.prototype, "synthesesRegistry", void 0);
__decorate([
(0, inversify_1.inject)(di_symbols_1.DISymbol.RenderOptionsRegistry),
__metadata("design:type", render_options_registry_1.RenderOptionsRegistry)
], ProxyViewActionHandler.prototype, "renderOptionsRegistry", void 0);
__decorate([
(0, inversify_1.inject)(di_symbols_1.DISymbol.OptionsRegistry),
__metadata("design:type", options_registry_1.OptionsRegistry
/** Whether the proxy-view was registered in the registries' onchange() method. Prevents registering multiple times. */
)
], ProxyViewActionHandler.prototype, "optionsRegistry", void 0);
__decorate([
(0, inversify_1.postConstruct)(),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], ProxyViewActionHandler.prototype, "init", null);
exports.ProxyViewActionHandler = ProxyViewActionHandler = __decorate([
(0, inversify_1.injectable)()
], ProxyViewActionHandler);
//# sourceMappingURL=proxy-view-actions.js.map