@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,198 @@
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, ChangeBoundsOperation, Point, SetViewportAction, Viewport } from '@eclipse-glsp/protocol';
18
+ import { inject, injectable } from 'inversify';
19
+ import { throttle } from 'lodash';
20
+ import { findParentByFeature, IActionDispatcher, IActionHandler, ICommand, isViewport, SModelRoot } from 'sprotty';
21
+ import { EditorContextService } from '../../../base/editor-context-service';
22
+ import { TYPES } from '../../../base/types';
23
+ import { getElements, isSelectableAndBoundsAware, SelectableBoundsAware } from '../../../utils/smodel-util';
24
+
25
+ /**
26
+ * Action for triggering moving of the viewport.
27
+ */
28
+ export interface MoveViewportAction extends Action {
29
+ kind: typeof MoveViewportAction.KIND;
30
+ /**
31
+ * used to specify the amount to be moved in the x-axis
32
+ */
33
+ moveX: number;
34
+ /**
35
+ * used to specify the amount to be moved in the y-axis
36
+ */
37
+ moveY: number;
38
+ }
39
+
40
+ export namespace MoveViewportAction {
41
+ export const KIND = 'moveViewportAction';
42
+
43
+ export function is(object: any): object is MoveViewportAction {
44
+ return Action.hasKind(object, KIND);
45
+ }
46
+
47
+ export function create(moveX: number, moveY: number): MoveViewportAction {
48
+ return { kind: KIND, moveX, moveY };
49
+ }
50
+ }
51
+
52
+ /**
53
+ * Action for triggering moving of elements.
54
+ */
55
+ export interface MoveElementAction extends Action {
56
+ kind: typeof MoveElementAction.KIND;
57
+ /**
58
+ * used to specify the elements to be zoomed in/out
59
+ */
60
+ elementIds: string[];
61
+ /**
62
+ * used to specify the amount to be moved in the x-axis
63
+ */
64
+ moveX: number;
65
+ /**
66
+ * used to specify the amount to be moved in the y-axis
67
+ */
68
+ moveY: number;
69
+ }
70
+
71
+ export namespace MoveElementAction {
72
+ export const KIND = 'moveElementAction';
73
+
74
+ export function is(object: any): object is MoveElementAction {
75
+ return Action.hasKind(object, KIND);
76
+ }
77
+
78
+ export function create(elementIds: string[], moveX: number, moveY: number): MoveElementAction {
79
+ return { kind: KIND, elementIds, moveX, moveY };
80
+ }
81
+ }
82
+
83
+ /* The MoveViewportHandler class is an implementation of the IActionHandler interface that handles
84
+ moving of the viewport. */
85
+ @injectable()
86
+ export class MoveViewportHandler implements IActionHandler {
87
+ @inject(EditorContextService)
88
+ protected editorContextService: EditorContextService;
89
+
90
+ @inject(TYPES.IActionDispatcher) protected dispatcher: IActionDispatcher;
91
+ protected readonly throttledHandleViewportMove = throttle((action: MoveViewportAction) => this.handleMoveViewport(action), 150);
92
+
93
+ handle(action: Action): void | Action | ICommand {
94
+ if (MoveViewportAction.is(action)) {
95
+ this.throttledHandleViewportMove(action);
96
+ }
97
+ }
98
+
99
+ handleMoveViewport(action: MoveViewportAction): void {
100
+ const viewport = findParentByFeature(this.editorContextService.modelRoot, isViewport);
101
+ if (!viewport) {
102
+ return;
103
+ }
104
+ this.dispatcher.dispatch(this.moveViewport(viewport, action.moveX, action.moveY));
105
+ }
106
+
107
+ protected moveViewport(viewport: SModelRoot & Viewport, offsetX: number, offSetY: number): SetViewportAction {
108
+ const newViewport: Viewport = {
109
+ scroll: {
110
+ x: viewport.scroll.x + offsetX,
111
+ y: viewport.scroll.y + offSetY
112
+ },
113
+ zoom: viewport.zoom
114
+ };
115
+
116
+ return SetViewportAction.create(viewport.id, newViewport, { animate: true });
117
+ }
118
+ }
119
+
120
+ /* The MoveElementHandler class is an implementation of the IActionHandler interface that handles
121
+ moving elements. */
122
+ @injectable()
123
+ export class MoveElementHandler implements IActionHandler {
124
+ @inject(EditorContextService)
125
+ protected editorContextService: EditorContextService;
126
+ @inject(TYPES.IActionDispatcher) protected dispatcher: IActionDispatcher;
127
+ protected readonly throttledHandleElementMove = throttle((action: MoveElementAction) => this.handleMoveElement(action), 150);
128
+
129
+ handle(action: Action): void | Action | ICommand {
130
+ if (MoveElementAction.is(action)) {
131
+ this.throttledHandleElementMove(action);
132
+ }
133
+ }
134
+
135
+ handleMoveElement(action: MoveElementAction): void {
136
+ const viewport = findParentByFeature(this.editorContextService.modelRoot, isViewport);
137
+ if (!viewport) {
138
+ return;
139
+ }
140
+
141
+ const elements = getElements(this.editorContextService.modelRoot.index, action.elementIds, isSelectableAndBoundsAware);
142
+
143
+ this.dispatcher.dispatchAll(this.move(viewport, elements, action.moveX, action.moveY));
144
+ }
145
+
146
+ protected getBounds(element: SelectableBoundsAware, offSetX: number, offSetY: number): Point {
147
+ return { x: element.bounds.x + offSetX, y: element.bounds.y + offSetY };
148
+ }
149
+
150
+ protected adaptViewport(
151
+ viewport: SModelRoot & Viewport,
152
+ newPoint: Point,
153
+ moveX: number,
154
+ moveY: number
155
+ ): MoveViewportAction | undefined {
156
+ if (
157
+ newPoint.x < viewport.scroll.x ||
158
+ newPoint.x > viewport.scroll.x + viewport.canvasBounds.width ||
159
+ newPoint.y < viewport.scroll.y ||
160
+ newPoint.y > viewport.scroll.y + viewport.canvasBounds.height
161
+ ) {
162
+ return MoveViewportAction.create(moveX, moveY);
163
+ }
164
+ return;
165
+ }
166
+
167
+ protected moveElement(element: SelectableBoundsAware, offSetX: number, offSetY: number): ChangeBoundsOperation {
168
+ return ChangeBoundsOperation.create([
169
+ {
170
+ elementId: element.id,
171
+ newSize: {
172
+ width: element.bounds.width,
173
+ height: element.bounds.height
174
+ },
175
+ newPosition: {
176
+ x: element.bounds.x + offSetX,
177
+ y: element.bounds.y + offSetY
178
+ }
179
+ }
180
+ ]);
181
+ }
182
+
183
+ protected move(viewport: SModelRoot & Viewport, selectedElements: SelectableBoundsAware[], deltaX: number, deltaY: number): Action[] {
184
+ const results: Action[] = [];
185
+
186
+ if (selectedElements.length !== 0) {
187
+ selectedElements.forEach(currentElement => {
188
+ results.push(this.moveElement(currentElement, deltaX, deltaY));
189
+ const newPosition = this.getBounds(currentElement, deltaX, deltaY);
190
+ const viewportAction = this.adaptViewport(viewport, newPosition, deltaX, deltaY);
191
+ if (viewportAction) {
192
+ results.push(viewportAction);
193
+ }
194
+ });
195
+ }
196
+ return results;
197
+ }
198
+ }
@@ -0,0 +1,178 @@
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, Bounds, Point, SetViewportAction, Viewport } from '@eclipse-glsp/protocol';
18
+ import { inject, injectable } from 'inversify';
19
+ import { throttle } from 'lodash';
20
+ import {
21
+ findParentByFeature,
22
+ IActionDispatcher,
23
+ IActionHandler,
24
+ ICommand,
25
+ isViewport,
26
+ SChildElement,
27
+ SModelElement,
28
+ SModelRoot
29
+ } from 'sprotty';
30
+ import { EditorContextService } from '../../../base/editor-context-service';
31
+ import { TYPES } from '../../../base/types';
32
+ import { getElements, isSelectableAndBoundsAware, SelectableBoundsAware } from '../../../utils/smodel-util';
33
+
34
+ /**
35
+ * Action for triggering zooming of the viewport.
36
+ */
37
+ export interface ZoomViewportAction extends Action {
38
+ kind: typeof ZoomViewportAction.KIND;
39
+ /**
40
+ * used to specify the amount by which the viewport should be zoomed
41
+ */
42
+ zoomFactor: number;
43
+ }
44
+
45
+ export namespace ZoomViewportAction {
46
+ export const KIND = 'zoomViewportAction';
47
+
48
+ export function is(object: any): object is ZoomViewportAction {
49
+ return Action.hasKind(object, KIND);
50
+ }
51
+
52
+ export function create(zoomFactor: number): ZoomViewportAction {
53
+ return { kind: KIND, zoomFactor };
54
+ }
55
+ }
56
+
57
+ /**
58
+ * Action for triggering zooming of the elements..
59
+ */
60
+ export interface ZoomElementAction extends Action {
61
+ kind: typeof ZoomElementAction.KIND;
62
+ /**
63
+ * used to specify the elements to be zoomed in/out
64
+ */
65
+ elementIds: string[];
66
+ /**
67
+ * used to specify the amount by which the viewport should be zoomed
68
+ */
69
+ zoomFactor: number;
70
+ }
71
+
72
+ export namespace ZoomElementAction {
73
+ export const KIND = 'zoomElementAction';
74
+
75
+ export function is(object: any): object is ZoomElementAction {
76
+ return Action.hasKind(object, KIND);
77
+ }
78
+
79
+ export function create(elementIds: string[], zoomFactor: number): ZoomElementAction {
80
+ return { kind: KIND, elementIds, zoomFactor };
81
+ }
82
+ }
83
+
84
+ /* The ZoomViewportHandler class is an implementation of the IActionHandler interface that handles
85
+ zooming in and out of a viewport. */
86
+ @injectable()
87
+ export class ZoomViewportHandler implements IActionHandler {
88
+ @inject(EditorContextService)
89
+ protected editorContextService: EditorContextService;
90
+
91
+ static readonly defaultZoomInFactor = 1.1;
92
+ static readonly defaultZoomOutFactor = 0.9;
93
+
94
+ @inject(TYPES.IActionDispatcher) protected dispatcher: IActionDispatcher;
95
+ protected readonly throttledHandleViewportZoom = throttle((action: ZoomViewportAction) => this.handleZoomViewport(action), 150);
96
+
97
+ handle(action: Action): void {
98
+ if (ZoomViewportAction.is(action)) {
99
+ this.throttledHandleViewportZoom(action);
100
+ }
101
+ }
102
+
103
+ handleZoomViewport(action: ZoomViewportAction): void {
104
+ const viewport = findParentByFeature(this.editorContextService.modelRoot, isViewport);
105
+ if (!viewport) {
106
+ return;
107
+ }
108
+ this.dispatcher.dispatch(this.setNewZoomFactor(viewport, action.zoomFactor));
109
+ }
110
+
111
+ protected setNewZoomFactor(viewport: SModelRoot & Viewport, zoomFactor: number): SetViewportAction {
112
+ const newZoom = viewport.zoom * zoomFactor;
113
+
114
+ const newViewport = {
115
+ scroll: viewport.scroll,
116
+ zoom: newZoom
117
+ };
118
+
119
+ return SetViewportAction.create(viewport.id, newViewport, { animate: true });
120
+ }
121
+ }
122
+
123
+ /* The ZoomElementHandler class is an implementation of the IActionHandler interface that handles
124
+ zooming in and out of elements. */
125
+ @injectable()
126
+ export class ZoomElementHandler implements IActionHandler {
127
+ @inject(EditorContextService)
128
+ protected editorContextService: EditorContextService;
129
+ @inject(TYPES.IActionDispatcher) protected dispatcher: IActionDispatcher;
130
+ protected readonly throttledHandleElementZoom = throttle((action: ZoomElementAction) => this.handleZoomElement(action), 150);
131
+
132
+ handle(action: Action): void | Action | ICommand {
133
+ if (ZoomElementAction.is(action)) {
134
+ this.throttledHandleElementZoom(action);
135
+ }
136
+ }
137
+
138
+ handleZoomElement(action: ZoomElementAction): void {
139
+ const viewport = findParentByFeature(this.editorContextService.modelRoot, isViewport);
140
+ if (!viewport) {
141
+ return;
142
+ }
143
+
144
+ const elements = getElements(this.editorContextService.modelRoot.index, action.elementIds, isSelectableAndBoundsAware);
145
+ const center = this.getCenter(viewport, elements);
146
+ this.dispatcher.dispatch(this.setNewZoomFactor(viewport, action.zoomFactor, center));
147
+ }
148
+
149
+ protected getCenter(viewport: SModelRoot & Viewport, selectedElements: SelectableBoundsAware[]): Point {
150
+ // Get bounds of elements based on the viewport
151
+ const allBounds = selectedElements.map(e => this.boundsInViewport(viewport, e, e.bounds));
152
+ const mergedBounds = allBounds.reduce((b0, b1) => Bounds.combine(b0, b1));
153
+ return Bounds.center(mergedBounds);
154
+ }
155
+
156
+ // copy from center-fit.ts, translates the children bounds to the viewport bounds
157
+ protected boundsInViewport(viewport: SModelRoot & Viewport, element: SModelElement, bounds: Bounds): Bounds {
158
+ if (element instanceof SChildElement && element.parent !== viewport) {
159
+ return this.boundsInViewport(viewport, element.parent, element.parent.localToParent(bounds) as Bounds);
160
+ } else {
161
+ return bounds;
162
+ }
163
+ }
164
+
165
+ protected setNewZoomFactor(viewport: SModelRoot & Viewport, zoomFactor: number, point: Point): SetViewportAction {
166
+ const newZoom = viewport.zoom * zoomFactor;
167
+
168
+ const newViewport = {
169
+ scroll: {
170
+ x: point.x - (0.5 * viewport.canvasBounds.width) / newZoom,
171
+ y: point.y - (0.5 * viewport.canvasBounds.height) / newZoom
172
+ },
173
+ zoom: newZoom
174
+ };
175
+
176
+ return SetViewportAction.create(viewport.id, newViewport, { animate: true });
177
+ }
178
+ }
@@ -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 { bindAsService, BindingContext } from '@eclipse-glsp/protocol';
18
+ import { ContainerModule } from 'inversify';
19
+ import { configureActionHandler } from 'sprotty';
20
+ import { TYPES } from '../../../base/types';
21
+ import { ResizeElementAction, ResizeElementHandler } from './resize-key-handler';
22
+ import { ResizeKeyTool } from './resize-key-tool';
23
+
24
+ /**
25
+ * Handles resize actions.
26
+ */
27
+ export const glspResizeKeyModule = new ContainerModule((bind, unbind, isBound, rebind) => {
28
+ const context = { bind, unbind, isBound, rebind };
29
+ configureResizeTools(context);
30
+ });
31
+
32
+ export function configureResizeTools(context: BindingContext): void {
33
+ context.bind(ResizeElementHandler).toSelf().inSingletonScope();
34
+
35
+ configureActionHandler(context, ResizeElementAction.KIND, ResizeElementHandler);
36
+ bindAsService(context, TYPES.IDefaultTool, ResizeKeyTool);
37
+ }
@@ -0,0 +1,120 @@
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, ChangeBoundsOperation, Dimension, Point } from '@eclipse-glsp/protocol';
18
+ import { inject, injectable, optional } from 'inversify';
19
+ import { IActionDispatcher, IActionHandler, ICommand, ISnapper, SModelElement, SParentElement } from 'sprotty';
20
+ import { EditorContextService } from '../../../base/editor-context-service';
21
+ import { TYPES } from '../../../base/types';
22
+ import { isValidMove, isValidSize, minHeight, minWidth } from '../../../utils/layout-utils';
23
+ import { getElements, isSelectableAndBoundsAware, SelectableBoundsAware, toElementAndBounds } from '../../../utils/smodel-util';
24
+ import { Resizable } from '../../change-bounds/model';
25
+ import { GridSnapper } from '../../change-bounds/snap';
26
+
27
+ // eslint-disable-next-line no-shadow
28
+ export enum ResizeType {
29
+ Increase,
30
+ Decrease,
31
+ MinSize
32
+ }
33
+
34
+ /**
35
+ * Action for triggering resizing of elements.
36
+ */
37
+ export interface ResizeElementAction extends Action {
38
+ kind: typeof ResizeElementAction.KIND;
39
+ elementIds: string[];
40
+ resizeType: ResizeType;
41
+ }
42
+ export namespace ResizeElementAction {
43
+ export const KIND = 'resizeElementAction';
44
+
45
+ export function is(object: any): object is ResizeElementAction {
46
+ return Action.hasKind(object, KIND);
47
+ }
48
+
49
+ export function create(elementIds: string[], resizeType: ResizeType): ResizeElementAction {
50
+ return { kind: KIND, elementIds, resizeType };
51
+ }
52
+ }
53
+
54
+ /* The ResizeElementHandler class is an implementation of the IActionHandler interface that handles
55
+ resizing of elements. */
56
+ @injectable()
57
+ export class ResizeElementHandler implements IActionHandler {
58
+ @inject(EditorContextService)
59
+ protected editorContextService: EditorContextService;
60
+
61
+ @inject(TYPES.IActionDispatcher) protected dispatcher: IActionDispatcher;
62
+
63
+ // Default x resize used if GridSnapper is not provided
64
+ static readonly defaultResizeX = 20;
65
+
66
+ // Default y resize used if GridSnapper is not provided
67
+ static readonly defaultResizeY = 20;
68
+ protected grid = { x: ResizeElementHandler.defaultResizeX, y: ResizeElementHandler.defaultResizeY };
69
+
70
+ protected isEditMode = false;
71
+
72
+ constructor(@inject(TYPES.ISnapper) @optional() protected readonly snapper?: ISnapper) {
73
+ if (snapper instanceof GridSnapper) {
74
+ this.grid = snapper.grid;
75
+ }
76
+ }
77
+
78
+ handle(action: Action): void | Action | ICommand {
79
+ if (ResizeElementAction.is(action)) {
80
+ this.handleResizeElement(action);
81
+ }
82
+ }
83
+
84
+ handleResizeElement(action: ResizeElementAction): void {
85
+ const elements = getElements(this.editorContextService.modelRoot.index, action.elementIds, isSelectableAndBoundsAware);
86
+ this.dispatcher.dispatchAll(this.resize(elements, action));
87
+ }
88
+
89
+ protected resize(elements: SelectableBoundsAware[], action: ResizeElementAction): Action[] {
90
+ const actions: Action[] = [];
91
+
92
+ elements.forEach(element => {
93
+ const { x, y, width: oldWidth, height: oldHeight } = element.bounds;
94
+ let width = 0;
95
+ let height = 0;
96
+
97
+ if (action.resizeType === ResizeType.Decrease) {
98
+ width = oldWidth - this.grid.x;
99
+ height = oldHeight - this.grid.y;
100
+ } else if (action.resizeType === ResizeType.Increase) {
101
+ width = oldWidth + this.grid.x;
102
+ height = oldHeight + this.grid.y;
103
+ } else if (action.resizeType === ResizeType.MinSize) {
104
+ width = minWidth(element);
105
+ height = minHeight(element);
106
+ }
107
+
108
+ if (this.isValidBoundChange(element, { x, y }, { width, height })) {
109
+ const resizeElement = { id: element.id, bounds: { x, y, width, height } } as SModelElement & SParentElement & Resizable;
110
+ actions.push(ChangeBoundsOperation.create([toElementAndBounds(resizeElement)]));
111
+ }
112
+ });
113
+
114
+ return actions;
115
+ }
116
+
117
+ protected isValidBoundChange(element: SelectableBoundsAware, newPosition: Point, newSize: Dimension): boolean {
118
+ return isValidSize(element, newSize) && isValidMove(element, newPosition);
119
+ }
120
+ }
@@ -0,0 +1,108 @@
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 { EnableDefaultToolsAction, EnableToolsAction, 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 { IMovementRestrictor } from '../../change-bounds/movement-restrictor';
24
+ import { SelectionService } from '../../select/selection-service';
25
+ import { ResizeElementAction, ResizeType } from './resize-key-handler';
26
+
27
+ @injectable()
28
+ export class ResizeKeyTool implements GLSPTool {
29
+ static ID = 'glsp.resize-key-tool';
30
+
31
+ isEditTool = true;
32
+
33
+ @inject(KeyTool) protected readonly keytool: KeyTool;
34
+ @inject(TYPES.IMovementRestrictor) @optional() readonly movementRestrictor?: IMovementRestrictor;
35
+ @inject(TYPES.ISnapper) @optional() readonly snapper?: ISnapper;
36
+ @inject(TYPES.SelectionService) readonly selectionService: SelectionService;
37
+
38
+ protected resizeKeyListener: ResizeKeyListener = new ResizeKeyListener(this);
39
+
40
+ get id(): string {
41
+ return ResizeKeyTool.ID;
42
+ }
43
+
44
+ enable(): void {
45
+ this.keytool.register(this.resizeKeyListener);
46
+ }
47
+
48
+ disable(): void {
49
+ this.keytool.deregister(this.resizeKeyListener);
50
+ }
51
+ }
52
+ @injectable()
53
+ export class ResizeKeyListener extends KeyListener {
54
+ protected isEditMode = false;
55
+
56
+ constructor(protected readonly tool: ResizeKeyTool) {
57
+ super();
58
+ }
59
+
60
+ override keyDown(element: SModelElement, event: KeyboardEvent): Action[] {
61
+ const actions = [];
62
+ const selectedElementsIds = this.tool.selectionService.getSelectedElementIDs();
63
+
64
+ if (this.isEditMode && this.matchesDeactivateResizeModeKeystroke(event)) {
65
+ this.isEditMode = false;
66
+ actions.push(EnableDefaultToolsAction.create());
67
+ }
68
+
69
+ if (selectedElementsIds.length > 0) {
70
+ if (!this.isEditMode && this.matchesActivateResizeModeKeystroke(event)) {
71
+ this.isEditMode = true;
72
+ actions.push(EnableToolsAction.create([ResizeKeyTool.ID]));
73
+ }
74
+
75
+ if (this.isEditMode) {
76
+ if (this.matchesIncreaseSizeKeystroke(event)) {
77
+ actions.push(ResizeElementAction.create(selectedElementsIds, ResizeType.Increase));
78
+ } else if (this.matchesDecreaseSizeKeystroke(event)) {
79
+ actions.push(ResizeElementAction.create(selectedElementsIds, ResizeType.Decrease));
80
+ } else if (this.matchesMinSizeKeystroke(event)) {
81
+ actions.push(ResizeElementAction.create(selectedElementsIds, ResizeType.MinSize));
82
+ }
83
+ }
84
+ }
85
+ return actions;
86
+ }
87
+
88
+ protected matchesIncreaseSizeKeystroke(event: KeyboardEvent): boolean {
89
+ /** here event.key is used for '+', as keycode 187 is already declared for 'Equals' in {@link matchesKeystroke}.*/
90
+ return event.key === '+' || matchesKeystroke(event, 'NumpadAdd');
91
+ }
92
+
93
+ protected matchesActivateResizeModeKeystroke(event: KeyboardEvent): boolean {
94
+ return matchesKeystroke(event, 'KeyA', 'alt');
95
+ }
96
+
97
+ protected matchesDeactivateResizeModeKeystroke(event: KeyboardEvent): boolean {
98
+ return matchesKeystroke(event, 'Escape');
99
+ }
100
+
101
+ protected matchesMinSizeKeystroke(event: KeyboardEvent): boolean {
102
+ return matchesKeystroke(event, 'Digit0', 'ctrl') || matchesKeystroke(event, 'Numpad0', 'ctrl');
103
+ }
104
+
105
+ protected matchesDecreaseSizeKeystroke(event: KeyboardEvent): boolean {
106
+ return matchesKeystroke(event, 'Minus') || matchesKeystroke(event, 'NumpadSubtract');
107
+ }
108
+ }
@@ -0,0 +1,31 @@
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 { bindAsService, BindingContext } from '@eclipse-glsp/protocol';
18
+ import { ContainerModule } from 'inversify';
19
+ import { TYPES } from '../../../base/types';
20
+ import { SearchAutocompletePalette } from './search-palette';
21
+ import { SearchAutocompletePaletteTool } from './search-tool';
22
+
23
+ export const glspSearchPaletteModule = new ContainerModule((bind, _unbind, isBound, rebind) => {
24
+ const context = { bind, isBound, rebind };
25
+ configureSearchPaletteModule(context);
26
+ });
27
+
28
+ export function configureSearchPaletteModule(context: Pick<BindingContext, 'bind'>): void {
29
+ bindAsService(context, TYPES.IUIExtension, SearchAutocompletePalette);
30
+ bindAsService(context, TYPES.IDefaultTool, SearchAutocompletePaletteTool);
31
+ }