@eclipse-glsp/client
Version:
A sprotty-based client for GLSP
164 lines • 9.24 kB
JavaScript
"use strict";
/********************************************************************************
* Copyright (c) 2021-2025 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
********************************************************************************/
Object.defineProperty(exports, "__esModule", { value: true });
exports.DEFAULT_MODULES = void 0;
exports.createDiagramOptionsModule = createDiagramOptionsModule;
exports.configureDiagramOptions = configureDiagramOptions;
exports.initializeDiagramContainer = initializeDiagramContainer;
const sprotty_1 = require("@eclipse-glsp/sprotty");
const default_module_1 = require("./base/default.module");
const bounds_module_1 = require("./features/bounds/bounds-module");
const resize_module_1 = require("./features/change-bounds/resize/resize-module");
const command_palette_module_1 = require("./features/command-palette/command-palette-module");
const context_menu_module_1 = require("./features/context-menu/context-menu-module");
const copy_paste_modules_1 = require("./features/copy-paste/copy-paste-modules");
const decoration_module_1 = require("./features/decoration/decoration-module");
const element_template_module_1 = require("./features/element-template/element-template-module");
const export_modules_1 = require("./features/export/export-modules");
const type_hints_module_1 = require("./features/hints/type-hints-module");
const hover_module_1 = require("./features/hover/hover-module");
const label_edit_ui_module_1 = require("./features/label-edit-ui/label-edit-ui-module");
const label_edit_module_1 = require("./features/label-edit/label-edit-module");
const layout_module_1 = require("./features/layout/layout-module");
const navigation_module_1 = require("./features/navigation/navigation-module");
const routing_module_1 = require("./features/routing/routing-module");
const search_palette_module_1 = require("./features/search-palette/search-palette-module");
const select_module_1 = require("./features/select/select-module");
const source_model_watcher_module_1 = require("./features/source-model-watcher/source-model-watcher-module");
const status_module_1 = require("./features/status/status-module");
const svg_metadata_module_1 = require("./features/svg-metadata/svg-metadata-module");
const tool_palette_module_1 = require("./features/tool-palette/tool-palette-module");
const change_bounds_tool_module_1 = require("./features/tools/change-bounds/change-bounds-tool-module");
const deletion_tool_module_1 = require("./features/tools/deletion/deletion-tool-module");
const edege_creation_module_1 = require("./features/tools/edge-creation/edege-creation-module");
const edge_edit_module_1 = require("./features/tools/edge-edit/edge-edit-module");
const marquee_selection_module_1 = require("./features/tools/marquee-selection/marquee-selection-module");
const node_creation_module_1 = require("./features/tools/node-creation/node-creation-module");
const tool_focus_loss_module_1 = require("./features/tools/tool-focus-loss-module");
const validation_modules_1 = require("./features/validation/validation-modules");
const viewport_modules_1 = require("./features/viewport/viewport-modules");
const zorder_module_1 = require("./features/zorder/zorder-module");
exports.DEFAULT_MODULES = [
default_module_1.defaultModule,
sprotty_1.buttonModule,
sprotty_1.edgeIntersectionModule,
sprotty_1.edgeLayoutModule,
sprotty_1.expandModule,
export_modules_1.exportModule,
sprotty_1.fadeModule,
bounds_module_1.boundsModule,
command_palette_module_1.commandPaletteModule,
context_menu_module_1.contextMenuModule,
decoration_module_1.decorationModule,
label_edit_module_1.labelEditModule,
hover_module_1.hoverModule,
select_module_1.selectModule,
copy_paste_modules_1.copyPasteModule,
viewport_modules_1.viewportModule,
label_edit_ui_module_1.labelEditUiModule,
layout_module_1.layoutModule,
validation_modules_1.markerNavigatorModule,
type_hints_module_1.typeHintsModule,
sprotty_1.modelSourceModule,
source_model_watcher_module_1.sourceModelWatcherModule,
navigation_module_1.navigationModule,
routing_module_1.routingModule,
tool_palette_module_1.toolPaletteModule,
edege_creation_module_1.edgeCreationToolModule,
edge_edit_module_1.edgeEditToolModule,
deletion_tool_module_1.deletionToolModule,
element_template_module_1.elementTemplateModule,
node_creation_module_1.nodeCreationToolModule,
change_bounds_tool_module_1.changeBoundsToolModule,
marquee_selection_module_1.marqueeSelectionToolModule,
tool_focus_loss_module_1.toolFocusLossModule,
validation_modules_1.validationModule,
zorder_module_1.zorderModule,
svg_metadata_module_1.svgMetadataModule,
status_module_1.statusModule,
resize_module_1.resizeModule,
search_palette_module_1.searchPaletteModule,
search_palette_module_1.searchPaletteDefaultSuggestionsModule
];
/**
* Wraps the {@link configureDiagramOptions} utility function in a module. Adopters can either include this
* module into the container {@link ModuleConfiguration} or configure the container after its creation
* (e.g. using the {@link configureDiagramOptions} utility function).
* @param diagramOptions The diagram instance specific configuration options
* @param viewerOptions Optional {@link ViewerOptions} that should be configured
* @returns The corresponding {@link FeatureModule}
*/
function createDiagramOptionsModule(diagramOptions, viewerOptions) {
return new sprotty_1.FeatureModule((bind, unbind, isBound, rebind) => configureDiagramOptions({ bind, unbind, isBound, rebind }, diagramOptions, viewerOptions));
}
/**
* Utility function to bind the diagram instance specific configuration options.
* In addition to binding the {@link IDiagramOptions} this function also overrides the
* {@link ViewerOptions} to match the given client id.
* @param context The binding context
* @param diagramOptions The {@link IDiagramOptions} that should be bound
* @param viewerOptions Optional {@link ViewerOptions} that should be configured
*/
function configureDiagramOptions(context, diagramOptions, viewerOptions) {
(0, sprotty_1.configureViewerOptions)(context, {
baseDiv: diagramOptions.clientId,
hiddenDiv: diagramOptions.clientId + '_hidden',
zoomLimits: { min: 0.1, max: 20 },
...viewerOptions
});
context.bind(sprotty_1.TYPES.IDiagramOptions).toConstantValue(diagramOptions);
}
/**
* Initializes a GLSP Diagram container with the GLSP default modules and the specified custom `modules`.
* Additional modules can be passed as direct arguments or as part of a {@link ModuleConfiguration}.
* ```typescript
* const container= createDiagramContainer(myModule1, myModule2)
* // or
* const container= createDiagramContainer({ add: [myModule1, myModule2]})
* ```
* Default modules can be excluded using {@link ModuleConfiguration}s.
* This means, you can still customize the default modules in two ways.
*
* First, you can exclude default modules and add a module with your custom code.
*
* ```typescript
* const container = createDiagramContainer({ add:myModelSourceWatcherModule, remove: modelSourceWatcherModule} );
* ```
*
* Second, you can unbind or rebind implementations that are originally bound in one of the default modules.
*
* ```typescript
* rebind(NavigationTargetResolver).to(MyNavigationTargetResolver);
* ```
* @param container The container that should be initialized
* @param containerConfigurations
* Custom modules to be loaded in addition to the default modules and/or default modules that should be excluded.
* @throws An error if the first module to load is not the `defaultModule` (or an equivalent custom replacement module)
* @returns The initialized container.
*/
function initializeDiagramContainer(container, ...containerConfigurations) {
const modules = (0, sprotty_1.resolveContainerConfiguration)(...exports.DEFAULT_MODULES, ...containerConfigurations);
// The `defaultModule` (or a custom replacement module with the same `featureId`) should be the first module that is
// loaded into the container
const firstModule = modules[0];
if (!firstModule || !(firstModule instanceof sprotty_1.FeatureModule && firstModule.featureId === default_module_1.defaultModule.featureId)) {
throw new Error('Invalid module configuration. The first module to load should be the `defaultModule` (or an equivalent replacement module)');
}
container.load(...modules);
return container;
}
//# sourceMappingURL=default-modules.js.map