@eclipse-glsp/client 1.1.0-next.d3b810d.243 → 1.1.0-next.d81a1ea.249

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.
Files changed (94) hide show
  1. package/css/autocomplete-palette.css +22 -0
  2. package/css/glsp-sprotty.css +16 -1
  3. package/lib/base/auto-complete/auto-complete-widget.d.ts +8 -2
  4. package/lib/base/auto-complete/auto-complete-widget.d.ts.map +1 -1
  5. package/lib/base/auto-complete/auto-complete-widget.js +25 -6
  6. package/lib/base/auto-complete/auto-complete-widget.js.map +1 -1
  7. package/lib/features/accessibility/di.config.d.ts +21 -0
  8. package/lib/features/accessibility/di.config.d.ts.map +1 -0
  9. package/lib/features/accessibility/di.config.js +34 -0
  10. package/lib/features/accessibility/di.config.js.map +1 -0
  11. package/lib/features/accessibility/move-zoom/di.config.d.ts +23 -0
  12. package/lib/features/accessibility/move-zoom/di.config.d.ts.map +1 -0
  13. package/lib/features/accessibility/move-zoom/di.config.js +41 -0
  14. package/lib/features/accessibility/move-zoom/di.config.js.map +1 -0
  15. package/lib/features/accessibility/move-zoom/move-handler.d.ts +81 -0
  16. package/lib/features/accessibility/move-zoom/move-handler.d.ts.map +1 -0
  17. package/lib/features/accessibility/move-zoom/move-handler.js +173 -0
  18. package/lib/features/accessibility/move-zoom/move-handler.js.map +1 -0
  19. package/lib/features/accessibility/move-zoom/zoom-handler.d.ts +74 -0
  20. package/lib/features/accessibility/move-zoom/zoom-handler.d.ts.map +1 -0
  21. package/lib/features/accessibility/move-zoom/zoom-handler.js +159 -0
  22. package/lib/features/accessibility/move-zoom/zoom-handler.js.map +1 -0
  23. package/lib/features/accessibility/resize-key-tool/di.config.d.ts +23 -0
  24. package/lib/features/accessibility/resize-key-tool/di.config.d.ts.map +1 -0
  25. package/lib/features/accessibility/resize-key-tool/di.config.js +38 -0
  26. package/lib/features/accessibility/resize-key-tool/di.config.js.map +1 -0
  27. package/lib/features/accessibility/resize-key-tool/resize-key-handler.d.ts +55 -0
  28. package/lib/features/accessibility/resize-key-tool/resize-key-handler.d.ts.map +1 -0
  29. package/lib/features/accessibility/resize-key-tool/resize-key-handler.js +126 -0
  30. package/lib/features/accessibility/resize-key-tool/resize-key-handler.js.map +1 -0
  31. package/lib/features/accessibility/resize-key-tool/resize-key-tool.d.ts +44 -0
  32. package/lib/features/accessibility/resize-key-tool/resize-key-tool.d.ts.map +1 -0
  33. package/lib/features/accessibility/resize-key-tool/resize-key-tool.js +127 -0
  34. package/lib/features/accessibility/resize-key-tool/resize-key-tool.js.map +1 -0
  35. package/lib/features/accessibility/search/di.config.d.ts +20 -0
  36. package/lib/features/accessibility/search/di.config.d.ts.map +1 -0
  37. package/lib/features/accessibility/search/di.config.js +33 -0
  38. package/lib/features/accessibility/search/di.config.js.map +1 -0
  39. package/lib/features/accessibility/search/search-palette.d.ts +47 -0
  40. package/lib/features/accessibility/search/search-palette.d.ts.map +1 -0
  41. package/lib/features/accessibility/search/search-palette.js +155 -0
  42. package/lib/features/accessibility/search/search-palette.js.map +1 -0
  43. package/lib/features/accessibility/search/search-tool.d.ts +30 -0
  44. package/lib/features/accessibility/search/search-tool.d.ts.map +1 -0
  45. package/lib/features/accessibility/search/search-tool.js +73 -0
  46. package/lib/features/accessibility/search/search-tool.js.map +1 -0
  47. package/lib/features/accessibility/view-key-tools/deselect-key-tool.d.ts +35 -0
  48. package/lib/features/accessibility/view-key-tools/deselect-key-tool.d.ts.map +1 -0
  49. package/lib/features/accessibility/view-key-tools/deselect-key-tool.js +87 -0
  50. package/lib/features/accessibility/view-key-tools/deselect-key-tool.js.map +1 -0
  51. package/lib/features/accessibility/view-key-tools/di.config.d.ts +20 -0
  52. package/lib/features/accessibility/view-key-tools/di.config.d.ts.map +1 -0
  53. package/lib/features/accessibility/view-key-tools/di.config.js +35 -0
  54. package/lib/features/accessibility/view-key-tools/di.config.js.map +1 -0
  55. package/lib/features/accessibility/view-key-tools/movement-key-tool.d.ts +49 -0
  56. package/lib/features/accessibility/view-key-tools/movement-key-tool.d.ts.map +1 -0
  57. package/lib/features/accessibility/view-key-tools/movement-key-tool.js +131 -0
  58. package/lib/features/accessibility/view-key-tools/movement-key-tool.js.map +1 -0
  59. package/lib/features/accessibility/view-key-tools/zoom-key-tool.d.ts +43 -0
  60. package/lib/features/accessibility/view-key-tools/zoom-key-tool.d.ts.map +1 -0
  61. package/lib/features/accessibility/view-key-tools/zoom-key-tool.js +109 -0
  62. package/lib/features/accessibility/view-key-tools/zoom-key-tool.js.map +1 -0
  63. package/lib/features/autocomplete-palette/autocomplete-suggestion-providers.d.ts +35 -0
  64. package/lib/features/autocomplete-palette/autocomplete-suggestion-providers.d.ts.map +1 -0
  65. package/lib/features/autocomplete-palette/autocomplete-suggestion-providers.js +18 -0
  66. package/lib/features/autocomplete-palette/autocomplete-suggestion-providers.js.map +1 -0
  67. package/lib/features/autocomplete-palette/base-autocomplete-palette.d.ts +41 -0
  68. package/lib/features/autocomplete-palette/base-autocomplete-palette.d.ts.map +1 -0
  69. package/lib/features/autocomplete-palette/base-autocomplete-palette.js +82 -0
  70. package/lib/features/autocomplete-palette/base-autocomplete-palette.js.map +1 -0
  71. package/lib/index.d.ts +12 -3
  72. package/lib/index.d.ts.map +1 -1
  73. package/lib/index.js +62 -48
  74. package/lib/index.js.map +1 -1
  75. package/package.json +5 -3
  76. package/src/base/auto-complete/auto-complete-widget.ts +31 -7
  77. package/src/features/accessibility/README.md +65 -0
  78. package/src/features/accessibility/di.config.ts +32 -0
  79. package/src/features/accessibility/move-zoom/di.config.ts +43 -0
  80. package/src/features/accessibility/move-zoom/move-handler.ts +198 -0
  81. package/src/features/accessibility/move-zoom/zoom-handler.ts +178 -0
  82. package/src/features/accessibility/resize-key-tool/di.config.ts +37 -0
  83. package/src/features/accessibility/resize-key-tool/resize-key-handler.ts +120 -0
  84. package/src/features/accessibility/resize-key-tool/resize-key-tool.ts +108 -0
  85. package/src/features/accessibility/search/di.config.ts +31 -0
  86. package/src/features/accessibility/search/search-palette.ts +181 -0
  87. package/src/features/accessibility/search/search-tool.ts +60 -0
  88. package/src/features/accessibility/view-key-tools/deselect-key-tool.ts +80 -0
  89. package/src/features/accessibility/view-key-tools/di.config.ts +33 -0
  90. package/src/features/accessibility/view-key-tools/movement-key-tool.ts +115 -0
  91. package/src/features/accessibility/view-key-tools/zoom-key-tool.ts +94 -0
  92. package/src/features/autocomplete-palette/autocomplete-suggestion-providers.ts +37 -0
  93. package/src/features/autocomplete-palette/base-autocomplete-palette.ts +88 -0
  94. package/src/index.ts +17 -3
