@eclipse-glsp/client 2.5.0-next.427 → 2.5.0-next.429

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 (44) hide show
  1. package/lib/base/command-stack.d.ts +6 -4
  2. package/lib/base/command-stack.d.ts.map +1 -1
  3. package/lib/base/command-stack.js +16 -7
  4. package/lib/base/command-stack.js.map +1 -1
  5. package/lib/base/default.module.d.ts.map +1 -1
  6. package/lib/base/default.module.js +2 -0
  7. package/lib/base/default.module.js.map +1 -1
  8. package/lib/base/editor-context-service.d.ts +9 -12
  9. package/lib/base/editor-context-service.d.ts.map +1 -1
  10. package/lib/base/editor-context-service.js +22 -26
  11. package/lib/base/editor-context-service.js.map +1 -1
  12. package/lib/base/focus/focus-tracker.d.ts +3 -2
  13. package/lib/base/focus/focus-tracker.d.ts.map +1 -1
  14. package/lib/base/focus/focus-tracker.js +9 -0
  15. package/lib/base/focus/focus-tracker.js.map +1 -1
  16. package/lib/base/model/model-change-service.d.ts +65 -0
  17. package/lib/base/model/model-change-service.d.ts.map +1 -0
  18. package/lib/base/model/model-change-service.js +113 -0
  19. package/lib/base/model/model-change-service.js.map +1 -0
  20. package/lib/default-modules.d.ts.map +1 -1
  21. package/lib/default-modules.js +2 -1
  22. package/lib/default-modules.js.map +1 -1
  23. package/lib/features/zorder/bring-to-front-command.d.ts +23 -0
  24. package/lib/features/zorder/bring-to-front-command.d.ts.map +1 -0
  25. package/lib/features/zorder/bring-to-front-command.js +54 -0
  26. package/lib/features/zorder/bring-to-front-command.js.map +1 -0
  27. package/lib/features/zorder/zorder-module.d.ts +18 -0
  28. package/lib/features/zorder/zorder-module.d.ts.map +1 -0
  29. package/lib/features/zorder/zorder-module.js +26 -0
  30. package/lib/features/zorder/zorder-module.js.map +1 -0
  31. package/lib/index.d.ts +2 -0
  32. package/lib/index.d.ts.map +1 -1
  33. package/lib/index.js +2 -0
  34. package/lib/index.js.map +1 -1
  35. package/package.json +3 -3
  36. package/src/base/command-stack.ts +19 -13
  37. package/src/base/default.module.ts +2 -0
  38. package/src/base/editor-context-service.ts +22 -29
  39. package/src/base/focus/focus-tracker.ts +8 -3
  40. package/src/base/model/model-change-service.ts +151 -0
  41. package/src/default-modules.ts +2 -2
  42. package/src/features/zorder/bring-to-front-command.ts +46 -0
  43. package/src/features/zorder/zorder-module.ts +26 -0
  44. package/src/index.ts +2 -0
