UNPKG

@kieler/klighd-core

Version:

Core KLighD diagram visualization with Sprotty

115 lines 5.4 kB
"use strict"; /* * KIELER - Kiel Integrated Environment for Layout Eclipse RichClient * * http://rtsys.informatik.uni-kiel.de/kieler * * Copyright 2021-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); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SidebarPanelRegistry = void 0; const inversify_1 = require("inversify"); const registry_1 = require("../base/registry"); const di_symbols_1 = require("../di.symbols"); const render_options_registry_1 = require("../options/render-options-registry"); const services_1 = require("../services"); const actions_1 = require("./actions"); /** * {@link Registry} that stores all sidebar panels which are resolved by the DI container. * At most one panel is considered active. The state (which panel is active) can * be changed with a {@link ToggleSidebarPanelAction}. */ let SidebarPanelRegistry = class SidebarPanelRegistry extends registry_1.Registry { constructor(panels = []) { super(); this._panels = new Map(); this._currentPanelID = null; for (const panel of panels) { this._panels.set(panel.id, panel); } } init() { // Reopen general panel if a panel was pinned. // Record has to be retrieved manually since the renderOptionsRegistry is not yet initialized and // cannot be changed to distribute a ready signal. this.storage.getItem('render').then((data) => { for (const entry of Object.entries(data)) { if (entry[0] === render_options_registry_1.PinSidebarOption.ID && entry[1] && this.allPanels.length > 0) { this._currentPanelID = this.allPanels[0].id; } } }); } handle(action) { if (actions_1.ToggleSidebarPanelAction.isThisAction(action)) { // Nothing to do if the panel should be shown/hidden and is already active/inactive. if (this._currentPanelID === action.id && action.state === 'show') return; if (this._currentPanelID !== action.id && action.state === 'hide') return; if (this._currentPanelID === action.id) { // Panel is active so it should either be hidden explicitly or toggled to be hidden this._currentPanelID = null; this.notifyListeners(); } else if (this._panels.has(action.id)) { // Panel is inactive and the given id exists so it should either be shown explicitly or toggled to be shown this._currentPanelID = action.id; this.notifyListeners(); } } } get allPanels() { // Sort the panels before they are returned. There won't be any considerable // amount of panels that could cause performance concerns. If sorting becomes // an issue, it could be moved to the constructor to only be applied once. This // would only work as long as it is not possible to add panels dynamically. return Array.from(this._panels.values()).sort((p1, p2) => p1.position - p2.position); } get currentPanel() { var _a; return this._currentPanelID === null ? null : (_a = this._panels.get(this._currentPanelID)) !== null && _a !== void 0 ? _a : null; } get currentPanelID() { return this._currentPanelID; } }; exports.SidebarPanelRegistry = SidebarPanelRegistry; __decorate([ (0, inversify_1.inject)(services_1.ServiceTypes.PersistenceStorage), __metadata("design:type", Object) ], SidebarPanelRegistry.prototype, "storage", void 0); __decorate([ (0, inversify_1.postConstruct)(), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], SidebarPanelRegistry.prototype, "init", null); exports.SidebarPanelRegistry = SidebarPanelRegistry = __decorate([ (0, inversify_1.injectable)(), __param(0, (0, inversify_1.multiInject)(di_symbols_1.DISymbol.SidebarPanel)), __param(0, (0, inversify_1.optional)()), __metadata("design:paramtypes", [Array]) ], SidebarPanelRegistry); //# sourceMappingURL=sidebar-panel-registry.js.map