@@ -0,0 +1,181 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2023 Business Informatics Group (TU Wien) 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
+
17
+ import { Action, CenterAction, SelectAction, SelectAllAction } from '@eclipse-glsp/protocol';
18
+ import { injectable } from 'inversify';
19
+ import { isEqual } from 'lodash';
20
+ import { codiconCSSString, isNameable, LabeledAction, name, SEdge, SModelElement, SModelRoot, SNode } from 'sprotty';
21
+ import { toArray } from 'sprotty/lib/utils/iterable';
22
+ import { AutocompleteSuggestion, IAutocompleteSuggestionProvider } from '../../autocomplete-palette/autocomplete-suggestion-providers';
23
+ import { BaseAutocompletePalette } from '../../autocomplete-palette/base-autocomplete-palette';
24
+
25
+ import { applyCssClasses, deleteCssClasses } from '../../tool-feedback/css-feedback';
26
+
27
+ const CSS_SEARCH_HIDDEN = 'search-hidden';
28
+ const CSS_SEARCH_HIGHLIGHTED = 'search-highlighted';
29
+
30
+ export class RevealNamedElementAutocompleteSuggestionProvider implements IAutocompleteSuggestionProvider {
31
+ async retrieveSuggestions(root: Readonly<SModelRoot>, text: string): Promise<AutocompleteSuggestion[]> {
32
+ const nameables = toArray(root.index.all().filter(element => isNameable(element)));
33
+ return nameables.map(nameable => ({
34
+ element: nameable,
35
+ action: new LabeledAction(
36
+ `[${nameable.type}] ${name(nameable) ?? '<no-name>'}`,
37
+ this.getActions(nameable),
38
+ codiconCSSString('eye')
39
+ )
40
+ }));
41
+ }
42
+
43
+ protected getActions(nameable: SModelElement): Action[] {
44
+ return [SelectAction.create({ selectedElementsIDs: [nameable.id] }), CenterAction.create([nameable.id], { retainZoom: true })];
45
+ }
46
+ }
47
+
48
+ export class RevealEdgeElementAutocompleteSuggestionProvider implements IAutocompleteSuggestionProvider {
49
+ async retrieveSuggestions(root: Readonly<SModelRoot>, text: string): Promise<AutocompleteSuggestion[]> {
50
+ const edges = toArray(root.index.all().filter(element => element instanceof SEdge)) as SEdge[];
51
+ return edges.map(edge => ({
52
+ element: edge,
53
+ action: new LabeledAction(
54
+ `[${edge.type}] ` + this.getEdgeLabel(root, edge),
55
+ this.getActions(edge),
56
+ codiconCSSString('arrow-both')
57
+ )
58
+ }));
59
+ }
60
+ protected getActions(edge: SEdge): Action[] {
61
+ return [SelectAction.create({ selectedElementsIDs: [edge.id] }), CenterAction.create([edge.sourceId, edge.targetId])];
62
+ }
63
+ protected getEdgeLabel(root: Readonly<SModelRoot>, edge: SEdge): string {
64
+ let sourceName = '';
65
+ let targetName = '';
66
+
67
+ const sourceNode = root.index.getById(edge.sourceId);
68
+ const targetNode = root.index.getById(edge.targetId);
69
+
70
+ if (sourceNode !== undefined) {
71
+ sourceName = name(sourceNode) ?? sourceNode.type;
72
+ }
73
+ if (targetNode !== undefined) {
74
+ targetName = name(targetNode) ?? targetNode.type;
75
+ }
76
+
77
+ return sourceName + ' -> ' + targetName;
78
+ }
79
+ }
80
+ @injectable()
81
+ export class SearchAutocompletePalette extends BaseAutocompletePalette {
82
+ static readonly ID = 'search-autocomplete-palette';
83
+
84
+ protected cachedSuggestions: AutocompleteSuggestion[] = [];
85
+
86
+ id(): string {
87
+ return SearchAutocompletePalette.ID;
88
+ }
89
+
90
+ protected override initializeContents(containerElement: HTMLElement): void {
91
+ super.initializeContents(containerElement);
92
+
93
+ this.autocompleteWidget.inputField.placeholder = 'Search for elements';
94
+ }
95
+ protected getSuggestionProviders(root: Readonly<SModelRoot>, input: string): IAutocompleteSuggestionProvider[] {
96
+ return [new RevealNamedElementAutocompleteSuggestionProvider(), new RevealEdgeElementAutocompleteSuggestionProvider()];
97
+ }
98
+ protected async retrieveSuggestions(root: Readonly<SModelRoot>, input: string): Promise<LabeledAction[]> {
99
+ const providers = this.getSuggestionProviders(root, input);
100
+ const suggestions = (await Promise.all(providers.map(provider => provider.retrieveSuggestions(root, input)))).flat(1);
101
+
102
+ this.cachedSuggestions = suggestions;
103
+
104
+ return suggestions.map(s => s.action);
105
+ }
106
+
107
+ protected override async visibleSuggestionsChanged(root: Readonly<SModelRoot>, labeledActions: LabeledAction[]): Promise<void> {
108
+ await this.applyCSS(this.getHiddenElements(root, this.getSuggestionsFromLabeledActions(labeledActions)), CSS_SEARCH_HIDDEN);
109
+ await this.deleteCSS(
110
+ this.getSuggestionsFromLabeledActions(labeledActions).map(s => s.element),
111
+ CSS_SEARCH_HIDDEN
112
+ );
113
+ }
114
+
115
+ protected override async selectedSuggestionChanged(
116
+ root: Readonly<SModelRoot>,
117
+ labeledAction?: LabeledAction | undefined
118
+ ): Promise<void> {
119
+ await this.deleteAllCSS(root, CSS_SEARCH_HIGHLIGHTED);
120
+ if (labeledAction !== undefined) {
121
+ const suggestions = this.getSuggestionsFromLabeledActions([labeledAction]);
122
+
123
+ const actions: CenterAction[] = [];
124
+ suggestions.map(currElem => actions.push(CenterAction.create([currElem.element.id], { animate: true, retainZoom: true })));
125
+
126
+ this.actionDispatcher.dispatchAll(actions);
127
+ await this.applyCSS(
128
+ suggestions.map(s => s.element),
129
+ CSS_SEARCH_HIGHLIGHTED
130
+ );
131
+ }
132
+ }
133
+
134
+ public override show(root: Readonly<SModelRoot>, ...contextElementIds: string[]): void {
135
+ this.actionDispatcher.dispatch(SelectAllAction.create(false));
136
+
137
+ super.show(root, ...contextElementIds);
138
+ }
139
+
140
+ public override hide(): void {
141
+ if (this.root !== undefined) {
142
+ this.deleteAllCSS(this.root, CSS_SEARCH_HIDDEN);
143
+ this.deleteAllCSS(this.root, CSS_SEARCH_HIGHLIGHTED);
144
+ this.autocompleteWidget.inputField.value = '';
145
+ }
146
+
147
+ super.hide();
148
+ }
149
+
150
+ protected applyCSS(elements: SModelElement[], cssClass: string): Promise<void> {
151
+ const actions = elements.map(element => applyCssClasses(element, cssClass));
152
+ return this.actionDispatcher.dispatchAll(actions);
153
+ }
154
+
155
+ protected deleteCSS(elements: SModelElement[], cssClass: string): Promise<void> {
156
+ const actions = elements.map(element => deleteCssClasses(element, cssClass));
157
+ return this.actionDispatcher.dispatchAll(actions);
158
+ }
159
+
160
+ protected deleteAllCSS(root: Readonly<SModelRoot>, cssClass: string): Promise<void> {
161
+ const actions = toArray(root.index.all().map(element => deleteCssClasses(element, cssClass)));
162
+ return this.actionDispatcher.dispatchAll(actions);
163
+ }
164
+
165
+ protected getSuggestionsFromLabeledActions(labeledActions: LabeledAction[]): AutocompleteSuggestion[] {
166
+ return this.cachedSuggestions.filter(c => labeledActions.find(s => isEqual(s, c.action)));
167
+ }
168
+
169
+ protected getHiddenSuggestionsFromLabeledActions(labeledActions: LabeledAction[]): AutocompleteSuggestion[] {
170
+ return this.cachedSuggestions.filter(c => !labeledActions.find(s => isEqual(s, c.action)));
171
+ }
172
+
173
+ protected getHiddenElements(root: Readonly<SModelRoot>, suggestions: AutocompleteSuggestion[]): SModelElement[] {
174
+ return toArray(
175
+ root.index
176
+ .all()
177
+ .filter(element => element instanceof SNode || element instanceof SEdge)
178
+ .filter(element => suggestions.find(suggestion => suggestion.element.id === element.id) === undefined)
179
+ );
180
+ }
181
+ }
@@ -0,0 +1,60 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2023 Business Informatics Group (TU Wien) 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
+
17
+ import { Action } from '@eclipse-glsp/protocol';
18
+ import { inject, injectable } from 'inversify';
19
+ import { KeyListener, KeyTool, SetUIExtensionVisibilityAction, SModelElement, Tool } from 'sprotty';
20
+ import { matchesKeystroke } from 'sprotty/lib/utils/keyboard';
21
+ import { SearchAutocompletePalette } from './search-palette';
22
+
23
+ @injectable()
24
+ export class SearchAutocompletePaletteTool implements Tool {
25
+ static readonly ID = 'glsp.search-autocomplete-palette-tool';
26
+
27
+ protected readonly keyListener = new SearchAutocompletePaletteKeyListener();
28
+
29
+ @inject(KeyTool) protected keyTool: KeyTool;
30
+
31
+ get id(): string {
32
+ return SearchAutocompletePaletteTool.ID;
33
+ }
34
+
35
+ enable(): void {
36
+ this.keyTool.register(this.keyListener);
37
+ }
38
+
39
+ disable(): void {
40
+ this.keyTool.deregister(this.keyListener);
41
+ }
42
+ }
43
+
44
+ export class SearchAutocompletePaletteKeyListener extends KeyListener {
45
+ override keyDown(element: SModelElement, event: KeyboardEvent): Action[] {
46
+ if (this.matchesSearchActivateKeystroke(event)) {
47
+ return [
48
+ SetUIExtensionVisibilityAction.create({
49
+ extensionId: SearchAutocompletePalette.ID,
50
+ visible: true
51
+ })
52
+ ];
53
+ }
54
+ return [];
55
+ }
56
+
57
+ protected matchesSearchActivateKeystroke(event: KeyboardEvent): boolean {
58
+ return matchesKeystroke(event, 'KeyF', 'ctrl');
59
+ }
60
+ }
@@ -0,0 +1,80 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2023 Business Informatics Group (TU Wien) 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
+
17
+ import { Action, SelectAction } from '@eclipse-glsp/protocol';
18
+ import { inject, injectable } from 'inversify';
19
+ import { isSelectable, KeyListener, KeyTool, SModelElement, SRoutableElement, SwitchEditModeAction } from 'sprotty';
20
+ import { toArray } from 'sprotty/lib/utils/iterable';
21
+ import { matchesKeystroke } from 'sprotty/lib/utils/keyboard';
22
+ import { GLSPTool } from '../../../base/tool-manager/glsp-tool-manager';
23
+ import { SResizeHandle } from '../../change-bounds/model';
24
+
25
+ /**
26
+ * Deselects the element if there is no interaction possible with element.
27
+ */
28
+ @injectable()
29
+ export class DeselectKeyTool implements GLSPTool {
30
+ static ID = 'glsp.deselect-key-tool';
31
+
32
+ isEditTool = true;
33
+
34
+ protected readonly deselectKeyListener = new DeselectKeyListener();
35
+
36
+ @inject(KeyTool) protected readonly keytool: KeyTool;
37
+
38
+ get id(): string {
39
+ return DeselectKeyTool.ID;
40
+ }
41
+
42
+ enable(): void {
43
+ this.keytool.register(this.deselectKeyListener);
44
+ }
45
+
46
+ disable(): void {
47
+ this.keytool.deregister(this.deselectKeyListener);
48
+ }
49
+ }
50
+
51
+ export class DeselectKeyListener extends KeyListener {
52
+ override keyDown(target: SModelElement, event: KeyboardEvent): Action[] {
53
+ if (this.matchesDeselectKeystroke(event)) {
54
+ const isResizeHandleActive = toArray(target.root.index.all().filter(el => el instanceof SResizeHandle)).length > 0;
55
+
56
+ if (isResizeHandleActive) {
57
+ return [];
58
+ }
59
+
60
+ const deselect = toArray(target.root.index.all().filter(element => isSelectable(element) && element.selected));
61
+ const actions: Action[] = [];
62
+
63
+ if (deselect.length > 0) {
64
+ actions.push(SelectAction.create({ deselectedElementsIDs: deselect.map(e => e.id) }));
65
+ }
66
+
67
+ const routableDeselect = deselect.filter(e => e instanceof SRoutableElement).map(e => e.id);
68
+ if (routableDeselect.length > 0) {
69
+ actions.push(SwitchEditModeAction.create({ elementsToDeactivate: routableDeselect }));
70
+ }
71
+
72
+ return actions;
73
+ }
74
+ return [];
75
+ }
76
+
77
+ protected matchesDeselectKeystroke(event: KeyboardEvent): boolean {
78
+ return matchesKeystroke(event, 'Escape');
79
+ }
80
+ }
@@ -0,0 +1,33 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2019-2023 EclipseSource 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
+
17
+ import { bindAsService, BindingContext } from '@eclipse-glsp/protocol';
18
+ import { ContainerModule } from 'inversify';
19
+ import { TYPES } from '../../../base/types';
20
+ import { DeselectKeyTool } from '../view-key-tools/deselect-key-tool';
21
+ import { MovementKeyTool } from './movement-key-tool';
22
+ import { ZoomKeyTool } from './zoom-key-tool';
23
+
24
+ export const glspViewKeyToolsModule = new ContainerModule((bind, _unbind, isBound, rebind) => {
25
+ const context = { bind, isBound, rebind };
26
+ configureViewKeyTools(context);
27
+ });
28
+
29
+ export function configureViewKeyTools(context: Pick<BindingContext, 'bind'>): void {
30
+ bindAsService(context, TYPES.IDefaultTool, MovementKeyTool);
31
+ bindAsService(context, TYPES.IDefaultTool, ZoomKeyTool);
32
+ bindAsService(context, TYPES.IDefaultTool, DeselectKeyTool);
33
+ }
@@ -0,0 +1,115 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2023 Business Informatics Group (TU Wien) 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
+
17
+ import { Action } from '@eclipse-glsp/protocol';
18
+ import { inject, injectable, optional } from 'inversify';
19
+ import { ISnapper, KeyListener, KeyTool, SModelElement } from 'sprotty';
20
+ import { matchesKeystroke } from 'sprotty/lib/utils/keyboard';
21
+ import { GLSPTool } from '../../../base/tool-manager/glsp-tool-manager';
22
+ import { TYPES } from '../../../base/types';
23
+ import { GridSnapper } from '../../change-bounds/snap';
24
+
25
+ import { SelectionService } from '../../select/selection-service';
26
+ import { MoveElementAction, MoveViewportAction } from '../move-zoom/move-handler';
27
+
28
+ /**
29
+ * Moves viewport and elements when its focused and arrow keys are hit.
30
+ */
31
+ @injectable()
32
+ export class MovementKeyTool implements GLSPTool {
33
+ static ID = 'glsp.movement-key-tool';
34
+
35
+ isEditTool = true;
36
+
37
+ protected readonly movementKeyListener = new MoveKeyListener(this);
38
+
39
+ @inject(KeyTool) protected readonly keytool: KeyTool;
40
+ @inject(TYPES.SelectionService) selectionService: SelectionService;
41
+ @inject(TYPES.ISnapper) @optional() readonly snapper?: ISnapper;
42
+
43
+ get id(): string {
44
+ return MovementKeyTool.ID;
45
+ }
46
+
47
+ enable(): void {
48
+ this.keytool.register(this.movementKeyListener);
49
+ }
50
+
51
+ disable(): void {
52
+ this.keytool.deregister(this.movementKeyListener);
53
+ }
54
+ }
55
+
56
+ export class MoveKeyListener extends KeyListener {
57
+ // Default x distance used if GridSnapper is not provided
58
+ static readonly defaultMoveX = 20;
59
+
60
+ // Default y distance used if GridSnapper is not provided
61
+ static readonly defaultMoveY = 20;
62
+
63
+ protected grid = { x: MoveKeyListener.defaultMoveX, y: MoveKeyListener.defaultMoveY };
64
+
65
+ constructor(protected readonly tool: MovementKeyTool) {
66
+ super();
67
+
68
+ if (this.tool.snapper instanceof GridSnapper) {
69
+ this.grid = this.tool.snapper.grid;
70
+ }
71
+ }
72
+
73
+ override keyDown(element: SModelElement, event: KeyboardEvent): Action[] {
74
+ const selectedElementIds = this.tool.selectionService.getSelectedElementIDs();
75
+
76
+ if (selectedElementIds.length > 0) {
77
+ if (this.matchesMoveUpKeystroke(event)) {
78
+ return [MoveElementAction.create(selectedElementIds, 0, -this.grid.x)];
79
+ } else if (this.matchesMoveDownKeystroke(event)) {
80
+ return [MoveElementAction.create(selectedElementIds, 0, this.grid.x)];
81
+ } else if (this.matchesMoveRightKeystroke(event)) {
82
+ return [MoveElementAction.create(selectedElementIds, this.grid.x, 0)];
83
+ } else if (this.matchesMoveLeftKeystroke(event)) {
84
+ return [MoveElementAction.create(selectedElementIds, -this.grid.x, 0)];
85
+ }
86
+ } else {
87
+ if (this.matchesMoveUpKeystroke(event)) {
88
+ return [MoveViewportAction.create(0, -this.grid.x)];
89
+ } else if (this.matchesMoveDownKeystroke(event)) {
90
+ return [MoveViewportAction.create(0, this.grid.x)];
91
+ } else if (this.matchesMoveRightKeystroke(event)) {
92
+ return [MoveViewportAction.create(this.grid.x, 0)];
93
+ } else if (this.matchesMoveLeftKeystroke(event)) {
94
+ return [MoveViewportAction.create(-this.grid.x, 0)];
95
+ }
96
+ }
97
+ return [];
98
+ }
99
+
100
+ protected matchesMoveUpKeystroke(event: KeyboardEvent): boolean {
101
+ return matchesKeystroke(event, 'ArrowUp');
102
+ }
103
+
104
+ protected matchesMoveDownKeystroke(event: KeyboardEvent): boolean {
105
+ return matchesKeystroke(event, 'ArrowDown');
106
+ }
107
+
108
+ protected matchesMoveRightKeystroke(event: KeyboardEvent): boolean {
109
+ return matchesKeystroke(event, 'ArrowRight');
110
+ }
111
+
112
+ protected matchesMoveLeftKeystroke(event: KeyboardEvent): boolean {
113
+ return matchesKeystroke(event, 'ArrowLeft');
114
+ }
115
+ }
@@ -0,0 +1,94 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2023 Business Informatics Group (TU Wien) 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
+
17
+ import { Action, CenterAction } from '@eclipse-glsp/protocol';
18
+ import { inject, injectable } from 'inversify';
19
+ import { KeyListener, KeyTool, SModelElement } from 'sprotty';
20
+ import { matchesKeystroke } from 'sprotty/lib/utils/keyboard';
21
+ import { GLSPTool } from '../../../base/tool-manager/glsp-tool-manager';
22
+ import { TYPES } from '../../../base/types';
23
+ import { SelectionService } from '../../select/selection-service';
24
+ import { ZoomElementAction, ZoomViewportAction } from '../move-zoom/zoom-handler';
25
+
26
+ /**
27
+ * Zoom viewport and elements when its focused and arrow keys are hit.
28
+ */
29
+ @injectable()
30
+ export class ZoomKeyTool implements GLSPTool {
31
+ static ID = 'glsp.zoom-key-tool';
32
+
33
+ isEditTool = false;
34
+
35
+ protected readonly zoomKeyListener = new ZoomKeyListener(this);
36
+
37
+ @inject(KeyTool) protected readonly keytool: KeyTool;
38
+ @inject(TYPES.SelectionService) selectionService: SelectionService;
39
+
40
+ get id(): string {
41
+ return ZoomKeyTool.ID;
42
+ }
43
+
44
+ enable(): void {
45
+ this.keytool.register(this.zoomKeyListener);
46
+ }
47
+
48
+ disable(): void {
49
+ this.keytool.deregister(this.zoomKeyListener);
50
+ }
51
+ }
52
+
53
+ export class ZoomKeyListener extends KeyListener {
54
+ static readonly defaultZoomInFactor = 1.1;
55
+ static readonly defaultZoomOutFactor = 0.9;
56
+
57
+ constructor(protected tool: ZoomKeyTool) {
58
+ super();
59
+ }
60
+
61
+ override keyDown(element: SModelElement, event: KeyboardEvent): Action[] {
62
+ const selectedElementIds = this.tool.selectionService.getSelectedElementIDs();
63
+
64
+ if (this.matchesZoomOutKeystroke(event)) {
65
+ if (selectedElementIds.length > 0) {
66
+ return [ZoomElementAction.create(selectedElementIds, ZoomKeyListener.defaultZoomOutFactor)];
67
+ } else {
68
+ return [ZoomViewportAction.create(ZoomKeyListener.defaultZoomOutFactor)];
69
+ }
70
+ } else if (this.matchesZoomInKeystroke(event)) {
71
+ if (selectedElementIds.length > 0) {
72
+ return [ZoomElementAction.create(selectedElementIds, ZoomKeyListener.defaultZoomInFactor)];
73
+ } else {
74
+ return [ZoomViewportAction.create(ZoomKeyListener.defaultZoomInFactor)];
75
+ }
76
+ } else if (this.matchesMinZoomLevelKeystroke(event)) {
77
+ return [CenterAction.create(selectedElementIds)];
78
+ }
79
+ return [];
80
+ }
81
+
82
+ protected matchesZoomInKeystroke(event: KeyboardEvent): boolean {
83
+ /** here event.key is used for '+', as keycode 187 is already declared for 'Equals' in {@link matchesKeystroke}.*/
84
+ return event.key === '+' || matchesKeystroke(event, 'NumpadAdd');
85
+ }
86
+
87
+ protected matchesMinZoomLevelKeystroke(event: KeyboardEvent): boolean {
88
+ return matchesKeystroke(event, 'Digit0', 'ctrl') || matchesKeystroke(event, 'Numpad0', 'ctrl');
89
+ }
90
+
91
+ protected matchesZoomOutKeystroke(event: KeyboardEvent): boolean {
92
+ return matchesKeystroke(event, 'Minus') || matchesKeystroke(event, 'NumpadSubtract');
93
+ }
94
+ }
@@ -0,0 +1,37 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2023 Business Informatics Group (TU Wien) 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
+
17
+ import { LabeledAction, SModelElement, SModelRoot } from 'sprotty';
18
+
19
+ /**
20
+ * Interface for a provider that provides suggestions that can be used to fill the autocomplete
21
+ */
22
+ export interface IAutocompleteSuggestionProvider {
23
+ /**
24
+ * Returns the suggestions based on the provided parameters.
25
+ * @param root: The root model
26
+ * @param text: The text input provided by the user.
27
+ */
28
+ retrieveSuggestions(root: Readonly<SModelRoot>, text: string): Promise<AutocompleteSuggestion[]>;
29
+ }
30
+
31
+ /**
32
+ * Interface for autocomplete suggestions.
33
+ */
34
+ export interface AutocompleteSuggestion {
35
+ element: SModelElement;
36
+ action: LabeledAction;
37
+ }