UNPKG

sprotty

Version:

A next-gen framework for graphical views

154 lines 9.46 kB
"use strict"; /******************************************************************************** * 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 ********************************************************************************/ Object.defineProperty(exports, "__esModule", { value: true }); const inversify_1 = require("inversify"); const types_1 = require("./types"); const initialize_canvas_1 = require("./features/initialize-canvas"); const logging_1 = require("../utils/logging"); const action_dispatcher_1 = require("./actions/action-dispatcher"); const action_handler_1 = require("./actions/action-handler"); const command_stack_1 = require("./commands/command-stack"); const command_stack_options_1 = require("./commands/command-stack-options"); const smodel_factory_1 = require("./model/smodel-factory"); const animation_frame_syncer_1 = require("./animations/animation-frame-syncer"); const viewer_1 = require("./views/viewer"); const viewer_options_1 = require("./views/viewer-options"); const mouse_tool_1 = require("./views/mouse-tool"); const key_tool_1 = require("./views/key-tool"); const vnode_postprocessor_1 = require("./views/vnode-postprocessor"); const view_1 = require("./views/view"); const viewer_cache_1 = require("./views/viewer-cache"); const dom_helper_1 = require("./views/dom-helper"); const id_postprocessor_1 = require("./views/id-postprocessor"); const command_registration_1 = require("./commands/command-registration"); const css_class_postprocessor_1 = require("./views/css-class-postprocessor"); const set_model_1 = require("./features/set-model"); const ui_extension_registry_1 = require("./ui-extensions/ui-extension-registry"); const diagram_locker_1 = require("./actions/diagram-locker"); const defaultContainerModule = new inversify_1.ContainerModule((bind, _unbind, isBound) => { // Logging --------------------------------------------- bind(types_1.TYPES.ILogger).to(logging_1.NullLogger).inSingletonScope(); bind(types_1.TYPES.LogLevel).toConstantValue(logging_1.LogLevel.warn); // Registries --------------------------------------------- bind(types_1.TYPES.SModelRegistry).to(smodel_factory_1.SModelRegistry).inSingletonScope(); bind(action_handler_1.ActionHandlerRegistry).toSelf().inSingletonScope(); bind(types_1.TYPES.ActionHandlerRegistryProvider).toProvider(ctx => { return () => { return new Promise((resolve) => { resolve(ctx.container.get(action_handler_1.ActionHandlerRegistry)); }); }; }); bind(types_1.TYPES.ViewRegistry).to(view_1.ViewRegistry).inSingletonScope(); // Model Creation --------------------------------------------- bind(types_1.TYPES.IModelFactory).to(smodel_factory_1.SModelFactory).inSingletonScope(); // Action Dispatcher --------------------------------------------- bind(types_1.TYPES.IActionDispatcher).to(action_dispatcher_1.ActionDispatcher).inSingletonScope(); bind(types_1.TYPES.IActionDispatcherProvider).toProvider(ctx => { return () => { return new Promise((resolve) => { resolve(ctx.container.get(types_1.TYPES.IActionDispatcher)); }); }; }); bind(types_1.TYPES.IDiagramLocker).to(diagram_locker_1.DefaultDiagramLocker).inSingletonScope(); // Action handler bind(command_registration_1.CommandActionHandlerInitializer).toSelf().inSingletonScope(); bind(types_1.TYPES.IActionHandlerInitializer).toService(command_registration_1.CommandActionHandlerInitializer); // Command Stack --------------------------------------------- bind(types_1.TYPES.ICommandStack).to(command_stack_1.CommandStack).inSingletonScope(); bind(types_1.TYPES.ICommandStackProvider).toProvider(ctx => { return () => { return new Promise((resolve) => { resolve(ctx.container.get(types_1.TYPES.ICommandStack)); }); }; }); bind(types_1.TYPES.CommandStackOptions).toConstantValue((0, command_stack_options_1.defaultCommandStackOptions)()); // Viewer --------------------------------------------- bind(viewer_1.ModelViewer).toSelf().inSingletonScope(); bind(viewer_1.HiddenModelViewer).toSelf().inSingletonScope(); bind(viewer_1.PopupModelViewer).toSelf().inSingletonScope(); bind(types_1.TYPES.ModelViewer).toDynamicValue(ctx => { const container = ctx.container.createChild(); container.bind(types_1.TYPES.IViewer).toService(viewer_1.ModelViewer); container.bind(viewer_cache_1.ViewerCache).toSelf(); return container.get(viewer_cache_1.ViewerCache); }).inSingletonScope(); bind(types_1.TYPES.PopupModelViewer).toDynamicValue(ctx => { const container = ctx.container.createChild(); container.bind(types_1.TYPES.IViewer).toService(viewer_1.PopupModelViewer); container.bind(viewer_cache_1.ViewerCache).toSelf(); return container.get(viewer_cache_1.ViewerCache); }).inSingletonScope(); bind(types_1.TYPES.HiddenModelViewer).toService(viewer_1.HiddenModelViewer); bind(types_1.TYPES.IViewerProvider).toDynamicValue(ctx => { return { get modelViewer() { return ctx.container.get(types_1.TYPES.ModelViewer); }, get hiddenModelViewer() { return ctx.container.get(types_1.TYPES.HiddenModelViewer); }, get popupModelViewer() { return ctx.container.get(types_1.TYPES.PopupModelViewer); } }; }); bind(types_1.TYPES.ViewerOptions).toConstantValue((0, viewer_options_1.defaultViewerOptions)()); bind(types_1.TYPES.PatcherProvider).to(viewer_1.PatcherProvider).inSingletonScope(); bind(types_1.TYPES.DOMHelper).to(dom_helper_1.DOMHelper).inSingletonScope(); bind(types_1.TYPES.ModelRendererFactory).toFactory(ctx => { return (targetKind, processors, args = {}) => { const viewRegistry = ctx.container.get(types_1.TYPES.ViewRegistry); return new viewer_1.ModelRenderer(viewRegistry, targetKind, processors, args); }; }); // Tools & Postprocessors -------------------------------------- bind(id_postprocessor_1.IdPostprocessor).toSelf().inSingletonScope(); bind(types_1.TYPES.IVNodePostprocessor).toService(id_postprocessor_1.IdPostprocessor); bind(types_1.TYPES.HiddenVNodePostprocessor).toService(id_postprocessor_1.IdPostprocessor); bind(css_class_postprocessor_1.CssClassPostprocessor).toSelf().inSingletonScope(); bind(types_1.TYPES.IVNodePostprocessor).toService(css_class_postprocessor_1.CssClassPostprocessor); bind(types_1.TYPES.HiddenVNodePostprocessor).toService(css_class_postprocessor_1.CssClassPostprocessor); bind(mouse_tool_1.MouseTool).toSelf().inSingletonScope(); bind(types_1.TYPES.IVNodePostprocessor).toService(mouse_tool_1.MouseTool); bind(key_tool_1.KeyTool).toSelf().inSingletonScope(); bind(types_1.TYPES.IVNodePostprocessor).toService(key_tool_1.KeyTool); bind(vnode_postprocessor_1.FocusFixPostprocessor).toSelf().inSingletonScope(); bind(types_1.TYPES.IVNodePostprocessor).toService(vnode_postprocessor_1.FocusFixPostprocessor); bind(types_1.TYPES.PopupVNodePostprocessor).toService(id_postprocessor_1.IdPostprocessor); bind(mouse_tool_1.PopupMouseTool).toSelf().inSingletonScope(); bind(types_1.TYPES.PopupVNodePostprocessor).toService(mouse_tool_1.PopupMouseTool); // Animation Frame Sync ------------------------------------------ bind(types_1.TYPES.AnimationFrameSyncer).to(animation_frame_syncer_1.AnimationFrameSyncer).inSingletonScope(); // Canvas Initialization --------------------------------------------- const context = { bind, isBound }; (0, command_registration_1.configureCommand)(context, initialize_canvas_1.InitializeCanvasBoundsCommand); bind(initialize_canvas_1.CanvasBoundsInitializer).toSelf().inSingletonScope(); bind(types_1.TYPES.IVNodePostprocessor).toService(initialize_canvas_1.CanvasBoundsInitializer); // Model commands --------------------------------------------- (0, command_registration_1.configureCommand)(context, set_model_1.SetModelCommand); // UIExtension registry initialization ------------------------------------ bind(types_1.TYPES.UIExtensionRegistry).to(ui_extension_registry_1.UIExtensionRegistry).inSingletonScope(); (0, command_registration_1.configureCommand)(context, ui_extension_registry_1.SetUIExtensionVisibilityCommand); // Tracker for last known mouse position on diagram ------------------------ bind(mouse_tool_1.MousePositionTracker).toSelf().inSingletonScope(); bind(types_1.TYPES.MouseListener).toService(mouse_tool_1.MousePositionTracker); }); exports.default = defaultContainerModule; //# sourceMappingURL=di.config.js.map