sprotty
Version:
A next-gen framework for graphical views
102 lines • 4.72 kB
JavaScript
;
/********************************************************************************
* Copyright (c) 2017-2018 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.ComputedBoundsApplicator = exports.ModelSource = void 0;
const inversify_1 = require("inversify");
const actions_1 = require("sprotty-protocol/lib/actions");
const model_utils_1 = require("sprotty-protocol/lib/utils/model-utils");
const types_1 = require("../base/types");
/**
* A model source is serving the model to the event cycle. It represents
* the entry point to the client for external sources, such as model
* editors.
*
* As an `IActionHandler` it listens to actions in and reacts to them with
* commands or actions if necessary. This way, you can implement action
* protocols between the client and the outside world.
*
* There are two default implementations for a ModelSource:
*
* - The `LocalModelSource` handles the actions to calculate bounds and
* set/update the model
* - the `DiagramServerProxy` connects via websocket to a remote source.
* It can be used to connect to a model editor that provides the model,
* layouts diagrams, transfers selection and answers model queries from
* the client.
*/
let ModelSource = class ModelSource {
initialize(registry) {
// Register this model source
registry.register(actions_1.RequestModelAction.KIND, this);
registry.register(actions_1.ExportSvgAction.KIND, this);
}
};
exports.ModelSource = ModelSource;
__decorate([
(0, inversify_1.inject)(types_1.TYPES.IActionDispatcher),
__metadata("design:type", Object)
], ModelSource.prototype, "actionDispatcher", void 0);
__decorate([
(0, inversify_1.inject)(types_1.TYPES.ViewerOptions),
__metadata("design:type", Object)
], ModelSource.prototype, "viewerOptions", void 0);
exports.ModelSource = ModelSource = __decorate([
(0, inversify_1.injectable)()
], ModelSource);
let ComputedBoundsApplicator = class ComputedBoundsApplicator {
apply(root, action) {
const index = new model_utils_1.SModelIndex();
index.add(root);
for (const b of action.bounds) {
const element = index.getById(b.elementId);
if (element !== undefined)
this.applyBounds(element, b.newPosition, b.newSize);
}
if (action.alignments !== undefined) {
for (const a of action.alignments) {
const element = index.getById(a.elementId);
if (element !== undefined)
this.applyAlignment(element, a.newAlignment);
}
}
return index;
}
applyAlignment(element, newAlignment) {
const e = element;
e.alignment = { x: newAlignment.x, y: newAlignment.y };
}
applyBounds(element, newPosition, newSize) {
const e = element;
if (newPosition)
e.position = Object.assign({}, newPosition);
e.size = Object.assign({}, newSize);
}
};
exports.ComputedBoundsApplicator = ComputedBoundsApplicator;
exports.ComputedBoundsApplicator = ComputedBoundsApplicator = __decorate([
(0, inversify_1.injectable)()
], ComputedBoundsApplicator);
//# sourceMappingURL=model-source.js.map