UNPKG

@kieler/klighd-core

Version:

Core KLighD diagram visualization with Sprotty

51 lines 1.78 kB
"use strict"; /* * KIELER - Kiel Integrated Environment for Layout Eclipse RichClient * * http://rtsys.informatik.uni-kiel.de/kieler * * Copyright 2021-2023 by * + Kiel University * + Department of Computer Science * + Real-Time and Embedded Systems Group * * This code is provided under the terms of the Eclipse Public License 2.0 (EPL-2.0). */ Object.defineProperty(exports, "__esModule", { value: true }); exports.insertSModelElementIntoModel = void 0; /** * Utility function to insert an SModelElement into an existing model. * The id of the new piece must already be known by the model. That is to * say, there is already a placeholder element with the same id in the model. * @param modelRoot * @param modelElement */ function insertSModelElementIntoModel(modelRoot, modelElement) { // traverse model and search for insertion point replaceNodeById(modelRoot, modelElement); } exports.insertSModelElementIntoModel = insertSModelElementIntoModel; function replaceNodeById(root, modelElement) { const { id } = modelElement; if (root.children === undefined) { return; } // try to find element in current children const index = root.children.findIndex((child) => child.id === id); if (index > -1) { // replace if it exists // root.children[index] = modelElement root.remove(root.children[index]); root.add(modelElement, index); } else { // recurse further down otherwise root.children.forEach((childNode) => { // find correct child to descend into by pattern matching ids if (id.startsWith(childNode.id)) { replaceNodeById(childNode, modelElement); } }); } } //# sourceMappingURL=smodel-util.js.map