@@ -0,0 +1,151 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2025 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 {
17
+ BoundsAwareViewportCommand,
18
+ Disposable,
19
+ DisposableCollection,
20
+ Emitter,
21
+ Event,
22
+ GModelRoot,
23
+ ICommand,
24
+ ICommandStack,
25
+ LazyInjector,
26
+ SetModelCommand,
27
+ SetViewportCommand,
28
+ TYPES,
29
+ UpdateModelCommand,
30
+ Viewport,
31
+ almostEquals,
32
+ isViewport
33
+ } from '@eclipse-glsp/sprotty';
34
+ import { inject, postConstruct, preDestroy } from 'inversify';
35
+
36
+ /**
37
+ * Service that tracks changes to the model root and the viewport.
38
+ * Allows to register listeners that are notified when the model root or the viewport changes.
39
+ * The current model root can be queried at any time.
40
+ */
41
+ export interface IModelChangeService {
42
+ /** The current model root */
43
+ readonly currentRoot: Readonly<GModelRoot> | undefined;
44
+ /**
45
+ * Event that is fired when the model root of the diagram changes i.e. after the `CommandStack` has processed a model update.
46
+ */
47
+ onModelRootChanged: Event<Readonly<GModelRoot>>;
48
+
49
+ /**
50
+ * Event that is fired when the viewport of the diagram changes i.e. after the `CommandStack` has processed a viewport update.
51
+ * By default, this event is only fired if the viewport was changed via a `SetViewportCommand` or `BoundsAwareViewportCommand`
52
+ */
53
+ onViewportChanged: Event<ViewportChange>;
54
+ }
55
+
56
+ /**
57
+ * Event data for the {@link IModelChangeService.onViewportChanged} event.
58
+ */
59
+ export interface ViewportChange {
60
+ /** The new viewport */
61
+ newViewport: Readonly<Viewport>;
62
+ /** The old viewport */
63
+ oldViewport?: Readonly<Viewport>;
64
+ }
65
+
66
+ export class ModelChangeService implements IModelChangeService, Disposable {
67
+ @inject(LazyInjector)
68
+ protected lazyInjector: LazyInjector;
69
+ protected _currentRoot?: Readonly<GModelRoot>;
70
+ protected lastViewport?: Readonly<Viewport>;
71
+ protected toDispose = new DisposableCollection();
72
+
73
+ get currentRoot(): Readonly<GModelRoot> | undefined {
74
+ return this._currentRoot;
75
+ }
76
+
77
+ protected get commandStack(): ICommandStack {
78
+ return this.lazyInjector.get<ICommandStack>(TYPES.ICommandStack);
79
+ }
80
+
81
+ protected onModelRootChangedEmitter = new Emitter<Readonly<GModelRoot>>();
82
+ get onModelRootChanged(): Event<Readonly<GModelRoot>> {
83
+ return this.onModelRootChangedEmitter.event;
84
+ }
85
+
86
+ protected onViewportChangedEmitter = new Emitter<ViewportChange>();
87
+ get onViewportChanged(): Event<ViewportChange> {
88
+ return this.onViewportChangedEmitter.event;
89
+ }
90
+
91
+ @postConstruct()
92
+ protected initialize(): void {
93
+ this.toDispose.push(this.onModelRootChangedEmitter, this.onViewportChangedEmitter);
94
+ this.commandStack.onCommandExecuted(data => this.handleCommandExecution(data.command, data.newRoot));
95
+ }
96
+
97
+ @preDestroy()
98
+ dispose(): void {
99
+ this.toDispose.dispose();
100
+ }
101
+
102
+ protected handleCommandExecution(command: ICommand, newRoot: GModelRoot): void {
103
+ if (this.isModelRootChangeCommand(command)) {
104
+ this.handleModelRootChangeCommand(command, newRoot);
105
+ }
106
+ if (this.isViewportChangeCommand(command)) {
107
+ this.handleViewportChangeCommand(command, newRoot);
108
+ }
109
+ }
110
+
111
+ protected isModelRootChangeCommand(command: ICommand): boolean {
112
+ return command instanceof SetModelCommand || command instanceof UpdateModelCommand;
113
+ }
114
+
115
+ protected isViewportChangeCommand(command: ICommand): boolean {
116
+ return command instanceof SetViewportCommand || command instanceof BoundsAwareViewportCommand;
117
+ }
118
+
119
+ protected handleModelRootChangeCommand(command: ICommand, newRoot: GModelRoot): void {
120
+ this._currentRoot = newRoot;
121
+ this.lastViewport = this.toViewport(newRoot);
122
+ this.onModelRootChangedEmitter.fire(newRoot);
123
+ }
124
+
125
+ protected handleViewportChangeCommand(command: ICommand, newRoot: GModelRoot): void {
126
+ const viewport = this.toViewport(newRoot);
127
+ if (!viewport) {
128
+ return;
129
+ }
130
+
131
+ if (this.hasViewportChanged(viewport)) {
132
+ this.onViewportChangedEmitter.fire({ newViewport: viewport, oldViewport: this.lastViewport });
133
+ this.lastViewport = viewport;
134
+ }
135
+ }
136
+
137
+ protected hasViewportChanged(newViewport: Readonly<Viewport>): boolean {
138
+ if (!this.lastViewport) {
139
+ return true;
140
+ }
141
+ return !(
142
+ almostEquals(newViewport.zoom, this.lastViewport.zoom) &&
143
+ almostEquals(newViewport.scroll.x, this.lastViewport.scroll.x) &&
144
+ almostEquals(newViewport.scroll.y, this.lastViewport.scroll.y)
145
+ );
146
+ }
147
+
148
+ protected toViewport(root: Readonly<GModelRoot>): Readonly<Viewport> | undefined {
149
+ return isViewport(root) ? { scroll: root.scroll, zoom: root.zoom } : undefined;
150
+ }
151
+ }
@@ -27,8 +27,7 @@ import {
27
27
  expandModule,
28
28
  fadeModule,
29
29
  modelSourceModule,
30
- resolveContainerConfiguration,
31
- zorderModule
30
+ resolveContainerConfiguration
32
31
  } from '@eclipse-glsp/sprotty';
