UNPKG

@eclipse-glsp/client

Version:

A sprotty-based client for GLSP

136 lines 6.81 kB
"use strict"; /******************************************************************************** * Copyright (c) 2023-2024 EclipseSource 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.DiagramLoader = exports.IDiagramStartup = void 0; const sprotty_1 = require("@eclipse-glsp/sprotty"); const inversify_1 = require("inversify"); const ranked_1 = require("../ranked"); const glsp_model_source_1 = require("./glsp-model-source"); const model_initialization_constraint_1 = require("./model-initialization-constraint"); var IDiagramStartup; (function (IDiagramStartup) { function is(object) { return (sprotty_1.AnyObject.is(object) && (0, sprotty_1.hasNumberProp)(object, 'rank', true) && ('preLoadDiagram' in object || 'preInitialize' in object || 'preRequestModel' in object || 'postRequestModel' in object || 'postModelInitialization' in object)); } IDiagramStartup.is = is; })(IDiagramStartup || (exports.IDiagramStartup = IDiagramStartup = {})); /** * The central component responsible for initializing the diagram and loading the graphical model * from the GLSP server. * Invoking the {@link DiagramLoader.load} method is typically the first operation that is executed after * a diagram DI container has been created. */ let DiagramLoader = class DiagramLoader { get diagramStartups() { return this.lazyInjector.getAll(sprotty_1.TYPES.IDiagramStartup); } async load(options = {}) { var _a, _b, _c, _d; this.diagramStartups.sort(ranked_1.Ranked.sort); await this.invokeStartupHook('preLoadDiagram'); const resolvedOptions = { requestModelOptions: { sourceUri: (_a = this.options.sourceUri) !== null && _a !== void 0 ? _a : '', diagramType: this.options.diagramType, ...options.requestModelOptions }, initializeParameters: { applicationId: sprotty_1.ApplicationIdProvider.get(), protocolVersion: sprotty_1.GLSPClient.protocolVersion, ...options.initializeParameters }, enableNotifications: (_b = options.enableNotifications) !== null && _b !== void 0 ? _b : true }; // Ensure that the action dispatcher is initialized before starting the diagram loading process await ((_d = (_c = this.actionDispatcher).initialize) === null || _d === void 0 ? void 0 : _d.call(_c)); await this.invokeStartupHook('preInitialize'); await this.initialize(resolvedOptions); await this.invokeStartupHook('preRequestModel'); await this.requestModel(resolvedOptions); await this.invokeStartupHook('postRequestModel'); await this.modelInitializationConstraint.onInitialized(); await this.invokeStartupHook('postModelInitialization'); } async invokeStartupHook(hook) { var _a; for (const startup of this.diagramStartups) { try { await ((_a = startup[hook]) === null || _a === void 0 ? void 0 : _a.call(startup)); } catch (err) { console.error(`Error invoking diagram startup hook '${hook}':`, '\n', err); } } } async requestModel(options) { await this.actionDispatcher.dispatch(sprotty_1.RequestModelAction.create({ options: options.requestModelOptions, requestId: sprotty_1.RequestAction.generateRequestId() })); } async initialize(options) { if (options.enableNotifications) { await this.actionDispatcher.dispatch(sprotty_1.StatusAction.create('Initializing...', { severity: 'INFO' })); } const glspClient = await this.options.glspClientProvider(); await glspClient.start(); if (!glspClient.initializeResult) { await glspClient.initializeServer(options.initializeParameters); } this.modelSource.configure(glspClient); if (options.enableNotifications) { this.actionDispatcher.dispatch(sprotty_1.StatusAction.create('', { severity: 'NONE' })); } } }; exports.DiagramLoader = DiagramLoader; __decorate([ (0, inversify_1.inject)(sprotty_1.TYPES.IDiagramOptions), __metadata("design:type", Object) ], DiagramLoader.prototype, "options", void 0); __decorate([ (0, inversify_1.inject)(sprotty_1.TYPES.IActionDispatcher), __metadata("design:type", Object) ], DiagramLoader.prototype, "actionDispatcher", void 0); __decorate([ (0, inversify_1.inject)(glsp_model_source_1.GLSPModelSource), __metadata("design:type", glsp_model_source_1.GLSPModelSource) ], DiagramLoader.prototype, "modelSource", void 0); __decorate([ (0, inversify_1.inject)(model_initialization_constraint_1.ModelInitializationConstraint), __metadata("design:type", model_initialization_constraint_1.ModelInitializationConstraint) ], DiagramLoader.prototype, "modelInitializationConstraint", void 0); __decorate([ (0, inversify_1.inject)(sprotty_1.LazyInjector), __metadata("design:type", Object) ], DiagramLoader.prototype, "lazyInjector", void 0); exports.DiagramLoader = DiagramLoader = __decorate([ (0, inversify_1.injectable)() ], DiagramLoader); //# sourceMappingURL=diagram-loader.js.map