@eclipse-glsp/client 2.3.0-next.391 → 2.3.0-next.392
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.
- package/lib/base/default.module.d.ts.map +1 -1
- package/lib/base/default.module.js +4 -2
- package/lib/base/default.module.js.map +1 -1
- package/lib/base/feedback/feedback-action-dispatcher.d.ts +18 -5
- package/lib/base/feedback/feedback-action-dispatcher.d.ts.map +1 -1
- package/lib/base/feedback/feedback-action-dispatcher.js +113 -10
- package/lib/base/feedback/feedback-action-dispatcher.js.map +1 -1
- package/lib/base/feedback/feedback-emitter.d.ts +2 -2
- package/lib/base/feedback/feedback-emitter.d.ts.map +1 -1
- package/lib/base/feedback/feedback-emitter.js +1 -2
- package/lib/base/feedback/feedback-emitter.js.map +1 -1
- package/lib/features/context-menu/delete-element-context-menu.d.ts +19 -2
- package/lib/features/context-menu/delete-element-context-menu.d.ts.map +1 -1
- package/lib/features/context-menu/delete-element-context-menu.js +11 -7
- package/lib/features/context-menu/delete-element-context-menu.js.map +1 -1
- package/lib/features/helper-lines/helper-line-manager.d.ts +78 -2
- package/lib/features/helper-lines/helper-line-manager.d.ts.map +1 -1
- package/lib/features/helper-lines/helper-line-manager.js +194 -0
- package/lib/features/helper-lines/helper-line-manager.js.map +1 -1
- package/lib/features/helper-lines/helper-line-module.js +2 -2
- package/lib/features/helper-lines/helper-line-module.js.map +1 -1
- package/lib/features/navigation/navigation-action-handler.d.ts +5 -1
- package/lib/features/navigation/navigation-action-handler.d.ts.map +1 -1
- package/lib/features/navigation/navigation-action-handler.js +11 -4
- package/lib/features/navigation/navigation-action-handler.js.map +1 -1
- package/lib/features/tools/base-tools.d.ts +2 -2
- package/lib/features/tools/base-tools.d.ts.map +1 -1
- package/lib/features/tools/base-tools.js.map +1 -1
- package/lib/index.d.ts +0 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +0 -2
- package/lib/index.js.map +1 -1
- package/package.json +3 -3
- package/src/base/default.module.ts +3 -1
- package/src/base/feedback/feedback-action-dispatcher.ts +114 -11
- package/src/base/feedback/feedback-emitter.ts +2 -2
- package/src/features/context-menu/delete-element-context-menu.ts +11 -7
- package/src/features/helper-lines/helper-line-manager.ts +234 -2
- package/src/features/helper-lines/helper-line-module.ts +1 -1
- package/src/features/hints/type-hint-provider.spec.ts +1 -1
- package/src/features/navigation/navigation-action-handler.ts +9 -5
- package/src/features/tools/base-tools.ts +2 -2
- package/src/index.ts +0 -2
- package/lib/base/feedback/feedback-action-dispatcher-default.d.ts +0 -36
- package/lib/base/feedback/feedback-action-dispatcher-default.d.ts.map +0 -1
- package/lib/base/feedback/feedback-action-dispatcher-default.js +0 -133
- package/lib/base/feedback/feedback-action-dispatcher-default.js.map +0 -1
- package/lib/features/helper-lines/helper-line-manager-default.d.ts +0 -95
- package/lib/features/helper-lines/helper-line-manager-default.d.ts.map +0 -1
- package/lib/features/helper-lines/helper-line-manager-default.js +0 -197
- package/lib/features/helper-lines/helper-line-manager-default.js.map +0 -1
- package/src/base/feedback/feedback-action-dispatcher-default.ts +0 -130
- package/src/features/helper-lines/helper-line-manager-default.ts +0 -250
|
@@ -13,23 +13,29 @@
|
|
|
13
13
|
*
|
|
14
14
|
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
15
|
********************************************************************************/
|
|
16
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
Action,
|
|
18
|
+
ActionHandlerRegistry,
|
|
19
|
+
Command,
|
|
20
|
+
CommandActionHandler,
|
|
21
|
+
CommandExecutionContext,
|
|
22
|
+
Disposable,
|
|
23
|
+
GModelElement,
|
|
24
|
+
IActionDispatcher,
|
|
25
|
+
ICommand,
|
|
26
|
+
ILogger,
|
|
27
|
+
MaybeActions,
|
|
28
|
+
TYPES,
|
|
29
|
+
toTypeGuard
|
|
30
|
+
} from '@eclipse-glsp/sprotty';
|
|
31
|
+
import { inject, injectable, preDestroy } from 'inversify';
|
|
32
|
+
import { getFeedbackRank } from './feedback-command';
|
|
17
33
|
import { FeedbackEmitter } from './feedback-emitter';
|
|
18
34
|
|
|
19
35
|
export interface IFeedbackEmitter {}
|
|
20
36
|
|
|
21
37
|
export const feedbackFeature = Symbol('feedbackFeature');
|
|
22
38
|
|
|
23
|
-
export type MaybeActions = MaybeFunction<Action[] | Action | undefined>;
|
|
24
|
-
|
|
25
|
-
export namespace MaybeActions {
|
|
26
|
-
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
27
|
-
export function asArray(actions?: MaybeActions): Action[] {
|
|
28
|
-
const cleanup = actions ? call(actions) : [];
|
|
29
|
-
return cleanup ? toArray(cleanup) : [];
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
39
|
/**
|
|
34
40
|
* Dispatcher for actions that are meant to show visual feedback on
|
|
35
41
|
* the diagram that is not part of the diagram sent from the server
|
|
@@ -86,3 +92,100 @@ export interface IFeedbackActionDispatcher {
|
|
|
86
92
|
*/
|
|
87
93
|
createEmitter(): FeedbackEmitter;
|
|
88
94
|
}
|
|
95
|
+
|
|
96
|
+
@injectable()
|
|
97
|
+
export class FeedbackActionDispatcher implements IFeedbackActionDispatcher, Disposable {
|
|
98
|
+
protected registeredFeedback: Map<IFeedbackEmitter, Action[]> = new Map();
|
|
99
|
+
|
|
100
|
+
@inject(TYPES.IActionDispatcher) protected actionDispatcher: IActionDispatcher;
|
|
101
|
+
|
|
102
|
+
@inject(TYPES.ILogger) protected logger: ILogger;
|
|
103
|
+
|
|
104
|
+
@inject(ActionHandlerRegistry) protected actionHandlerRegistry: ActionHandlerRegistry;
|
|
105
|
+
|
|
106
|
+
protected isDisposed = false;
|
|
107
|
+
|
|
108
|
+
registerFeedback(feedbackEmitter: IFeedbackEmitter, feedbackActions: Action[], cleanupActions?: MaybeActions): Disposable {
|
|
109
|
+
if (feedbackEmitter instanceof GModelElement) {
|
|
110
|
+
this.logger.log(
|
|
111
|
+
this,
|
|
112
|
+
// eslint-disable-next-line max-len
|
|
113
|
+
'GModelElements as feedback emitters are discouraged, as they usually change between model updates and are considered unstable.'
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
if (feedbackActions.length > 0) {
|
|
117
|
+
this.registeredFeedback.set(feedbackEmitter, feedbackActions);
|
|
118
|
+
this.dispatchFeedback(feedbackActions, feedbackEmitter);
|
|
119
|
+
}
|
|
120
|
+
return Disposable.create(() => this.deregisterFeedback(feedbackEmitter, cleanupActions));
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
deregisterFeedback(feedbackEmitter: IFeedbackEmitter, cleanupActions?: MaybeActions): void {
|
|
124
|
+
this.registeredFeedback.delete(feedbackEmitter);
|
|
125
|
+
const actions = MaybeActions.asArray(cleanupActions);
|
|
126
|
+
if (actions.length > 0) {
|
|
127
|
+
this.dispatchFeedback(actions, feedbackEmitter);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
getRegisteredFeedback(): Action[] {
|
|
132
|
+
const result: Action[] = [];
|
|
133
|
+
this.registeredFeedback.forEach(actions => result.push(...actions));
|
|
134
|
+
return result;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
getRegisteredFeedbackEmitters(action: Action): IFeedbackEmitter[] {
|
|
138
|
+
const result: IFeedbackEmitter[] = [];
|
|
139
|
+
this.registeredFeedback.forEach((actions, emitter) => {
|
|
140
|
+
if (actions.includes(action)) {
|
|
141
|
+
result.push(emitter);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
return result;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
getFeedbackCommands(): Command[] {
|
|
148
|
+
return this.getRegisteredFeedback()
|
|
149
|
+
.flatMap(action => this.actionToCommands(action))
|
|
150
|
+
.sort((left, right) => getFeedbackRank(left) - getFeedbackRank(right));
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
async applyFeedbackCommands(context: CommandExecutionContext): Promise<void> {
|
|
154
|
+
const feedbackCommands = this.getFeedbackCommands() ?? [];
|
|
155
|
+
if (feedbackCommands?.length > 0) {
|
|
156
|
+
const results = feedbackCommands.map(command => command.execute(context));
|
|
157
|
+
await Promise.all(results);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
protected actionToCommands(action: Action): ICommand[] {
|
|
162
|
+
return (
|
|
163
|
+
this.actionHandlerRegistry
|
|
164
|
+
.get(action.kind)
|
|
165
|
+
.filter(toTypeGuard(CommandActionHandler))
|
|
166
|
+
.map(handler => handler.handle(action)) ?? []
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
createEmitter(): FeedbackEmitter {
|
|
171
|
+
return new FeedbackEmitter(this);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
protected async dispatchFeedback(actions: Action[], feedbackEmitter: IFeedbackEmitter): Promise<void> {
|
|
175
|
+
try {
|
|
176
|
+
if (this.isDisposed) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
await this.actionDispatcher.dispatchAll(actions);
|
|
180
|
+
this.logger.info(this, `Dispatched feedback actions for ${feedbackEmitter}`);
|
|
181
|
+
} catch (reason) {
|
|
182
|
+
this.logger.error(this, 'Failed to dispatch feedback actions', reason);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
@preDestroy()
|
|
187
|
+
dispose(): void {
|
|
188
|
+
this.registeredFeedback.clear();
|
|
189
|
+
this.isDisposed = true;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
15
|
********************************************************************************/
|
|
16
16
|
|
|
17
|
-
import { Action, Disposable, arrayOf } from '@eclipse-glsp/sprotty';
|
|
18
|
-
import { IFeedbackActionDispatcher, IFeedbackEmitter
|
|
17
|
+
import { Action, Disposable, MaybeActions, arrayOf } from '@eclipse-glsp/sprotty';
|
|
18
|
+
import type { IFeedbackActionDispatcher, IFeedbackEmitter } from './feedback-action-dispatcher';
|
|
19
19
|
|
|
20
20
|
// counter for internal id, mainly useful for debugging
|
|
21
21
|
let idCounter = 0;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/********************************************************************************
|
|
2
|
-
* Copyright (c) 2019-
|
|
2
|
+
* Copyright (c) 2019-2024 EclipseSource and others.
|
|
3
3
|
*
|
|
4
4
|
* This program and the accompanying materials are made available under the
|
|
5
5
|
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
@@ -13,27 +13,31 @@
|
|
|
13
13
|
*
|
|
14
14
|
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
15
|
********************************************************************************/
|
|
16
|
+
import { DeleteElementOperation, GModelRoot, IContextMenuItemProvider, MenuItem, Point, TYPES } from '@eclipse-glsp/sprotty';
|
|
16
17
|
import { inject, injectable } from 'inversify';
|
|
17
|
-
import { DeleteElementOperation, IContextMenuItemProvider, MenuItem, Point, GModelRoot, TYPES } from '@eclipse-glsp/sprotty';
|
|
18
18
|
import { EditorContextService, EditorContextServiceProvider } from '../../base/editor-context-service';
|
|
19
19
|
|
|
20
20
|
@injectable()
|
|
21
21
|
export class DeleteElementContextMenuItemProvider implements IContextMenuItemProvider {
|
|
22
|
+
/** @deprecated No longer used. The {@link EditorContextService} is now directly injected.*/
|
|
23
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
22
24
|
@inject(TYPES.IEditorContextServiceProvider) editorContextServiceProvider: EditorContextServiceProvider;
|
|
23
25
|
|
|
26
|
+
@inject(EditorContextService)
|
|
27
|
+
protected editorContext: EditorContextService;
|
|
28
|
+
|
|
24
29
|
async getItems(_root: Readonly<GModelRoot>, _lastMousePosition?: Point): Promise<MenuItem[]> {
|
|
25
|
-
|
|
26
|
-
return [this.createDeleteMenuItem(editorContextService)];
|
|
30
|
+
return [this.createDeleteMenuItem()];
|
|
27
31
|
}
|
|
28
32
|
|
|
29
|
-
protected createDeleteMenuItem(
|
|
33
|
+
protected createDeleteMenuItem(): MenuItem {
|
|
30
34
|
return {
|
|
31
35
|
id: 'delete',
|
|
32
36
|
label: 'Delete',
|
|
33
37
|
sortString: 'd',
|
|
34
38
|
group: 'edit',
|
|
35
|
-
actions: [DeleteElementOperation.create(
|
|
36
|
-
isEnabled: () => !
|
|
39
|
+
actions: [DeleteElementOperation.create(this.editorContext.selectedElements.map(e => e.id))],
|
|
40
|
+
isEnabled: () => !this.editorContext.isReadonly && this.editorContext.selectedElements.length > 0
|
|
37
41
|
};
|
|
38
42
|
}
|
|
39
43
|
}
|
|
@@ -13,8 +13,38 @@
|
|
|
13
13
|
*
|
|
14
14
|
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
15
|
********************************************************************************/
|
|
16
|
-
import {
|
|
17
|
-
|
|
16
|
+
import {
|
|
17
|
+
Action,
|
|
18
|
+
GModelElement,
|
|
19
|
+
GModelRoot,
|
|
20
|
+
IActionHandler,
|
|
21
|
+
MoveAction,
|
|
22
|
+
Point,
|
|
23
|
+
SetBoundsAction,
|
|
24
|
+
TYPES,
|
|
25
|
+
Vector,
|
|
26
|
+
Writable
|
|
27
|
+
} from '@eclipse-glsp/sprotty';
|
|
28
|
+
import { inject, injectable, optional, postConstruct } from 'inversify';
|
|
29
|
+
import { IFeedbackActionDispatcher } from '../../base/feedback/feedback-action-dispatcher';
|
|
30
|
+
import { FeedbackEmitter } from '../../base/feedback/feedback-emitter';
|
|
31
|
+
import { ISelectionListener, SelectionService } from '../../base/selection-service';
|
|
32
|
+
import { SetBoundsFeedbackAction } from '../bounds/set-bounds-feedback-command';
|
|
33
|
+
import { GResizeHandle, ResizeHandleLocation } from '../change-bounds/model';
|
|
34
|
+
import { Grid } from '../grid/grid';
|
|
35
|
+
import { MoveFinishedEventAction, MoveInitializedEventAction } from '../tools/change-bounds/change-bounds-tool-feedback';
|
|
36
|
+
import {
|
|
37
|
+
AlignmentElementFilter,
|
|
38
|
+
DEFAULT_ALIGNABLE_ELEMENT_FILTER,
|
|
39
|
+
DEFAULT_DEBUG,
|
|
40
|
+
DEFAULT_ELEMENT_LINES,
|
|
41
|
+
DEFAULT_EPSILON,
|
|
42
|
+
DEFAULT_VIEWPORT_LINES,
|
|
43
|
+
DrawHelperLinesFeedbackAction,
|
|
44
|
+
RemoveHelperLinesFeedbackAction,
|
|
45
|
+
ViewportLineType
|
|
46
|
+
} from './helper-line-feedback';
|
|
47
|
+
import { Direction, HelperLine, HelperLineType, isHelperLine } from './model';
|
|
18
48
|
|
|
19
49
|
export interface IHelperLineManager {
|
|
20
50
|
/**
|
|
@@ -35,3 +65,205 @@ export interface IHelperLineManager {
|
|
|
35
65
|
*/
|
|
36
66
|
getMinimumMoveVector(element: GModelElement, isSnap: boolean, directions: Direction[]): Vector | undefined;
|
|
37
67
|
}
|
|
68
|
+
|
|
69
|
+
export interface IHelperLineOptions {
|
|
70
|
+
/**
|
|
71
|
+
* A list of helper line types that should be rendered when elements are aligned.
|
|
72
|
+
* Defaults to all possible alignments.
|
|
73
|
+
*/
|
|
74
|
+
elementLines?: HelperLineType[];
|
|
75
|
+
/**
|
|
76
|
+
* A list of helper line types that should be rendered when an element is aligned with the viewport.
|
|
77
|
+
* Defaults to middle and center alignment.
|
|
78
|
+
*/
|
|
79
|
+
viewportLines?: ViewportLineType[];
|
|
80
|
+
/**
|
|
81
|
+
* The minimum difference between two coordinates
|
|
82
|
+
* Defaults to 1 or zero (perfect match) if the optional grid module is loaded.
|
|
83
|
+
*/
|
|
84
|
+
alignmentEpsilon?: number;
|
|
85
|
+
/**
|
|
86
|
+
* A filter that is applied to determine on which elements the alignment calculation is performed.
|
|
87
|
+
* By default all top-level bounds-aware, non-routable elements that are visible on the canvas are considered.
|
|
88
|
+
*/
|
|
89
|
+
alignmentElementFilter?: AlignmentElementFilter;
|
|
90
|
+
/**
|
|
91
|
+
* The minimum move delta that is necessary for an element to break through a helper line.
|
|
92
|
+
* Defaults to { x: 1, y: 1 } whereas the x represents the horizontal distance and y represents the vertical distance.
|
|
93
|
+
* If the optional grid module is loaded, defaults to twice the grid size, i.e., two grid moves to break through a helper line.
|
|
94
|
+
*/
|
|
95
|
+
minimumMoveDelta?: Point;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Produces debug output.
|
|
99
|
+
* Defaults to false.
|
|
100
|
+
*/
|
|
101
|
+
debug?: boolean;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export const DEFAULT_MOVE_DELTA = { x: 1, y: 1 };
|
|
105
|
+
|
|
106
|
+
export const DEFAULT_HELPER_LINE_OPTIONS: Required<IHelperLineOptions> = {
|
|
107
|
+
elementLines: DEFAULT_ELEMENT_LINES,
|
|
108
|
+
viewportLines: DEFAULT_VIEWPORT_LINES,
|
|
109
|
+
alignmentEpsilon: DEFAULT_EPSILON,
|
|
110
|
+
alignmentElementFilter: DEFAULT_ALIGNABLE_ELEMENT_FILTER,
|
|
111
|
+
minimumMoveDelta: DEFAULT_MOVE_DELTA,
|
|
112
|
+
debug: DEFAULT_DEBUG
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
@injectable()
|
|
116
|
+
export class HelperLineManager implements IActionHandler, ISelectionListener, IHelperLineManager {
|
|
117
|
+
@inject(TYPES.IFeedbackActionDispatcher) protected feedbackDispatcher: IFeedbackActionDispatcher;
|
|
118
|
+
@inject(SelectionService) protected selectionService: SelectionService;
|
|
119
|
+
@optional() @inject(TYPES.IHelperLineOptions) protected userOptions?: IHelperLineOptions;
|
|
120
|
+
@optional() @inject(TYPES.Grid) protected grid?: Grid;
|
|
121
|
+
|
|
122
|
+
protected options: Required<IHelperLineOptions>;
|
|
123
|
+
protected feedback: FeedbackEmitter;
|
|
124
|
+
|
|
125
|
+
@postConstruct()
|
|
126
|
+
protected init(): void {
|
|
127
|
+
this.feedback = this.feedbackDispatcher.createEmitter();
|
|
128
|
+
const dynamicOptions: IHelperLineOptions = {};
|
|
129
|
+
if (this.grid) {
|
|
130
|
+
dynamicOptions.alignmentEpsilon = 0;
|
|
131
|
+
dynamicOptions.minimumMoveDelta = Point.multiplyScalar(this.grid, 2);
|
|
132
|
+
}
|
|
133
|
+
this.options = { ...DEFAULT_HELPER_LINE_OPTIONS, ...dynamicOptions, ...this.userOptions };
|
|
134
|
+
this.selectionService.addListener(this);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
handle(action: Action): void {
|
|
138
|
+
if (MoveInitializedEventAction.is(action)) {
|
|
139
|
+
this.handleMoveInitializedAction(action);
|
|
140
|
+
} else if (MoveAction.is(action)) {
|
|
141
|
+
this.handleMoveAction(action);
|
|
142
|
+
} else if (MoveFinishedEventAction.is(action)) {
|
|
143
|
+
this.handleMoveFinishedAction(action);
|
|
144
|
+
} else if (SetBoundsAction.is(action) || SetBoundsFeedbackAction.is(action)) {
|
|
145
|
+
this.handleSetBoundsAction(action);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
protected handleMoveInitializedAction(_action: MoveInitializedEventAction): void {
|
|
150
|
+
this.submitHelperLineFeedback();
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
protected handleMoveFinishedAction(_action: MoveFinishedEventAction): void {
|
|
154
|
+
this.feedback.dispose();
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
protected handleMoveAction(action: MoveAction): void {
|
|
158
|
+
if (!action.finished) {
|
|
159
|
+
this.submitHelperLineFeedback(action.moves.map(move => move.elementId));
|
|
160
|
+
} else {
|
|
161
|
+
this.feedback.dispose();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
protected submitHelperLineFeedback(elementIds: string[] = this.selectionService.getSelectedElementIDs()): void {
|
|
166
|
+
const feedback = this.createHelperLineFeedback(elementIds);
|
|
167
|
+
this.feedback.add(feedback, [RemoveHelperLinesFeedbackAction.create()]).submit();
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
protected createHelperLineFeedback(elementIds: string[]): DrawHelperLinesFeedbackAction {
|
|
171
|
+
return DrawHelperLinesFeedbackAction.create({ elementIds, ...this.options });
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
protected handleSetBoundsAction(action: SetBoundsAction | SetBoundsFeedbackAction): void {
|
|
175
|
+
this.submitHelperLineFeedback(action.bounds.map(bound => bound.elementId));
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
selectionChanged(root: Readonly<GModelRoot>, selectedElements: string[], deselectedElements?: string[] | undefined): void {
|
|
179
|
+
this.feedback.dispose();
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
getMinimumMoveDelta(element: GModelElement, isSnap: boolean, direction: Direction): number {
|
|
183
|
+
if (!isSnap) {
|
|
184
|
+
return 0;
|
|
185
|
+
}
|
|
186
|
+
const minimumMoveDelta = this.options.minimumMoveDelta;
|
|
187
|
+
return direction === Direction.Left || direction === Direction.Right ? minimumMoveDelta.x : minimumMoveDelta.y;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
getMinimumMoveVector(element: GModelElement, isSnap: boolean, move: Direction[]): Vector | undefined {
|
|
191
|
+
if (!isSnap) {
|
|
192
|
+
return undefined;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const state = this.getHelperLineState(element);
|
|
196
|
+
if (state.helperLines.length === 0) {
|
|
197
|
+
return undefined;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const minimum: Writable<Vector> = { ...Vector.ZERO };
|
|
201
|
+
const resize =
|
|
202
|
+
element instanceof GResizeHandle
|
|
203
|
+
? ResizeHandleLocation.direction(element.location)
|
|
204
|
+
: [Direction.Left, Direction.Right, Direction.Up, Direction.Down];
|
|
205
|
+
|
|
206
|
+
if ((state.types.left || state.types.center) && move.includes(Direction.Left) && resize.includes(Direction.Left)) {
|
|
207
|
+
minimum.x = this.getMinimumMoveDelta(element, isSnap, Direction.Left);
|
|
208
|
+
} else if ((state.types.right || state.types.center) && move.includes(Direction.Right) && resize.includes(Direction.Right)) {
|
|
209
|
+
minimum.x = this.getMinimumMoveDelta(element, isSnap, Direction.Right);
|
|
210
|
+
}
|
|
211
|
+
if ((state.types.top || state.types.middle) && move.includes(Direction.Up) && resize.includes(Direction.Up)) {
|
|
212
|
+
minimum.y = this.getMinimumMoveDelta(element, isSnap, Direction.Up);
|
|
213
|
+
} else if ((state.types.bottom || state.types.middle) && move.includes(Direction.Down) && resize.includes(Direction.Down)) {
|
|
214
|
+
minimum.y = this.getMinimumMoveDelta(element, isSnap, Direction.Down);
|
|
215
|
+
}
|
|
216
|
+
return Vector.isZero(minimum) ? undefined : minimum;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
protected getHelperLineState(element: GModelElement): HelperLineState {
|
|
220
|
+
const helperLines = element.root.children.filter(isHelperLine) || [];
|
|
221
|
+
const types = {
|
|
222
|
+
left: false,
|
|
223
|
+
right: false,
|
|
224
|
+
top: false,
|
|
225
|
+
bottom: false,
|
|
226
|
+
center: false,
|
|
227
|
+
middle: false
|
|
228
|
+
};
|
|
229
|
+
for (const line of helperLines) {
|
|
230
|
+
switch (line.lineType) {
|
|
231
|
+
case HelperLineType.Left:
|
|
232
|
+
case HelperLineType.LeftRight:
|
|
233
|
+
types.left = true;
|
|
234
|
+
break;
|
|
235
|
+
case HelperLineType.Right:
|
|
236
|
+
case HelperLineType.RightLeft:
|
|
237
|
+
types.right = true;
|
|
238
|
+
break;
|
|
239
|
+
case HelperLineType.Top:
|
|
240
|
+
case HelperLineType.TopBottom:
|
|
241
|
+
types.top = true;
|
|
242
|
+
break;
|
|
243
|
+
case HelperLineType.Bottom:
|
|
244
|
+
case HelperLineType.BottomTop:
|
|
245
|
+
types.bottom = true;
|
|
246
|
+
break;
|
|
247
|
+
case HelperLineType.Center:
|
|
248
|
+
types.center = true;
|
|
249
|
+
break;
|
|
250
|
+
case HelperLineType.Middle:
|
|
251
|
+
types.middle = true;
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return { helperLines, types };
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export interface HelperLineState {
|
|
260
|
+
helperLines: HelperLine[];
|
|
261
|
+
types: {
|
|
262
|
+
left: boolean;
|
|
263
|
+
right: boolean;
|
|
264
|
+
top: boolean;
|
|
265
|
+
bottom: boolean;
|
|
266
|
+
center: boolean;
|
|
267
|
+
middle: boolean;
|
|
268
|
+
};
|
|
269
|
+
}
|
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
import { SetBoundsFeedbackAction } from '../bounds/set-bounds-feedback-command';
|
|
28
28
|
import { MoveFinishedEventAction, MoveInitializedEventAction } from '../tools/change-bounds/change-bounds-tool-feedback';
|
|
29
29
|
import { DrawHelperLinesFeedbackCommand, RemoveHelperLinesFeedbackCommand } from './helper-line-feedback';
|
|
30
|
-
import { HelperLineManager } from './helper-line-manager
|
|
30
|
+
import { HelperLineManager } from './helper-line-manager';
|
|
31
31
|
import { HELPER_LINE, HelperLine, SELECTION_BOUNDS, SelectionBounds } from './model';
|
|
32
32
|
import { HelperLineView, SelectionBoundsView } from './view';
|
|
33
33
|
|
|
@@ -36,7 +36,7 @@ import { expect } from 'chai';
|
|
|
36
36
|
import { Container } from 'inversify';
|
|
37
37
|
import * as sinon from 'sinon';
|
|
38
38
|
import { GLSPActionDispatcher } from '../../base/action-dispatcher';
|
|
39
|
-
import { FeedbackActionDispatcher } from '../../base/feedback/feedback-action-dispatcher
|
|
39
|
+
import { FeedbackActionDispatcher } from '../../base/feedback/feedback-action-dispatcher';
|
|
40
40
|
import { FeedbackEmitter } from '../../base/feedback/feedback-emitter';
|
|
41
41
|
import { GEdge } from '../../model';
|
|
42
42
|
import { isResizable } from '../change-bounds/model';
|
|
@@ -38,7 +38,7 @@ import {
|
|
|
38
38
|
hasStringProp
|
|
39
39
|
} from '@eclipse-glsp/sprotty';
|
|
40
40
|
import { inject, injectable } from 'inversify';
|
|
41
|
-
import { EditorContextServiceProvider } from '../../base/editor-context-service';
|
|
41
|
+
import { EditorContextService, EditorContextServiceProvider } from '../../base/editor-context-service';
|
|
42
42
|
import { NavigationTargetResolver } from './navigation-target-resolver';
|
|
43
43
|
|
|
44
44
|
/**
|
|
@@ -140,9 +140,15 @@ export class NavigationActionHandler implements IActionHandler {
|
|
|
140
140
|
|
|
141
141
|
@inject(TYPES.ILogger) protected logger: ILogger;
|
|
142
142
|
@inject(TYPES.IActionDispatcher) protected dispatcher: IActionDispatcher;
|
|
143
|
+
/** @deprecated No longer in used. The {@link ActionHandlerRegistry} is now directly injected */
|
|
144
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
143
145
|
@inject(TYPES.ActionHandlerRegistryProvider) protected actionHandlerRegistryProvider: () => Promise<ActionHandlerRegistry>;
|
|
146
|
+
/** @deprecated No longer in used. The {@link EditorContextService} is now directly injected */
|
|
147
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
144
148
|
@inject(TYPES.IEditorContextServiceProvider) protected editorContextService: EditorContextServiceProvider;
|
|
149
|
+
@inject(ActionHandlerRegistry) protected actionHandlerRegistry: ActionHandlerRegistry;
|
|
145
150
|
@inject(NavigationTargetResolver) protected resolver: NavigationTargetResolver;
|
|
151
|
+
@inject(EditorContextService) protected editorContext: EditorContextService;
|
|
146
152
|
|
|
147
153
|
handle(action: Action): ICommand | Action | void {
|
|
148
154
|
if (NavigateAction.is(action)) {
|
|
@@ -158,8 +164,7 @@ export class NavigationActionHandler implements IActionHandler {
|
|
|
158
164
|
|
|
159
165
|
protected async handleNavigateAction(action: NavigateAction): Promise<void> {
|
|
160
166
|
try {
|
|
161
|
-
const
|
|
162
|
-
const editorContext = editorContextService.get(action.args);
|
|
167
|
+
const editorContext = this.editorContext.get(action.args);
|
|
163
168
|
const response = await this.dispatcher.request(
|
|
164
169
|
RequestNavigationTargetsAction.create({ targetTypeId: action.targetTypeId, editorContext })
|
|
165
170
|
);
|
|
@@ -250,8 +255,7 @@ export class NavigationActionHandler implements IActionHandler {
|
|
|
250
255
|
}
|
|
251
256
|
|
|
252
257
|
protected async handleNavigateToExternalTarget(action: NavigateToExternalTargetAction): Promise<void> {
|
|
253
|
-
const
|
|
254
|
-
const handlers = registry.get(NavigateToExternalTargetAction.KIND);
|
|
258
|
+
const handlers = this.actionHandlerRegistry.get(NavigateToExternalTargetAction.KIND);
|
|
255
259
|
if (handlers.length === 1) {
|
|
256
260
|
// we are the only handler so we know nobody took care of it
|
|
257
261
|
this.warnAboutFailedNavigation('Could not resolve or navigate to target', action.target);
|
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
*
|
|
14
14
|
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
15
|
********************************************************************************/
|
|
16
|
-
import { Action, Disposable, DisposableCollection, IActionDispatcher, IActionHandler, TYPES } from '@eclipse-glsp/sprotty';
|
|
16
|
+
import { Action, Disposable, DisposableCollection, IActionDispatcher, IActionHandler, MaybeActions, TYPES } from '@eclipse-glsp/sprotty';
|
|
17
17
|
import { inject, injectable } from 'inversify';
|
|
18
18
|
import { EditorContextService } from '../../base/editor-context-service';
|
|
19
|
-
import { IFeedbackActionDispatcher, IFeedbackEmitter
|
|
19
|
+
import { IFeedbackActionDispatcher, IFeedbackEmitter } from '../../base/feedback/feedback-action-dispatcher';
|
|
20
20
|
import { FeedbackEmitter } from '../../base/feedback/feedback-emitter';
|
|
21
21
|
import { EnableToolsAction, Tool } from '../../base/tool-manager/tool';
|
|
22
22
|
import { GLSPKeyTool } from '../../base/view/key-tool';
|
package/src/index.ts
CHANGED
|
@@ -27,7 +27,6 @@ export * from './base/drag-aware-mouse-listener';
|
|
|
27
27
|
export * from './base/editor-context-service';
|
|
28
28
|
export * from './base/feedback/css-feedback';
|
|
29
29
|
export * from './base/feedback/feedback-action-dispatcher';
|
|
30
|
-
export * from './base/feedback/feedback-action-dispatcher-default';
|
|
31
30
|
export * from './base/feedback/feedback-command';
|
|
32
31
|
export * from './base/feedback/feedback-emitter';
|
|
33
32
|
export * from './base/feedback/set-model-command';
|
|
@@ -145,7 +144,6 @@ export * from './features/grid/grid-snapper';
|
|
|
145
144
|
export * from './features/grid/grid-style';
|
|
146
145
|
export * from './features/helper-lines/helper-line-feedback';
|
|
147
146
|
export * from './features/helper-lines/helper-line-manager';
|
|
148
|
-
export * from './features/helper-lines/helper-line-manager-default';
|
|
149
147
|
export * from './features/helper-lines/helper-line-module';
|
|
150
148
|
export * from './features/helper-lines/model';
|
|
151
149
|
export * from './features/helper-lines/view';
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/********************************************************************************
|
|
2
|
-
* Copyright (c) 2019-2024 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
|
-
import { Action, ActionHandlerRegistry, Command, CommandExecutionContext, Disposable, IActionDispatcher, ICommand, ILogger } from '@eclipse-glsp/sprotty';
|
|
17
|
-
import { IFeedbackActionDispatcher, IFeedbackEmitter, MaybeActions } from './feedback-action-dispatcher';
|
|
18
|
-
import { FeedbackEmitter } from './feedback-emitter';
|
|
19
|
-
export declare class FeedbackActionDispatcher implements IFeedbackActionDispatcher, Disposable {
|
|
20
|
-
protected registeredFeedback: Map<IFeedbackEmitter, Action[]>;
|
|
21
|
-
protected actionDispatcher: IActionDispatcher;
|
|
22
|
-
protected logger: ILogger;
|
|
23
|
-
protected actionHandlerRegistry: ActionHandlerRegistry;
|
|
24
|
-
protected isDisposed: boolean;
|
|
25
|
-
registerFeedback(feedbackEmitter: IFeedbackEmitter, feedbackActions: Action[], cleanupActions?: MaybeActions): Disposable;
|
|
26
|
-
deregisterFeedback(feedbackEmitter: IFeedbackEmitter, cleanupActions?: MaybeActions): void;
|
|
27
|
-
getRegisteredFeedback(): Action[];
|
|
28
|
-
getRegisteredFeedbackEmitters(action: Action): IFeedbackEmitter[];
|
|
29
|
-
getFeedbackCommands(): Command[];
|
|
30
|
-
applyFeedbackCommands(context: CommandExecutionContext): Promise<void>;
|
|
31
|
-
protected actionToCommands(action: Action): ICommand[];
|
|
32
|
-
createEmitter(): FeedbackEmitter;
|
|
33
|
-
protected dispatchFeedback(actions: Action[], feedbackEmitter: IFeedbackEmitter): Promise<void>;
|
|
34
|
-
dispose(): void;
|
|
35
|
-
}
|
|
36
|
-
//# sourceMappingURL=feedback-action-dispatcher-default.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"feedback-action-dispatcher-default.d.ts","sourceRoot":"","sources":["../../../src/base/feedback/feedback-action-dispatcher-default.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;kFAckF;AAClF,OAAO,EACH,MAAM,EACN,qBAAqB,EACrB,OAAO,EAEP,uBAAuB,EACvB,UAAU,EAEV,iBAAiB,EACjB,QAAQ,EACR,OAAO,EAGV,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAEzG,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,qBACa,wBAAyB,YAAW,yBAAyB,EAAE,UAAU;IAClF,SAAS,CAAC,kBAAkB,EAAE,GAAG,CAAC,gBAAgB,EAAE,MAAM,EAAE,CAAC,CAAa;IAEzC,SAAS,CAAC,gBAAgB,EAAE,iBAAiB,CAAC;IAExD,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC;IAElB,SAAS,CAAC,qBAAqB,EAAE,qBAAqB,CAAC;IAEtF,SAAS,CAAC,UAAU,UAAS;IAE7B,gBAAgB,CAAC,eAAe,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,EAAE,EAAE,cAAc,CAAC,EAAE,YAAY,GAAG,UAAU;IAezH,kBAAkB,CAAC,eAAe,EAAE,gBAAgB,EAAE,cAAc,CAAC,EAAE,YAAY,GAAG,IAAI;IAQ1F,qBAAqB,IAAI,MAAM,EAAE;IAMjC,6BAA6B,CAAC,MAAM,EAAE,MAAM,GAAG,gBAAgB,EAAE;IAUjE,mBAAmB,IAAI,OAAO,EAAE;IAM1B,qBAAqB,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ5E,SAAS,CAAC,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,EAAE;IAStD,aAAa,IAAI,eAAe;cAIhB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,eAAe,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAarG,OAAO,IAAI,IAAI;CAIlB"}
|