@eclipse-glsp/client 2.1.0-next.304 → 2.1.0-next.306
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/selection-service.d.ts +1 -1
- package/lib/base/selection-service.d.ts.map +1 -1
- package/lib/base/selection-service.js +15 -20
- package/lib/base/selection-service.js.map +1 -1
- package/lib/base/selection-service.spec.js +9 -7
- package/lib/base/selection-service.spec.js.map +1 -1
- package/lib/features/change-bounds/position-snapper.js +4 -4
- package/lib/features/change-bounds/position-snapper.js.map +1 -1
- package/lib/features/helper-lines/helper-line-feedback.d.ts +30 -11
- package/lib/features/helper-lines/helper-line-feedback.d.ts.map +1 -1
- package/lib/features/helper-lines/helper-line-feedback.js +93 -32
- package/lib/features/helper-lines/helper-line-feedback.js.map +1 -1
- package/lib/features/helper-lines/helper-line-manager-default.d.ts +42 -11
- package/lib/features/helper-lines/helper-line-manager-default.d.ts.map +1 -1
- package/lib/features/helper-lines/helper-line-manager-default.js +21 -16
- package/lib/features/helper-lines/helper-line-manager-default.js.map +1 -1
- package/lib/features/helper-lines/helper-line-manager.d.ts +8 -1
- package/lib/features/helper-lines/helper-line-manager.d.ts.map +1 -1
- package/lib/features/tools/change-bounds/change-bounds-tool-feedback.js +1 -1
- package/lib/features/tools/change-bounds/change-bounds-tool-feedback.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/utils/gmodel-util.d.ts +1 -0
- package/lib/utils/gmodel-util.d.ts.map +1 -1
- package/lib/utils/gmodel-util.js +10 -1
- package/lib/utils/gmodel-util.js.map +1 -1
- package/package.json +3 -3
- package/src/base/selection-service.spec.ts +9 -7
- package/src/base/selection-service.ts +17 -21
- package/src/features/change-bounds/position-snapper.ts +4 -4
- package/src/features/helper-lines/helper-line-feedback.ts +127 -45
- package/src/features/helper-lines/helper-line-manager-default.ts +68 -20
- package/src/features/helper-lines/helper-line-manager.ts +8 -1
- package/src/features/tools/change-bounds/change-bounds-tool-feedback.ts +1 -1
- package/src/utils/gmodel-util.ts +12 -0
|
@@ -19,8 +19,8 @@ import {
|
|
|
19
19
|
GModelElement,
|
|
20
20
|
GModelRoot,
|
|
21
21
|
IActionHandler,
|
|
22
|
-
ISnapper,
|
|
23
22
|
MoveAction,
|
|
23
|
+
Point,
|
|
24
24
|
SetBoundsAction,
|
|
25
25
|
TYPES
|
|
26
26
|
} from '@eclipse-glsp/sprotty';
|
|
@@ -28,33 +28,81 @@ import { inject, injectable, optional, postConstruct } from 'inversify';
|
|
|
28
28
|
import { IFeedbackActionDispatcher } from '../../base/feedback/feedback-action-dispatcher';
|
|
29
29
|
import { ISelectionListener, SelectionService } from '../../base/selection-service';
|
|
30
30
|
import { SetBoundsFeedbackAction } from '../bounds/set-bounds-feedback-command';
|
|
31
|
-
import { GridSnapper } from '../change-bounds/snap';
|
|
32
31
|
import { MoveFinishedEventAction, MoveInitializedEventAction } from '../tools/change-bounds/change-bounds-tool-feedback';
|
|
33
|
-
import {
|
|
32
|
+
import {
|
|
33
|
+
AlignmentElementFilter,
|
|
34
|
+
DEFAULT_ALIGNABLE_ELEMENT_FILTER,
|
|
35
|
+
DEFAULT_DEBUG,
|
|
36
|
+
DEFAULT_ELEMENT_LINES,
|
|
37
|
+
DEFAULT_EPSILON,
|
|
38
|
+
DEFAULT_VIEWPORT_LINES,
|
|
39
|
+
DrawHelperLinesFeedbackAction,
|
|
40
|
+
RemoveHelperLinesFeedbackAction,
|
|
41
|
+
ViewportLineType
|
|
42
|
+
} from './helper-line-feedback';
|
|
34
43
|
import { IHelperLineManager } from './helper-line-manager';
|
|
35
44
|
import { Direction, HelperLineType } from './model';
|
|
36
45
|
|
|
46
|
+
export interface IHelperLineOptions {
|
|
47
|
+
/**
|
|
48
|
+
* A list of helper line types that should be rendered when elements are aligned.
|
|
49
|
+
* Defaults to all possible alignments.
|
|
50
|
+
*/
|
|
51
|
+
elementLines?: HelperLineType[];
|
|
52
|
+
/**
|
|
53
|
+
* A list of helper line types that should be rendered when an element is aligned with the viewport.
|
|
54
|
+
* Defaults to middle and center alignment.
|
|
55
|
+
*/
|
|
56
|
+
viewportLines?: ViewportLineType[];
|
|
57
|
+
/**
|
|
58
|
+
* The minimum difference between two coordinates
|
|
59
|
+
* Defaults to 1.
|
|
60
|
+
*/
|
|
61
|
+
alignmentEpsilon?: number;
|
|
62
|
+
/**
|
|
63
|
+
* A filter that is applied to determine on which elements the alignment calculation is performed.
|
|
64
|
+
* By default all top-level bounds-aware, non-routable elements that are visible on the canvas are considered.
|
|
65
|
+
*/
|
|
66
|
+
alignmentElementFilter?: AlignmentElementFilter;
|
|
67
|
+
/**
|
|
68
|
+
* The minimum move delta that is necessary for an element to break through a helper line.
|
|
69
|
+
* Defaults to { x: 1, y: 1 } whereas the x represents the horizontal distance and y represents the vertical distance.
|
|
70
|
+
*/
|
|
71
|
+
minimumMoveDelta?: Point;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Produces debug output.
|
|
75
|
+
* Defaults to false.
|
|
76
|
+
*/
|
|
77
|
+
debug?: boolean;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export const DEFAULT_MOVE_DELTA = { x: 1, y: 1 };
|
|
81
|
+
|
|
82
|
+
export const DEFAULT_HELPER_LINE_OPTIONS: Required<IHelperLineOptions> = {
|
|
83
|
+
elementLines: DEFAULT_ELEMENT_LINES,
|
|
84
|
+
viewportLines: DEFAULT_VIEWPORT_LINES,
|
|
85
|
+
alignmentEpsilon: DEFAULT_EPSILON,
|
|
86
|
+
alignmentElementFilter: DEFAULT_ALIGNABLE_ELEMENT_FILTER,
|
|
87
|
+
minimumMoveDelta: DEFAULT_MOVE_DELTA,
|
|
88
|
+
debug: DEFAULT_DEBUG
|
|
89
|
+
};
|
|
90
|
+
|
|
37
91
|
@injectable()
|
|
38
92
|
export class HelperLineManager implements IActionHandler, ISelectionListener, IHelperLineManager {
|
|
39
93
|
@inject(TYPES.IFeedbackActionDispatcher) protected feedbackDispatcher: IFeedbackActionDispatcher;
|
|
40
94
|
@inject(SelectionService) protected selectionService: SelectionService;
|
|
41
|
-
@optional() @inject(TYPES.
|
|
95
|
+
@optional() @inject(TYPES.IHelperLineOptions) protected userOptions?: IHelperLineOptions;
|
|
42
96
|
|
|
43
|
-
protected
|
|
97
|
+
protected options: Required<IHelperLineOptions>;
|
|
44
98
|
protected feedback: DisposableCollection = new DisposableCollection();
|
|
45
99
|
|
|
46
|
-
protected elementLines?: HelperLineType[];
|
|
47
|
-
protected viewportLines?: ViewportLineType[];
|
|
48
|
-
protected alignmentEpsilon?: number;
|
|
49
|
-
|
|
50
100
|
@postConstruct()
|
|
51
101
|
protected init(): void {
|
|
102
|
+
this.options = { ...DEFAULT_HELPER_LINE_OPTIONS, ...this.userOptions };
|
|
52
103
|
this.selectionService.onSelectionChanged(change =>
|
|
53
104
|
this.selectionChanged(change.root, change.selectedElements, change.deselectedElements)
|
|
54
105
|
);
|
|
55
|
-
if (this.snapper instanceof GridSnapper) {
|
|
56
|
-
this.snapSize = { x: this.snapper.grid.x * 2, y: this.snapper.grid.y * 2 };
|
|
57
|
-
}
|
|
58
106
|
}
|
|
59
107
|
|
|
60
108
|
handle(action: Action): void {
|
|
@@ -90,12 +138,7 @@ export class HelperLineManager implements IActionHandler, ISelectionListener, IH
|
|
|
90
138
|
}
|
|
91
139
|
|
|
92
140
|
protected createHelperLineFeedback(elementIds: string[]): DrawHelperLinesFeedbackAction {
|
|
93
|
-
return DrawHelperLinesFeedbackAction.create({
|
|
94
|
-
elementIds,
|
|
95
|
-
elementLines: this.elementLines,
|
|
96
|
-
viewportLines: this.viewportLines,
|
|
97
|
-
alignmentEpsilon: this.alignmentEpsilon
|
|
98
|
-
});
|
|
141
|
+
return DrawHelperLinesFeedbackAction.create({ elementIds, ...this.options });
|
|
99
142
|
}
|
|
100
143
|
|
|
101
144
|
protected handleSetBoundsAction(action: SetBoundsAction | SetBoundsFeedbackAction): void {
|
|
@@ -108,7 +151,12 @@ export class HelperLineManager implements IActionHandler, ISelectionListener, IH
|
|
|
108
151
|
this.feedback.dispose();
|
|
109
152
|
}
|
|
110
153
|
|
|
111
|
-
|
|
112
|
-
|
|
154
|
+
getMinimumMoveDelta(element: GModelElement, isSnap: boolean, direction: Direction): number {
|
|
155
|
+
if (!isSnap) {
|
|
156
|
+
return 0;
|
|
157
|
+
}
|
|
158
|
+
return direction === Direction.Left || direction === Direction.Right
|
|
159
|
+
? this.options.minimumMoveDelta.x
|
|
160
|
+
: this.options.minimumMoveDelta.y;
|
|
113
161
|
}
|
|
114
162
|
}
|
|
@@ -17,5 +17,12 @@ import { GModelElement } from '@eclipse-glsp/sprotty';
|
|
|
17
17
|
import { Direction } from './model';
|
|
18
18
|
|
|
19
19
|
export interface IHelperLineManager {
|
|
20
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Calculates the minimum move delta that is necessary to break through a helper line.
|
|
22
|
+
*
|
|
23
|
+
* @param element element that is being moved
|
|
24
|
+
* @param isSnap whether snapping is active or not
|
|
25
|
+
* @param direction direction in which the target element is moving
|
|
26
|
+
*/
|
|
27
|
+
getMinimumMoveDelta(element: GModelElement, isSnap: boolean, direction: Direction): number;
|
|
21
28
|
}
|
|
@@ -195,13 +195,13 @@ export class FeedbackMoveMouseListener extends DragAwareMouseListener implements
|
|
|
195
195
|
if (event.buttons === 0) {
|
|
196
196
|
this.mouseUp(target, event);
|
|
197
197
|
} else if (!this.positionUpdater.isLastDragPositionUndefined()) {
|
|
198
|
-
this.pendingMoveInitialized?.cancel();
|
|
199
198
|
if (this.elementId2startPos.size === 0) {
|
|
200
199
|
this.collectStartPositions(target.root);
|
|
201
200
|
}
|
|
202
201
|
this._isMouseDrag = true;
|
|
203
202
|
const moveAction = this.getElementMoves(target, event, false);
|
|
204
203
|
if (moveAction) {
|
|
204
|
+
this.pendingMoveInitialized?.cancel();
|
|
205
205
|
result.push(moveAction);
|
|
206
206
|
result.push(cursorFeedbackAction(CursorCSS.MOVE));
|
|
207
207
|
this.tool.registerFeedback(result, this);
|
package/src/utils/gmodel-util.ts
CHANGED
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
TypeGuard,
|
|
32
32
|
distinctAdd,
|
|
33
33
|
findParentByFeature,
|
|
34
|
+
getAbsoluteBounds,
|
|
34
35
|
isBoundsAware,
|
|
35
36
|
isMoveable,
|
|
36
37
|
isSelectable,
|
|
@@ -350,3 +351,14 @@ export function calculateDeltaBetweenPoints(target: Point, source: Point, elemen
|
|
|
350
351
|
const adaptedDelta = { x: delta.x / zoom, y: delta.y / zoom };
|
|
351
352
|
return adaptedDelta;
|
|
352
353
|
}
|
|
354
|
+
|
|
355
|
+
export function isVisibleOnCanvas(model: BoundsAwareModelElement): boolean {
|
|
356
|
+
const modelBounds = getAbsoluteBounds(model);
|
|
357
|
+
const canvasBounds = model.root.canvasBounds;
|
|
358
|
+
return (
|
|
359
|
+
modelBounds.x <= canvasBounds.width &&
|
|
360
|
+
modelBounds.x + modelBounds.width >= 0 &&
|
|
361
|
+
modelBounds.y <= canvasBounds.height &&
|
|
362
|
+
modelBounds.y + modelBounds.height >= 0
|
|
363
|
+
);
|
|
364
|
+
}
|