33
32
  import { Container } from 'inversify';
34
33
  import { defaultModule } from './base/default.module';
@@ -62,6 +61,7 @@ import { nodeCreationToolModule } from './features/tools/node-creation/node-crea
62
61
  import { toolFocusLossModule } from './features/tools/tool-focus-loss-module';
63
62
  import { markerNavigatorModule, validationModule } from './features/validation/validation-modules';
64
63
  import { viewportModule } from './features/viewport/viewport-modules';
64
+ import { zorderModule } from './features/zorder/zorder-module';
65
65
 
66
66
  export const DEFAULT_MODULES = [
67
67
  defaultModule,
@@ -0,0 +1,46 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2025 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 {
18
+ LayoutContainer,
19
+ LayoutRegistry,
20
+ SprottyBringToFrontCommand,
21
+ TYPES,
22
+ ZOrderElement,
23
+ isLayoutContainer
24
+ } from '@eclipse-glsp/sprotty';
25
+ import { inject, injectable } from 'inversify';
26
+
27
+ @injectable()
28
+ export class BringToFrontCommand extends SprottyBringToFrontCommand {
29
+ @inject(TYPES.LayoutRegistry) protected layoutRegistry: LayoutRegistry;
30
+
31
+ protected getLayoutContainer(zorder: ZOrderElement): LayoutContainer | undefined {
32
+ return isLayoutContainer(zorder.element.parent) ? zorder.element.parent : undefined;
33
+ }
34
+
35
+ protected shouldBringToFront(zorder: ZOrderElement): boolean {
36
+ // only re-order children if the layout supports it
37
+ const layoutContainer = this.getLayoutContainer(zorder);
38
+ return !layoutContainer || (this.layoutRegistry.get(layoutContainer.layout)?.orderAgnostic ?? true);
39
+ }
40
+
41
+ protected override bringToFront(zorder: ZOrderElement): void {
42
+ if (this.shouldBringToFront(zorder)) {
43
+ super.bringToFront(zorder);
44
+ }
45
+ }
46
+ }
@@ -0,0 +1,26 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2025 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 { FeatureModule, configureCommand } from '@eclipse-glsp/sprotty';
17
+ import { boundsModule } from '../bounds/bounds-module';
18
+ import { BringToFrontCommand } from './bring-to-front-command';
19
+
20
+ export const zorderModule = new FeatureModule(
21
+ (bind, _unbind, isBound) => {
22
+ const context = { bind, isBound };
23
+ configureCommand(context, BringToFrontCommand);
24
+ },
25
+ { featureId: Symbol('zorder'), requires: [boundsModule] }
26
+ );
package/src/index.ts CHANGED
@@ -226,6 +226,8 @@ export * from './features/viewport/viewport-key-listener';
226
226
  export * from './features/viewport/viewport-modules';
227
227
  export * from './features/viewport/viewport-tool';
228
228
  export * from './features/viewport/zoom-viewport-action';
229
+ export * from './features/zorder/bring-to-front-command';
230
+ export * from './features/zorder/zorder-module';
229
231
  export * from './model';
230
232
  export * from './re-exports';
231
233
  export * from './standalone-modules';