sprotty
Version:
A next-gen framework for graphical views
93 lines • 5.17 kB
JavaScript
;
/********************************************************************************
* Copyright (c) 2024 TypeFox and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-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.JunctionPostProcessor = void 0;
const inversify_1 = require("inversify");
const sprotty_protocol_1 = require("sprotty-protocol");
const types_1 = require("../../base/types");
const model_source_1 = require("../../model-source/model-source");
/**
* Finds all junction points in the first SVG group element (diagram root level) and moves them to the end of the SVG.
* This ensures that junction points are rendered on top of all other elements.
*/
let JunctionPostProcessor = class JunctionPostProcessor {
constructor() {
this.isFirstRender = true;
}
decorate(vnode, element) {
return vnode;
}
postUpdate(cause) {
// if the model has changed, we need to remove the junction points from the previous model
if (this.currentModel !== this.modelSource.model) {
this.isFirstRender = true;
}
// if the cause of the update is a RequestBoundsAction (from the hidden model)
// and we are rendering the diagram for the first time (not from an update or setting the same model again)
// we need to remove the junction points from the previous model
if ((cause === null || cause === void 0 ? void 0 : cause.kind) === sprotty_protocol_1.RequestBoundsAction.KIND && this.isFirstRender) {
const junctionPointsInHiddenDiv = document.querySelectorAll(`#${this.viewerOptions.hiddenDiv} > svg > g > g.sprotty-junction`);
junctionPointsInHiddenDiv.forEach(e => e.remove());
const junctionPointsInBaseDiv = document.querySelectorAll(`#${this.viewerOptions.baseDiv} > svg > g > g.sprotty-junction`);
junctionPointsInBaseDiv.forEach(e => e.remove());
}
const hiddenSvg = document.querySelector(`#${this.viewerOptions.hiddenDiv} > svg > g`);
const baseSvg = document.querySelector(`#${this.viewerOptions.baseDiv} > svg > g`);
// move junction points to the end of the SVG in the hidden div
if (hiddenSvg) {
const junctionGroups = Array.from(document.querySelectorAll(`#${this.viewerOptions.hiddenDiv} > svg > g > g > g.sprotty-junction`));
junctionGroups.forEach(junctionGroup => {
junctionGroup.remove();
});
hiddenSvg.append(...junctionGroups);
}
// move junction points to the end of the SVG in the base div
if (baseSvg) {
const junctionGroups = Array.from(document.querySelectorAll(`#${this.viewerOptions.baseDiv} > svg > g > g > g.sprotty-junction`));
junctionGroups.forEach(junctionGroup => {
junctionGroup.remove();
});
baseSvg.append(...junctionGroups);
}
// update the current model
this.currentModel = this.modelSource.model;
// after the first render, we don't need to remove the junction points anymore
this.isFirstRender = false;
}
};
exports.JunctionPostProcessor = JunctionPostProcessor;
__decorate([
(0, inversify_1.inject)(types_1.TYPES.ViewerOptions),
__metadata("design:type", Object)
], JunctionPostProcessor.prototype, "viewerOptions", void 0);
__decorate([
(0, inversify_1.inject)(types_1.TYPES.ModelSource),
__metadata("design:type", model_source_1.ModelSource)
], JunctionPostProcessor.prototype, "modelSource", void 0);
exports.JunctionPostProcessor = JunctionPostProcessor = __decorate([
(0, inversify_1.injectable)()
], JunctionPostProcessor);
//# sourceMappingURL=junction-postprocessor.js.map