@eclipse-glsp/layout-elk 0.9.0-next.0193b16.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,47 @@
1
+ import { LayoutOptions } from 'elkjs/lib/elk.bundled';
2
+ import { ContainerModule } from 'inversify';
3
+ import { ElementFilter, LayoutConfigurator } from '.';
4
+ declare type Constructor<T> = new (...args: any[]) => T;
5
+ /**
6
+ * Configuration options for the {@link configureELKLayoutModule} function.
7
+ */
8
+ export interface ElkModuleOptions {
9
+ /**
10
+ * The set of elk algorithms that is used by the {@link GlspElkLayoutEngine}.
11
+ */
12
+ algorithms: string[];
13
+ /**
14
+ * Additional default layout options. This options are passed to the underlying {@link ElkFactory}.
15
+ * In addition, they are used to configure the {@link FallbackGlspLayoutConfigurator}.
16
+ */
17
+ defaultLayoutOptions?: LayoutOptions;
18
+ /**
19
+ * The custom {@link LayoutConfigurator} class that should be bound. If this option is not set
20
+ * the {@link FallbackLayoutConfigurator} is bound instead.
21
+ */
22
+ layoutConfigurator?: Constructor<LayoutConfigurator>;
23
+ /**
24
+ * The custom {@link ElementFilter} class that should be bound. If this option is not set, the default implementation
25
+ * is bound.
26
+ */
27
+ elementFilter?: Constructor<ElementFilter>;
28
+ }
29
+ /**
30
+ * Utility method to create a DI module that provides all necessary bindings to use the {@link GlspElkLayoutEngine} in a node GLSP server
31
+ * implementation. A set of configuration options is provided to enable easy customization. In most cases at least
32
+ * the custom {@link layoutConfigurator} binding should be provided (in addition to the required `algorithms' property) via these options.
33
+ *
34
+ * The constructed module is not intended for standalone use cases and only works in combination with a GLSPDiagramModule.
35
+ *
36
+ * * The following bindings are provided:
37
+ * - {@link ILayoutConfigurator}
38
+ * - {@link IElementFilter}
39
+ * - {@link LayoutEngine}
40
+ * - {@link ElkFactory}
41
+ *
42
+ * @param options The configuration options
43
+ * @returns A DI module that can be loaded as additional module when configuring a diagram module for a GLSP server.
44
+ */
45
+ export declare function configureELKLayoutModule(options: ElkModuleOptions): ContainerModule;
46
+ export {};
47
+ //# sourceMappingURL=di.config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"di.config.d.ts","sourceRoot":"","sources":["../src/di.config.ts"],"names":[],"mappings":"AAgBA,OAAuB,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAE5C,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,GAAG,CAAC;AAKtD,aAAK,WAAW,CAAC,CAAC,IAAI,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;AAEhD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC7B;;OAEG;IACH,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB;;;OAGG;IACH,oBAAoB,CAAC,EAAE,aAAa,CAAC;IACrC;;;OAGG;IACH,kBAAkB,CAAC,EAAE,WAAW,CAAC,kBAAkB,CAAC,CAAC;IACrD;;;OAGG;IACH,aAAa,CAAC,EAAE,WAAW,CAAC,aAAa,CAAC,CAAC;CAC9C;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,gBAAgB,GAAG,eAAe,CAoCnF"}
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.configureELKLayoutModule = void 0;
4
+ /********************************************************************************
5
+ * Copyright (c) 2022 STMicroelectronics and others.
6
+ *
7
+ * This program and the accompanying materials are made available under the
8
+ * terms of the Eclipse Public License v. 2.0 which is available at
9
+ * http://www.eclipse.org/legal/epl-2.0.
10
+ *
11
+ * This Source Code may also be made available under the following Secondary
12
+ * Licenses when the conditions for such availability set forth in the Eclipse
13
+ * Public License v. 2.0 are satisfied: GNU General Public License, version 2
14
+ * with the GNU Classpath Exception which is available at
15
+ * https://www.gnu.org/software/classpath/license.html.
16
+ *
17
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
18
+ ********************************************************************************/
19
+ const server_node_1 = require("@eclipse-glsp/server-node");
20
+ const elk_bundled_1 = require("elkjs/lib/elk.bundled");
21
+ const inversify_1 = require("inversify");
22
+ const sprotty_elk_1 = require("sprotty-elk");
23
+ const _1 = require(".");
24
+ const element_filter_1 = require("./element-filter");
25
+ const glsp_elk_layout_engine_1 = require("./glsp-elk-layout-engine");
26
+ const layout_configurator_1 = require("./layout-configurator");
27
+ /**
28
+ * Utility method to create a DI module that provides all necessary bindings to use the {@link GlspElkLayoutEngine} in a node GLSP server
29
+ * implementation. A set of configuration options is provided to enable easy customization. In most cases at least
30
+ * the custom {@link layoutConfigurator} binding should be provided (in addition to the required `algorithms' property) via these options.
31
+ *
32
+ * The constructed module is not intended for standalone use cases and only works in combination with a GLSPDiagramModule.
33
+ *
34
+ * * The following bindings are provided:
35
+ * - {@link ILayoutConfigurator}
36
+ * - {@link IElementFilter}
37
+ * - {@link LayoutEngine}
38
+ * - {@link ElkFactory}
39
+ *
40
+ * @param options The configuration options
41
+ * @returns A DI module that can be loaded as additional module when configuring a diagram module for a GLSP server.
42
+ */
43
+ function configureELKLayoutModule(options) {
44
+ return new inversify_1.ContainerModule(bind => {
45
+ if (options.elementFilter) {
46
+ bind(_1.ElementFilter).to(options.elementFilter).inSingletonScope();
47
+ }
48
+ else {
49
+ bind(_1.ElementFilter).to(element_filter_1.DefaultElementFilter).inSingletonScope();
50
+ }
51
+ if (options.layoutConfigurator) {
52
+ bind(_1.LayoutConfigurator).to(options.layoutConfigurator);
53
+ }
54
+ else {
55
+ bind(_1.LayoutConfigurator)
56
+ .toDynamicValue(context => new layout_configurator_1.FallbackLayoutConfigurator(options.algorithms, options.defaultLayoutOptions))
57
+ .inSingletonScope();
58
+ }
59
+ const elkFactory = () => new elk_bundled_1.default({
60
+ algorithms: options.algorithms,
61
+ defaultLayoutOptions: options.defaultLayoutOptions
62
+ });
63
+ bind(sprotty_elk_1.ElkFactory).toConstantValue(elkFactory);
64
+ bind(glsp_elk_layout_engine_1.GlspElkLayoutEngine)
65
+ .toDynamicValue(context => {
66
+ const container = context.container;
67
+ const factory = container.get(sprotty_elk_1.ElkFactory);
68
+ const filter = container.get(_1.ElementFilter);
69
+ const configurator = container.get(_1.LayoutConfigurator);
70
+ const modelState = container.get(server_node_1.ModelState);
71
+ return new glsp_elk_layout_engine_1.GlspElkLayoutEngine(factory, filter, configurator, modelState);
72
+ })
73
+ .inSingletonScope();
74
+ bind(server_node_1.LayoutEngine).toService(glsp_elk_layout_engine_1.GlspElkLayoutEngine);
75
+ });
76
+ }
77
+ exports.configureELKLayoutModule = configureELKLayoutModule;
78
+ //# sourceMappingURL=di.config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"di.config.js","sourceRoot":"","sources":["../src/di.config.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;kFAckF;AAClF,2DAAqE;AACrE,uDAAsE;AACtE,yCAA4C;AAC5C,6CAAyC;AACzC,wBAAsD;AACtD,qDAAwD;AACxD,qEAA+D;AAC/D,+DAAmE;AA6BnE;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,wBAAwB,CAAC,OAAyB;IAC9D,OAAO,IAAI,2BAAe,CAAC,IAAI,CAAC,EAAE;QAC9B,IAAI,OAAO,CAAC,aAAa,EAAE;YACvB,IAAI,CAAC,gBAAa,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,gBAAgB,EAAE,CAAC;SACpE;aAAM;YACH,IAAI,CAAC,gBAAa,CAAC,CAAC,EAAE,CAAC,qCAAoB,CAAC,CAAC,gBAAgB,EAAE,CAAC;SACnE;QAED,IAAI,OAAO,CAAC,kBAAkB,EAAE;YAC5B,IAAI,CAAC,qBAAkB,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;SAC3D;aAAM;YACH,IAAI,CAAC,qBAAkB,CAAC;iBACnB,cAAc,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,gDAA0B,CAAC,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,oBAAoB,CAAC,CAAC;iBAC3G,gBAAgB,EAAE,CAAC;SAC3B;QAED,MAAM,UAAU,GAAe,GAAG,EAAE,CAChC,IAAI,qBAAc,CAAC;YACf,UAAU,EAAE,OAAO,CAAC,UAAU;YAC9B,oBAAoB,EAAE,OAAO,CAAC,oBAAoB;SACrD,CAAC,CAAC;QAEP,IAAI,CAAC,wBAAU,CAAC,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC;QAE7C,IAAI,CAAC,4CAAmB,CAAC;aACpB,cAAc,CAAC,OAAO,CAAC,EAAE;YACtB,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;YACpC,MAAM,OAAO,GAAG,SAAS,CAAC,GAAG,CAAa,wBAAU,CAAC,CAAC;YACtD,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,CAAgB,gBAAa,CAAC,CAAC;YAC3D,MAAM,YAAY,GAAG,SAAS,CAAC,GAAG,CAAqB,qBAAkB,CAAC,CAAC;YAC3E,MAAM,UAAU,GAAG,SAAS,CAAC,GAAG,CAAa,wBAAU,CAAC,CAAC;YACzD,OAAO,IAAI,4CAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,UAAU,CAAC,CAAC;QAC9E,CAAC,CAAC;aACD,gBAAgB,EAAE,CAAC;QACxB,IAAI,CAAC,0BAAY,CAAC,CAAC,SAAS,CAAC,4CAAmB,CAAC,CAAC;IACtD,CAAC,CAAC,CAAC;AACP,CAAC;AApCD,4DAoCC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=di.config.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"di.config.spec.d.ts","sourceRoot":"","sources":["../src/di.config.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ 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;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ /********************************************************************************
10
+ * Copyright (c) 2022 STMicroelectronics and others.
11
+ *
12
+ * This program and the accompanying materials are made available under the
13
+ * terms of the Eclipse Public License v. 2.0 which is available at
14
+ * http://www.eclipse.org/legal/epl-2.0.
15
+ *
16
+ * This Source Code may also be made available under the following Secondary
17
+ * Licenses when the conditions for such availability set forth in the Eclipse
18
+ * Public License v. 2.0 are satisfied: GNU General Public License, version 2
19
+ * with the GNU Classpath Exception which is available at
20
+ * https://www.gnu.org/software/classpath/license.html.
21
+ *
22
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
23
+ ********************************************************************************/
24
+ const server_node_1 = require("@eclipse-glsp/server-node");
25
+ const mock_util_1 = require("@eclipse-glsp/server-node/lib/test/mock-util");
26
+ const chai_1 = require("chai");
27
+ const inversify_1 = require("inversify");
28
+ const sinon = require("sinon");
29
+ const _1 = require(".");
30
+ const di_config_1 = require("./di.config");
31
+ const element_filter_1 = require("./element-filter");
32
+ const layout_configurator_1 = require("./layout-configurator");
33
+ let CustomLayoutConfigurator = class CustomLayoutConfigurator extends _1.AbstractLayoutConfigurator {
34
+ };
35
+ CustomLayoutConfigurator = __decorate([
36
+ (0, inversify_1.injectable)()
37
+ ], CustomLayoutConfigurator);
38
+ let CustomElementFilter = class CustomElementFilter extends element_filter_1.DefaultElementFilter {
39
+ };
40
+ CustomElementFilter = __decorate([
41
+ (0, inversify_1.injectable)()
42
+ ], CustomElementFilter);
43
+ describe('test configureELKLayoutModule', () => {
44
+ const sandbox = sinon.createSandbox();
45
+ const mockDiagramConfiguration = new mock_util_1.StubDiagramConfiguration();
46
+ const typeMappings = new Map();
47
+ typeMappings.set('graph', server_node_1.GGraph);
48
+ sandbox.stub(mockDiagramConfiguration, 'typeMapping').value(typeMappings);
49
+ const modelState = new server_node_1.DefaultModelState();
50
+ const baseModule = new inversify_1.ContainerModule(bind => {
51
+ bind(server_node_1.ModelState).toConstantValue(modelState);
52
+ });
53
+ it('configure with minimal options', () => {
54
+ const algorithm = 'layered';
55
+ const elkModule = (0, di_config_1.configureELKLayoutModule)({ algorithms: [algorithm] });
56
+ const container = new inversify_1.Container();
57
+ container.load(baseModule, elkModule);
58
+ const filter = container.get(element_filter_1.ElementFilter);
59
+ (0, chai_1.expect)(filter).to.be.an.instanceOf(element_filter_1.DefaultElementFilter);
60
+ const configurator = container.get(layout_configurator_1.LayoutConfigurator);
61
+ (0, chai_1.expect)(configurator).to.be.an.instanceOf(layout_configurator_1.FallbackLayoutConfigurator);
62
+ const graphOptions = configurator.apply(new server_node_1.GGraph());
63
+ (0, chai_1.expect)(graphOptions).not.to.be.undefined;
64
+ (0, chai_1.expect)(graphOptions['elk.algorithm']).to.equal(algorithm);
65
+ });
66
+ it('configure with additional default layout options', () => {
67
+ const algorithm = 'layered';
68
+ const defaultLayoutOptions = {
69
+ 'elk.direction': 'LEFT',
70
+ 'elk.edgeRouting': 'POLYLINE'
71
+ };
72
+ const elkModule = (0, di_config_1.configureELKLayoutModule)({ algorithms: [algorithm], defaultLayoutOptions });
73
+ const container = new inversify_1.Container();
74
+ container.load(baseModule, elkModule);
75
+ const configurator = container.get(layout_configurator_1.LayoutConfigurator);
76
+ const graphOptions = configurator.apply(new server_node_1.GGraph());
77
+ (0, chai_1.expect)(graphOptions).not.to.be.undefined;
78
+ (0, chai_1.expect)(graphOptions).to.include(defaultLayoutOptions);
79
+ });
80
+ it('configure with custom layout configurator', () => {
81
+ const algorithm = 'layered';
82
+ const elkModule = (0, di_config_1.configureELKLayoutModule)({ algorithms: [algorithm], layoutConfigurator: CustomLayoutConfigurator });
83
+ const container = new inversify_1.Container();
84
+ container.load(baseModule, elkModule);
85
+ const configurator = container.get(layout_configurator_1.LayoutConfigurator);
86
+ (0, chai_1.expect)(configurator).to.be.an.instanceOf(CustomLayoutConfigurator);
87
+ });
88
+ it('configure with custom element filter', () => {
89
+ const algorithm = 'layered';
90
+ const elkModule = (0, di_config_1.configureELKLayoutModule)({ algorithms: [algorithm], elementFilter: CustomElementFilter });
91
+ const container = new inversify_1.Container();
92
+ container.load(baseModule, elkModule);
93
+ const filter = container.get(element_filter_1.ElementFilter);
94
+ (0, chai_1.expect)(filter).to.be.an.instanceOf(CustomElementFilter);
95
+ });
96
+ });
97
+ //# sourceMappingURL=di.config.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"di.config.spec.js","sourceRoot":"","sources":["../src/di.config.spec.ts"],"names":[],"mappings":";;;;;;;;AAAA;;;;;;;;;;;;;;kFAckF;AAClF,2DAA4G;AAC5G,4EAAwF;AACxF,+BAA8B;AAC9B,yCAAmE;AACnE,+BAA+B;AAC/B,wBAA+C;AAC/C,2CAAuD;AACvD,qDAAuE;AACvE,+DAAuF;AAGvF,IAAM,wBAAwB,GAA9B,MAAM,wBAAyB,SAAQ,6BAA0B;CAAG,CAAA;AAA9D,wBAAwB;IAD7B,IAAA,sBAAU,GAAE;GACP,wBAAwB,CAAsC;AAGpE,IAAM,mBAAmB,GAAzB,MAAM,mBAAoB,SAAQ,qCAAoB;CAAG,CAAA;AAAnD,mBAAmB;IADxB,IAAA,sBAAU,GAAE;GACP,mBAAmB,CAAgC;AAEzD,QAAQ,CAAC,+BAA+B,EAAE,GAAG,EAAE;IAC3C,MAAM,OAAO,GAAG,KAAK,CAAC,aAAa,EAAE,CAAC;IACtC,MAAM,wBAAwB,GAAG,IAAI,oCAAwB,EAAE,CAAC;IAChE,MAAM,YAAY,GAAG,IAA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C;QAC3E,IAAA,aAAM,EAAC,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,UAAU,CAAC,wBAAwB,CAAC,CAAC;IACvE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,sCAAsC,EAAE,GAAG,EAAE;QAC5C,MAAM,SAAS,GAAG,SAAS,CAAC;QAC5B,MAAM,SAAS,GAAG,IAAA,oCAAwB,EAAC,EAAE,UAAU,EAAE,CAAC,SAAS,CAAC,EAAE,aAAa,EAAE,mBAAmB,EAAE,CAAC,CAAC;QAC5G,MAAM,SAAS,GAAG,IAAI,qBAAS,EAAE,CAAC;QAClC,SAAS,CAAC,IAAI,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;QACtC,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,CAAgB,8BAAa,CAAC,CAAC;QAC3D,IAAA,aAAM,EAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,UAAU,CAAC,mBAAmB,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
@@ -0,0 +1,45 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2018-2022 TypeFox and others.
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the Eclipse Public License v. 2.0 which is available at
6
+ * http://www.eclipse.org/legal/epl-2.0.
7
+ *
8
+ * This Source Code may also be made available under the following Secondary
9
+ * Licenses when the conditions for such availability set forth in the Eclipse
10
+ * Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ * with the GNU Classpath Exception which is available at
12
+ * https://www.gnu.org/software/classpath/license.html.
13
+ *
14
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
+ ********************************************************************************/
16
+ import { GEdge, GLabel, GModelElement, GNode, GPort, ModelState } from '@eclipse-glsp/server-node';
17
+ export declare const ElementFilter: unique symbol;
18
+ /**
19
+ * Filter used to determine which model elements should be included in the automatic layout.
20
+ */
21
+ export interface ElementFilter {
22
+ /**
23
+ * Applies the element filter on the given element,
24
+ * @param element The element on which the filter should be applied.
25
+ * @returns `true` if the element should be included in the automatic layout, `false` otherwise.
26
+ */
27
+ apply(element: GModelElement): boolean;
28
+ }
29
+ /**
30
+ * Default implementation of {@link ElementFilter}.
31
+ * Without further configuration this filter includes all basic model elements (nodes,edges,labels,ports) that are
32
+ * part of the graphical model. For each basic type a custom filter behavior is in place.
33
+ * Edges that have no source or target are filtered out. In addition, edges that are connected to a filtered element are filtered out
34
+ * as well. The filter behavior for each of the basic types can be customized by overriding the corresponding `filter` method.
35
+ * (e.g. {@link DefaultElementFilter.filterNode})
36
+ */
37
+ export declare class DefaultElementFilter implements ElementFilter {
38
+ protected modelState: ModelState;
39
+ apply(element: GModelElement): boolean;
40
+ protected filterNode(node: GNode): boolean;
41
+ protected filterEdge(edge: GEdge): boolean;
42
+ protected filterLabel(label: GLabel): boolean;
43
+ protected filterPort(port: GPort): boolean;
44
+ }
45
+ //# sourceMappingURL=element-filter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"element-filter.d.ts","sourceRoot":"","sources":["../src/element-filter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;kFAckF;AAClF,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAGnG,eAAO,MAAM,aAAa,eAA0B,CAAC;AACrD;;GAEG;AACH,MAAM,WAAW,aAAa;IAC1B;;;;OAIG;IACH,KAAK,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC;CAC1C;AAED;;;;;;;GAOG;AACH,qBACa,oBAAqB,YAAW,aAAa;IAEtD,SAAS,CAAC,UAAU,EAAE,UAAU,CAAC;IAEjC,KAAK,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO;IAatC,SAAS,CAAC,UAAU,CAAC,IAAI,EAAE,KAAK,GAAG,OAAO;IAI1C,SAAS,CAAC,UAAU,CAAC,IAAI,EAAE,KAAK,GAAG,OAAO;IAe1C,SAAS,CAAC,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAI7C,SAAS,CAAC,UAAU,CAAC,IAAI,EAAE,KAAK,GAAG,OAAO;CAG7C"}
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ 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;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.DefaultElementFilter = exports.ElementFilter = void 0;
13
+ /********************************************************************************
14
+ * Copyright (c) 2018-2022 TypeFox and others.
15
+ *
16
+ * This program and the accompanying materials are made available under the
17
+ * terms of the Eclipse Public License v. 2.0 which is available at
18
+ * http://www.eclipse.org/legal/epl-2.0.
19
+ *
20
+ * This Source Code may also be made available under the following Secondary
21
+ * Licenses when the conditions for such availability set forth in the Eclipse
22
+ * Public License v. 2.0 are satisfied: GNU General Public License, version 2
23
+ * with the GNU Classpath Exception which is available at
24
+ * https://www.gnu.org/software/classpath/license.html.
25
+ *
26
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
27
+ ********************************************************************************/
28
+ const server_node_1 = require("@eclipse-glsp/server-node");
29
+ const inversify_1 = require("inversify");
30
+ exports.ElementFilter = Symbol('ElementFilter');
31
+ /**
32
+ * Default implementation of {@link ElementFilter}.
33
+ * Without further configuration this filter includes all basic model elements (nodes,edges,labels,ports) that are
34
+ * part of the graphical model. For each basic type a custom filter behavior is in place.
35
+ * Edges that have no source or target are filtered out. In addition, edges that are connected to a filtered element are filtered out
36
+ * as well. The filter behavior for each of the basic types can be customized by overriding the corresponding `filter` method.
37
+ * (e.g. {@link DefaultElementFilter.filterNode})
38
+ */
39
+ let DefaultElementFilter = class DefaultElementFilter {
40
+ apply(element) {
41
+ if (element instanceof server_node_1.GNode) {
42
+ return this.filterNode(element);
43
+ }
44
+ else if (element instanceof server_node_1.GEdge) {
45
+ return this.filterEdge(element);
46
+ }
47
+ else if (element instanceof server_node_1.GLabel) {
48
+ this.filterLabel(element);
49
+ }
50
+ else if (element instanceof server_node_1.GPort) {
51
+ this.filterPort(element);
52
+ }
53
+ return true;
54
+ }
55
+ filterNode(node) {
56
+ return true;
57
+ }
58
+ filterEdge(edge) {
59
+ const source = this.modelState.index.get(edge.sourceId);
60
+ if (!source || (source instanceof server_node_1.GNode && !this.filterNode(source)) || (source instanceof server_node_1.GPort && !this.filterPort(source))) {
61
+ return false;
62
+ }
63
+ const target = this.modelState.index.get(edge.targetId);
64
+ if (!target || (target instanceof server_node_1.GNode && !this.filterNode(target)) || (target instanceof server_node_1.GPort && !this.filterPort(target))) {
65
+ return false;
66
+ }
67
+ return true;
68
+ }
69
+ filterLabel(label) {
70
+ return true;
71
+ }
72
+ filterPort(port) {
73
+ return true;
74
+ }
75
+ };
76
+ __decorate([
77
+ (0, inversify_1.inject)(server_node_1.ModelState),
78
+ __metadata("design:type", Object)
79
+ ], DefaultElementFilter.prototype, "modelState", void 0);
80
+ DefaultElementFilter = __decorate([
81
+ (0, inversify_1.injectable)()
82
+ ], DefaultElementFilter);
83
+ exports.DefaultElementFilter = DefaultElementFilter;
84
+ //# sourceMappingURL=element-filter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"element-filter.js","sourceRoot":"","sources":["../src/element-filter.ts"],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IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,YAAY,mBAAK,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,EAAE;YAC3H,OAAO,KAAK,CAAC;SAChB;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;IAES,WAAW,CAAC,KAAa;QAC/B,OAAO,IAAI,CAAC;IAChB,CAAC;IAES,UAAU,CAAC,IAAW;QAC5B,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ,CAAA;AAzCG;IADC,IAAA,kBAAM,EAAC,wBAAU,CAAC;;wDACc;AAFxB,oBAAoB;IADhC,IAAA,sBAAU,GAAE;GACA,oBAAoB,CA2ChC;AA3CY,oDAAoB"}
@@ -0,0 +1,53 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2018-2022 TypeFox and others.
3
+ * This program and the accompanying materials are made available under the
4
+ * terms of the Eclipse Public License v. 2.0 which is available at
5
+ * http://www.eclipse.org/legal/epl-2.0.
6
+ *
7
+ * This Source Code may also be made available under the following Secondary
8
+ * Licenses when the conditions for such availability set forth in the Eclipse
9
+ * Public License v. 2.0 are satisfied: GNU General Public License, version 2
10
+ * with the GNU Classpath Exception which is available at
11
+ * https://www.gnu.org/software/classpath/license.html.
12
+ *
13
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
14
+ ********************************************************************************/
15
+ import { GEdge, GGraph, GLabel, GModelElement, GModelElementConstructor, GModelRoot, GNode, GPort, GShapeElement, LayoutEngine, MaybePromise, ModelState } from '@eclipse-glsp/server-node';
16
+ import { ELK, ElkEdge, ElkGraphElement, ElkLabel, ElkNode, ElkPort, ElkPrimitiveEdge, ElkShape } from 'elkjs/lib/elk-api';
17
+ import { ElkFactory } from 'sprotty-elk';
18
+ import { ElementFilter } from './element-filter';
19
+ import { LayoutConfigurator } from './layout-configurator';
20
+ /**
21
+ * An implementation of GLSP's {@link LayoutEngine} interface that retrieves the graphical model from the {@link ModelState},
22
+ * transforms this model into an ELK graph and then invokes the underlying ELK instance for layout computation.
23
+ */
24
+ export declare class GlspElkLayoutEngine implements LayoutEngine {
25
+ protected readonly filter: ElementFilter;
26
+ protected readonly configurator: LayoutConfigurator;
27
+ protected modelState: ModelState;
28
+ protected readonly elk: ELK;
29
+ protected elkEdges: ElkEdge[];
30
+ protected idToElkElement: Map<string, ElkGraphElement>;
31
+ constructor(elkFactory: ElkFactory, filter: ElementFilter, configurator: LayoutConfigurator, modelState: ModelState);
32
+ layout(): MaybePromise<GModelRoot>;
33
+ protected transformToElk(model: GModelElement): ElkGraphElement;
34
+ /**
35
+ * Searches for all children of the given element that are an instance of the given {@link GModelElementConstructor}
36
+ * and are included by the {@link ElementFilter}. Also considers children that are nested inside of {@link GCompartment}s.
37
+ * @param element The element whose children should be queried.
38
+ * @param constructor The class instance that should be matched
39
+ * @returns A list of all matching children.
40
+ */
41
+ protected findChildren<G extends GModelElement>(element: GModelElement, constructor: GModelElementConstructor<G>): G[];
42
+ protected findCommonAncestor(elkEdge: ElkPrimitiveEdge): ElkNode | undefined;
43
+ protected transformGraph(graph: GGraph): ElkGraphElement;
44
+ protected transformNode(node: GNode): ElkNode;
45
+ protected transformShape(elkShape: ElkShape, shape: GShapeElement): void;
46
+ protected transformEdge(edge: GEdge): ElkEdge;
47
+ protected transformLabel(label: GLabel): ElkLabel;
48
+ protected transformPort(port: GPort): ElkPort;
49
+ protected applyLayout(elkNode: ElkNode): void;
50
+ protected applyShape(shape: GShapeElement, elkShape: ElkShape): void;
51
+ protected applyEdge(edge: GEdge, elkEdge: ElkEdge): void;
52
+ }
53
+ //# sourceMappingURL=glsp-elk-layout-engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"glsp-elk-layout-engine.d.ts","sourceRoot":"","sources":["../src/glsp-elk-layout-engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;kFAakF;AAClF,OAAO,EAIH,KAAK,EACL,MAAM,EACN,MAAM,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