@eclipse-glsp/client 2.1.0-next.295 → 2.1.0-next.296

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 (110) hide show
  1. package/css/ghost-element.css +25 -0
  2. package/css/glsp-sprotty.css +5 -0
  3. package/lib/base/args-feature.d.ts +2 -1
  4. package/lib/base/args-feature.d.ts.map +1 -1
  5. package/lib/base/args-feature.js +12 -2
  6. package/lib/base/args-feature.js.map +1 -1
  7. package/lib/base/feedback/css-feedback.d.ts +17 -0
  8. package/lib/base/feedback/css-feedback.d.ts.map +1 -1
  9. package/lib/base/feedback/css-feedback.js +4 -2
  10. package/lib/base/feedback/css-feedback.js.map +1 -1
  11. package/lib/default-modules.d.ts +1 -1
  12. package/lib/default-modules.d.ts.map +1 -1
  13. package/lib/default-modules.js +2 -0
  14. package/lib/default-modules.js.map +1 -1
  15. package/lib/features/accessibility/keyboard-tool-palette/keyboard-tool-palette-module.d.ts.map +1 -1
  16. package/lib/features/accessibility/keyboard-tool-palette/keyboard-tool-palette-module.js +4 -2
  17. package/lib/features/accessibility/keyboard-tool-palette/keyboard-tool-palette-module.js.map +1 -1
  18. package/lib/features/accessibility/keyboard-tool-palette/keyboard-tool-palette.d.ts +16 -1
  19. package/lib/features/accessibility/keyboard-tool-palette/keyboard-tool-palette.d.ts.map +1 -1
  20. package/lib/features/accessibility/keyboard-tool-palette/keyboard-tool-palette.js +9 -10
  21. package/lib/features/accessibility/keyboard-tool-palette/keyboard-tool-palette.js.map +1 -1
  22. package/lib/features/bounds/bounds-module.d.ts.map +1 -1
  23. package/lib/features/bounds/bounds-module.js +4 -0
  24. package/lib/features/bounds/bounds-module.js.map +1 -1
  25. package/lib/features/bounds/glsp-hidden-bounds-updater.d.ts +2 -2
  26. package/lib/features/bounds/glsp-hidden-bounds-updater.d.ts.map +1 -1
  27. package/lib/features/bounds/glsp-hidden-bounds-updater.js +7 -3
  28. package/lib/features/bounds/glsp-hidden-bounds-updater.js.map +1 -1
  29. package/lib/features/bounds/local-bounds.d.ts +34 -0
  30. package/lib/features/bounds/local-bounds.d.ts.map +1 -0
  31. package/lib/features/bounds/local-bounds.js +99 -0
  32. package/lib/features/bounds/local-bounds.js.map +1 -0
  33. package/lib/features/bounds/set-bounds-feedback-command.d.ts +33 -0
  34. package/lib/features/bounds/set-bounds-feedback-command.d.ts.map +1 -0
  35. package/lib/features/bounds/set-bounds-feedback-command.js +74 -0
  36. package/lib/features/bounds/set-bounds-feedback-command.js.map +1 -0
  37. package/lib/features/change-bounds/model.d.ts +1 -1
  38. package/lib/features/change-bounds/model.d.ts.map +1 -1
  39. package/lib/features/change-bounds/model.js +0 -1
  40. package/lib/features/change-bounds/model.js.map +1 -1
  41. package/lib/features/decoration/decoration-placer.d.ts +16 -1
  42. package/lib/features/decoration/decoration-placer.d.ts.map +1 -1
  43. package/lib/features/decoration/decoration-placer.js +3 -3
  44. package/lib/features/decoration/decoration-placer.js.map +1 -1
  45. package/lib/features/element-template/add-template-element.d.ts +39 -0
  46. package/lib/features/element-template/add-template-element.d.ts.map +1 -0
  47. package/lib/features/element-template/add-template-element.js +107 -0
  48. package/lib/features/element-template/add-template-element.js.map +1 -0
  49. package/lib/features/element-template/element-template-module.d.ts +18 -0
  50. package/lib/features/element-template/element-template-module.d.ts.map +1 -0
  51. package/lib/features/element-template/element-template-module.js +27 -0
  52. package/lib/features/element-template/element-template-module.js.map +1 -0
  53. package/lib/features/element-template/mouse-tracking-element-position-listener.d.ts +38 -0
  54. package/lib/features/element-template/mouse-tracking-element-position-listener.d.ts.map +1 -0
  55. package/lib/features/element-template/mouse-tracking-element-position-listener.js +102 -0
  56. package/lib/features/element-template/mouse-tracking-element-position-listener.js.map +1 -0
  57. package/lib/features/element-template/remove-template-element.d.ts +32 -0
  58. package/lib/features/element-template/remove-template-element.d.ts.map +1 -0
  59. package/lib/features/element-template/remove-template-element.js +66 -0
  60. package/lib/features/element-template/remove-template-element.js.map +1 -0
  61. package/lib/features/tool-palette/tool-palette-module.d.ts.map +1 -1
  62. package/lib/features/tool-palette/tool-palette-module.js +2 -0
  63. package/lib/features/tool-palette/tool-palette-module.js.map +1 -1
  64. package/lib/features/tool-palette/tool-palette.d.ts +22 -4
  65. package/lib/features/tool-palette/tool-palette.d.ts.map +1 -1
  66. package/lib/features/tool-palette/tool-palette.js +35 -11
  67. package/lib/features/tool-palette/tool-palette.js.map +1 -1
  68. package/lib/features/tools/change-bounds/change-bounds-tool.d.ts +1 -1
  69. package/lib/features/tools/change-bounds/change-bounds-tool.d.ts.map +1 -1
  70. package/lib/features/tools/change-bounds/change-bounds-tool.js +6 -5
  71. package/lib/features/tools/change-bounds/change-bounds-tool.js.map +1 -1
  72. package/lib/features/tools/change-bounds/view.d.ts +16 -1
  73. package/lib/features/tools/change-bounds/view.d.ts.map +1 -1
  74. package/lib/features/tools/change-bounds/view.js +1 -1
  75. package/lib/features/tools/change-bounds/view.js.map +1 -1
  76. package/lib/features/tools/node-creation/node-creation-module.d.ts.map +1 -1
  77. package/lib/features/tools/node-creation/node-creation-module.js +2 -1
  78. package/lib/features/tools/node-creation/node-creation-module.js.map +1 -1
  79. package/lib/features/tools/node-creation/node-creation-tool.d.ts +24 -3
  80. package/lib/features/tools/node-creation/node-creation-tool.d.ts.map +1 -1
  81. package/lib/features/tools/node-creation/node-creation-tool.js +41 -11
  82. package/lib/features/tools/node-creation/node-creation-tool.js.map +1 -1
  83. package/lib/index.d.ts +4 -0
  84. package/lib/index.d.ts.map +1 -1
  85. package/lib/index.js +4 -0
  86. package/lib/index.js.map +1 -1
  87. package/lib/tsconfig.tsbuildinfo +1 -1
  88. package/package.json +3 -3
  89. package/src/base/args-feature.ts +12 -2
  90. package/src/base/feedback/css-feedback.ts +4 -1
  91. package/src/default-modules.ts +2 -0
  92. package/src/features/accessibility/keyboard-tool-palette/keyboard-tool-palette-module.ts +13 -3
  93. package/src/features/accessibility/keyboard-tool-palette/keyboard-tool-palette.ts +15 -16
  94. package/src/features/bounds/bounds-module.ts +6 -0
  95. package/src/features/bounds/glsp-hidden-bounds-updater.ts +11 -7
  96. package/src/features/bounds/local-bounds.ts +91 -0
  97. package/src/features/bounds/set-bounds-feedback-command.ts +70 -0
  98. package/src/features/change-bounds/model.ts +2 -3
  99. package/src/features/decoration/decoration-placer.ts +3 -3
  100. package/src/features/element-template/add-template-element.ts +109 -0
  101. package/src/features/element-template/element-template-module.ts +24 -0
  102. package/src/features/element-template/mouse-tracking-element-position-listener.ts +110 -0
  103. package/src/features/element-template/remove-template-element.ts +56 -0
  104. package/src/features/tool-palette/tool-palette-module.ts +3 -1
  105. package/src/features/tool-palette/tool-palette.ts +42 -14
  106. package/src/features/tools/change-bounds/change-bounds-tool.ts +12 -10
  107. package/src/features/tools/change-bounds/view.tsx +1 -1
  108. package/src/features/tools/node-creation/node-creation-module.ts +9 -5
  109. package/src/features/tools/node-creation/node-creation-tool.ts +51 -13
  110. package/src/index.ts +4 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eclipse-glsp/client",
3
- "version": "2.1.0-next.295+0c22eb6",
3
+ "version": "2.1.0-next.296+545a20c",
4
4
  "description": "A sprotty-based client for GLSP",
5
5
  "keywords": [
6
6
  "eclipse",
@@ -47,7 +47,7 @@
47
47
  "watch": "tsc -w"
48
48
  },
49
49
  "dependencies": {
50
- "@eclipse-glsp/sprotty": "2.1.0-next.295+0c22eb6",
50
+ "@eclipse-glsp/sprotty": "2.1.0-next.296+545a20c",
51
51
  "autocompleter": "^9.1.0",
52
52
  "file-saver": "^2.0.5",
53
53
  "lodash": "4.17.21"
@@ -59,5 +59,5 @@
59
59
  "publishConfig": {
60
60
  "access": "public"
61
61
  },
62
- "gitHead": "0c22eb65d1e79fca017703f1238ef39bc33c06b9"
62
+ "gitHead": "545a20ca017d2efdf7bfc15fddea7f89197916c5"
63
63
  }
@@ -28,10 +28,20 @@ export interface ArgsAware {
28
28
  args?: Args;
29
29
  }
30
30
 
31
- export function isArgsAware(element: GModelElement): element is GModelElement & ArgsAware {
32
- return element.hasFeature(argsFeature);
31
+ export function isArgsAware(element?: GModelElement): element is GModelElement & ArgsAware {
32
+ return element !== undefined && element.hasFeature(argsFeature);
33
33
  }
34
34
 
35
35
  export function hasArgs(element?: GModelElement): element is GModelElement & Required<ArgsAware> {
36
36
  return element !== undefined && isArgsAware(element) && element.args !== undefined;
37
37
  }
38
+
39
+ export function ensureArgs(element?: GModelElement): element is GModelElement & Required<ArgsAware> {
40
+ if (!isArgsAware(element)) {
41
+ return false;
42
+ }
43
+ if (element.args === undefined) {
44
+ element.args = {};
45
+ }
46
+ return true;
47
+ }
@@ -13,8 +13,8 @@
13
13
  *
14
14
  * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
15
  ********************************************************************************/
16
- import { inject, injectable } from 'inversify';
17
16
  import { Action, CommandExecutionContext, GModelElement, GModelRoot, TYPES, hasArrayProp } from '@eclipse-glsp/sprotty';
17
+ import { inject, injectable } from 'inversify';
18
18
  import { addCssClasses, getElements, removeCssClasses } from '../../utils/gmodel-util';
19
19
  import { FeedbackCommand } from './feedback-command';
20
20
 
@@ -69,6 +69,9 @@ export class ModifyCssFeedbackCommand extends FeedbackCommand {
69
69
  }
70
70
  }
71
71
 
72
+ export const CSS_GHOST_ELEMENT = 'ghost-element';
73
+ export const CSS_HIDDEN = 'hidden';
74
+
72
75
  export enum CursorCSS {
73
76
  DEFAULT = 'default-mode',
74
77
  OVERLAP_FORBIDDEN = 'overlap-forbidden-mode',
@@ -39,6 +39,7 @@ import { commandPaletteModule } from './features/command-palette/command-palette
39
39
  import { contextMenuModule } from './features/context-menu/context-menu-module';
40
40
  import { copyPasteModule } from './features/copy-paste/copy-paste-modules';
41
41
  import { decorationModule } from './features/decoration/decoration-module';
42
+ import { elementTemplateModule } from './features/element-template/element-template-module';
42
43
  import { exportModule } from './features/export/export-modules';
43
44
  import { typeHintsModule } from './features/hints/type-hints-module';
44
45
  import { hoverModule } from './features/hover/hover-module';
@@ -90,6 +91,7 @@ export const DEFAULT_MODULES = [
90
91
  edgeCreationToolModule,
91
92
  edgeEditToolModule,
92
93
  deletionToolModule,
94
+ elementTemplateModule,
93
95
  nodeCreationToolModule,
94
96
  changeBoundsToolModule,
95
97
  marqueeSelectionToolModule,
@@ -15,11 +15,19 @@
15
15
  ********************************************************************************/
16
16
  import '../../../../css/keyboard-tool-palette.css';
17
17
 
18
- import { configureActionHandler, TYPES, bindAsService, BindingContext, FeatureModule } from '@eclipse-glsp/sprotty';
18
+ import {
19
+ BindingContext,
20
+ FeatureModule,
21
+ SetModelAction,
22
+ TYPES,
23
+ UpdateModelAction,
24
+ bindAsService,
25
+ configureActionHandler
26
+ } from '@eclipse-glsp/sprotty';
27
+ import { EnableDefaultToolsAction } from '../../../base/tool-manager/tool';
19
28
  import { EnableToolPaletteAction } from '../../tool-palette/tool-palette';
20
- import { KeyboardToolPalette } from './keyboard-tool-palette';
21
29
  import { FocusDomAction } from '../actions';
22
- import { EnableDefaultToolsAction } from '../../../base/tool-manager/tool';
30
+ import { KeyboardToolPalette } from './keyboard-tool-palette';
23
31
 
24
32
  export const keyboardToolPaletteModule = new FeatureModule((bind, unbind, isBound, rebind) => {
25
33
  const context = { bind, unbind, isBound, rebind };
@@ -32,4 +40,6 @@ export function configureKeyboardToolPaletteTool(context: BindingContext): void
32
40
  configureActionHandler(context, EnableDefaultToolsAction.KIND, KeyboardToolPalette);
33
41
  configureActionHandler(context, FocusDomAction.KIND, KeyboardToolPalette);
34
42
  configureActionHandler(context, EnableToolPaletteAction.KIND, KeyboardToolPalette);
43
+ configureActionHandler(context, UpdateModelAction.KIND, KeyboardToolPalette);
44
+ configureActionHandler(context, SetModelAction.KIND, KeyboardToolPalette);
35
45
  }
@@ -13,35 +13,35 @@
13
13
  *
14
14
  * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
15
  ********************************************************************************/
16
- import { injectable } from 'inversify';
17
16
  import {
18
- ICommand,
19
- SetUIExtensionVisibilityAction,
20
17
  Action,
18
+ ICommand,
21
19
  PaletteItem,
22
20
  RequestContextActions,
23
21
  RequestMarkersAction,
24
22
  SetContextActions,
23
+ SetUIExtensionVisibilityAction,
25
24
  TriggerNodeCreationAction
26
25
  } from '@eclipse-glsp/sprotty';
26
+ import { injectable } from 'inversify';
27
27
  import { KeyCode, matchesKeystroke } from 'sprotty/lib/utils/keyboard';
28
- import { MouseDeleteTool } from '../../tools/deletion/delete-tool';
29
- import { MarqueeMouseTool } from '../../tools/marquee-selection/marquee-mouse-tool';
28
+ import { EnableDefaultToolsAction, EnableToolsAction } from '../../../base/tool-manager/tool';
30
29
  import {
31
- createIcon,
32
- changeCodiconClass,
33
- createToolGroup,
30
+ EnableToolPaletteAction,
34
31
  ToolPalette,
32
+ changeCodiconClass,
35
33
  compare,
36
- EnableToolPaletteAction
34
+ createIcon,
35
+ createToolGroup
37
36
  } from '../../tool-palette/tool-palette';
38
- import { KeyboardNodeGridMetadata } from '../keyboard-grid/constants';
37
+ import { MouseDeleteTool } from '../../tools/deletion/delete-tool';
38
+ import { MarqueeMouseTool } from '../../tools/marquee-selection/marquee-mouse-tool';
39
39
  import { FocusDomAction } from '../actions';
40
40
  import { EdgeAutocompletePaletteMetadata } from '../edge-autocomplete/edge-autocomplete-palette';
41
- import { EnableDefaultToolsAction, EnableToolsAction } from '../../../base/tool-manager/tool';
42
- import { ShowToastMessageAction } from '../toast/toast-handler';
43
41
  import { ElementNavigatorKeyListener } from '../element-navigation/diagram-navigation-tool';
42
+ import { KeyboardNodeGridMetadata } from '../keyboard-grid/constants';
44
43
  import * as messages from '../toast/messages.json';
44
+ import { ShowToastMessageAction } from '../toast/toast-handler';
45
45
 
46
46
  const SEARCH_ICON_ID = 'search';
47
47
  const PALETTE_ICON_ID = 'symbol-color';
@@ -119,7 +119,7 @@ export class KeyboardToolPalette extends ToolPalette {
119
119
  }
120
120
 
121
121
  override handle(action: Action): ICommand | Action | void {
122
- if (action.kind === EnableToolPaletteAction.KIND) {
122
+ if (EnableToolPaletteAction.is(action)) {
123
123
  const requestAction = RequestContextActions.create({
124
124
  contextId: ToolPalette.ID,
125
125
  editorContext: {
@@ -134,9 +134,6 @@ export class KeyboardToolPalette extends ToolPalette {
134
134
  ]);
135
135
  }
136
136
  });
137
- } else if (action.kind === EnableDefaultToolsAction.KIND) {
138
- this.changeActiveButton();
139
- this.restoreFocus();
140
137
  } else if (FocusDomAction.is(action) && action.id === ToolPalette.ID) {
141
138
  if (this.containerElement.contains(document.activeElement)) {
142
139
  this.toggleShortcutVisibility();
@@ -144,6 +141,8 @@ export class KeyboardToolPalette extends ToolPalette {
144
141
  this.showShortcuts();
145
142
  }
146
143
  this.containerElement.focus();
144
+ } else {
145
+ super.handle(action);
147
146
  }
148
147
  }
149
148
 
@@ -30,6 +30,8 @@ import { FreeFormLayouter } from './freeform-layout';
30
30
  import { GLSPHiddenBoundsUpdater } from './glsp-hidden-bounds-updater';
31
31
  import { HBoxLayouterExt } from './hbox-layout';
32
32
  import { LayouterExt } from './layouter';
33
+ import { LocalComputedBoundsCommand } from './local-bounds';
34
+ import { SetBoundsFeebackCommand } from './set-bounds-feedback-command';
33
35
  import { VBoxLayouterExt } from './vbox-layout';
34
36
 
35
37
  export const boundsModule = new FeatureModule((bind, _unbind, isBound, _rebind) => {
@@ -38,6 +40,10 @@ export const boundsModule = new FeatureModule((bind, _unbind, isBound, _rebind)
38
40
  configureCommand(context, RequestBoundsCommand);
39
41
  bind(HiddenBoundsUpdater).toSelf().inSingletonScope();
40
42
  bindAsService(context, TYPES.HiddenVNodePostprocessor, GLSPHiddenBoundsUpdater);
43
+
44
+ configureCommand(context, LocalComputedBoundsCommand);
45
+ configureCommand(context, SetBoundsFeebackCommand);
46
+
41
47
  bind(TYPES.Layouter).to(LayouterExt).inSingletonScope();
42
48
  bind(TYPES.LayoutRegistry).to(LayoutRegistry).inSingletonScope();
43
49
 
@@ -14,22 +14,23 @@
14
14
  * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
15
  ********************************************************************************/
16
16
 
17
- import { inject, injectable, optional } from 'inversify';
18
- import { VNode } from 'snabbdom';
19
17
  import {
20
18
  Action,
21
19
  ComputedBoundsAction,
22
20
  Deferred,
23
21
  EdgeRouterRegistry,
24
22
  ElementAndRoutingPoints,
23
+ GModelElement,
24
+ GRoutableElement,
25
25
  HiddenBoundsUpdater,
26
26
  IActionDispatcher,
27
27
  RequestAction,
28
- ResponseAction,
29
- GModelElement,
30
- GRoutableElement
28
+ ResponseAction
31
29
  } from '@eclipse-glsp/sprotty';
30
+ import { inject, injectable, optional } from 'inversify';
31
+ import { VNode } from 'snabbdom';
32
32
  import { calcElementAndRoute, isRoutable } from '../../utils/gmodel-util';
33
+ import { LocalComputedBoundsAction, LocalRequestBoundsAction } from './local-bounds';
33
34
 
34
35
  /**
35
36
  * Grabs the bounds from hidden SVG DOM elements, applies layouts, collects routes and fires {@link ComputedBoundsAction}s.
@@ -56,7 +57,7 @@ export class GLSPHiddenBoundsUpdater extends HiddenBoundsUpdater {
56
57
  const actions = this.captureActions(() => super.postUpdate(cause));
57
58
  actions
58
59
  .filter(action => ComputedBoundsAction.is(action))
59
- .forEach(action => this.actionDispatcher.dispatch(this.enhanceAction(action as ComputedBoundsAction)));
60
+ .forEach(action => this.actionDispatcher.dispatch(this.enhanceAction(action as ComputedBoundsAction, cause)));
60
61
  this.element2route = [];
61
62
  }
62
63
 
@@ -72,7 +73,10 @@ export class GLSPHiddenBoundsUpdater extends HiddenBoundsUpdater {
72
73
  }
73
74
  }
74
75
 
75
- protected enhanceAction(action: ComputedBoundsAction): ComputedBoundsAction {
76
+ protected enhanceAction(action: ComputedBoundsAction, cause?: Action): ComputedBoundsAction {
77
+ if (LocalRequestBoundsAction.is(cause)) {
78
+ LocalComputedBoundsAction.mark(action);
79
+ }
76
80
  action.routes = this.element2route.length === 0 ? undefined : this.element2route;
77
81
  return action;
78
82
  }
@@ -0,0 +1,91 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2023 EclipseSource and others.
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the Eclipse Public License v. 2.0 which is available at
6
+ * http://www.eclipse.org/legal/epl-2.0.
7
+ *
8
+ * This Source Code may also be made available under the following Secondary
9
+ * Licenses when the conditions for such availability set forth in the Eclipse
10
+ * Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ * with the GNU Classpath Exception which is available at
12
+ * https://www.gnu.org/software/classpath/license.html.
13
+ *
14
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
+ ********************************************************************************/
16
+ import {
17
+ Action,
18
+ ActionDispatcher,
19
+ Command,
20
+ CommandExecutionContext,
21
+ CommandResult,
22
+ CommandReturn,
23
+ ComputedBoundsAction,
24
+ ComputedBoundsApplicator,
25
+ GModelRoot,
26
+ GModelRootSchema,
27
+ RequestBoundsAction,
28
+ TYPES
29
+ } from '@eclipse-glsp/sprotty';
30
+ import { inject, injectable } from 'inversify';
31
+ import { ServerAction } from '../../base/model/glsp-model-source';
32
+
33
+ export namespace LocalRequestBoundsAction {
34
+ export function is(object: unknown): object is RequestBoundsAction {
35
+ return RequestBoundsAction.is(object) && !ServerAction.is(object);
36
+ }
37
+
38
+ export function fromCommand(context: CommandExecutionContext, actionDispatcher: ActionDispatcher, cause?: Action): CommandResult {
39
+ // do not modify the main model (modelChanged = false) but request local bounds calculation on hidden model
40
+ actionDispatcher.dispatch(RequestBoundsAction.create(context.root as unknown as GModelRootSchema));
41
+ return {
42
+ model: context.root,
43
+ modelChanged: false,
44
+ cause
45
+ };
46
+ }
47
+ }
48
+
49
+ export namespace LocalComputedBoundsAction {
50
+ export function is(object: unknown): object is RequestBoundsAction {
51
+ return ComputedBoundsAction.is(object) && ServerAction.is(object);
52
+ }
53
+
54
+ export function mark(action: ComputedBoundsAction): ComputedBoundsAction {
55
+ // mimic: we mark the computed bounds action as coming from the server so it is not sent to the server and handled locally
56
+ ServerAction.mark(action);
57
+ return action;
58
+ }
59
+ }
60
+
61
+ @injectable()
62
+ export class LocalComputedBoundsCommand extends Command {
63
+ static readonly KIND: string = ComputedBoundsAction.KIND;
64
+
65
+ @inject(ComputedBoundsApplicator) protected readonly computedBoundsApplicator: ComputedBoundsApplicator;
66
+
67
+ constructor(@inject(TYPES.Action) readonly action: ComputedBoundsAction) {
68
+ super();
69
+ }
70
+
71
+ override execute(context: CommandExecutionContext): GModelRoot | CommandResult {
72
+ if (LocalComputedBoundsAction.is(this.action)) {
73
+ // apply computed bounds from the hidden model and return updated model to render new main model
74
+ this.computedBoundsApplicator.apply(context.root as unknown as GModelRootSchema, this.action);
75
+ return context.root;
76
+ }
77
+ // computed bounds action from server -> we do not care and do not trigger any update of the main model
78
+ return {
79
+ model: context.root,
80
+ modelChanged: false
81
+ };
82
+ }
83
+
84
+ override undo(context: CommandExecutionContext): CommandReturn {
85
+ return context.root;
86
+ }
87
+
88
+ override redo(context: CommandExecutionContext): CommandReturn {
89
+ return context.root;
90
+ }
91
+ }
@@ -0,0 +1,70 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2023 EclipseSource and others.
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the Eclipse Public License v. 2.0 which is available at
6
+ * http://www.eclipse.org/legal/epl-2.0.
7
+ *
8
+ * This Source Code may also be made available under the following Secondary
9
+ * Licenses when the conditions for such availability set forth in the Eclipse
10
+ * Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ * with the GNU Classpath Exception which is available at
12
+ * https://www.gnu.org/software/classpath/license.html.
13
+ *
14
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
+ ********************************************************************************/
16
+ import {
17
+ Action,
18
+ CommandExecutionContext,
19
+ CommandReturn,
20
+ ElementAndBounds,
21
+ SetBoundsAction,
22
+ SetBoundsCommand,
23
+ TYPES,
24
+ isLayoutContainer
25
+ } from '@eclipse-glsp/sprotty';
26
+ import { inject, injectable } from 'inversify';
27
+ import { GLSPActionDispatcher } from '../../base/action-dispatcher';
28
+ import { FeedbackCommand } from '../../base/feedback/feedback-command';
29
+ import { LocalRequestBoundsAction } from './local-bounds';
30
+
31
+ export interface SetBoundsFeedbackAction extends Omit<SetBoundsAction, 'kind'> {
32
+ kind: typeof SetBoundsFeedbackAction.KIND;
33
+ }
34
+
35
+ export namespace SetBoundsFeedbackAction {
36
+ export const KIND = 'setBoundsFeedback';
37
+
38
+ export function is(object: any): object is SetBoundsFeedbackAction {
39
+ return Action.hasKind(object, KIND);
40
+ }
41
+
42
+ export function create(bounds: ElementAndBounds[]): SetBoundsFeedbackAction {
43
+ return { kind: KIND, bounds };
44
+ }
45
+ }
46
+
47
+ @injectable()
48
+ export class SetBoundsFeebackCommand extends SetBoundsCommand implements FeedbackCommand {
49
+ static override readonly KIND: string = SetBoundsFeedbackAction.KIND;
50
+
51
+ readonly priority: number = 0;
52
+
53
+ @inject(TYPES.IActionDispatcher) protected actionDispatcher: GLSPActionDispatcher;
54
+
55
+ override execute(context: CommandExecutionContext): CommandReturn {
56
+ super.execute(context);
57
+
58
+ // apply set bounds as layout options so that when we calculate the bounds they are considered by the layouter
59
+ this.action.bounds.forEach(bounds => {
60
+ const element = context.root.index.getById(bounds.elementId);
61
+ if (element && isLayoutContainer(element)) {
62
+ const options = element.layoutOptions ?? {};
63
+ options.prefHeight = bounds.newSize.height;
64
+ options.prefWidth = bounds.newSize.width;
65
+ element.layoutOptions = options;
66
+ }
67
+ });
68
+ return LocalRequestBoundsAction.fromCommand(context, this.actionDispatcher, this.action);
69
+ }
70
+ }
@@ -16,10 +16,10 @@
16
16
  import {
17
17
  BoundsAware,
18
18
  GChildElement,
19
- Hoverable,
20
- Locateable,
21
19
  GModelElement,
22
20
  GParentElement,
21
+ Hoverable,
22
+ Locateable,
23
23
  Selectable,
24
24
  hoverFeedbackFeature,
25
25
  isBoundsAware,
@@ -72,7 +72,6 @@ export class SResizeHandle extends GChildElement implements Hoverable {
72
72
  }
73
73
 
74
74
  export function addResizeHandles(element: GParentElement): void {
75
- removeResizeHandles(element);
76
75
  element.add(new SResizeHandle(ResizeHandleLocation.TopLeft));
77
76
  element.add(new SResizeHandle(ResizeHandleLocation.TopRight));
78
77
  element.add(new SResizeHandle(ResizeHandleLocation.BottomLeft));
@@ -13,8 +13,8 @@
13
13
  *
14
14
  * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
15
  ********************************************************************************/
16
+ import { Decoration, DecorationPlacer, GChildElement, GModelElement, GRoutableElement, Point, isSizeable } from '@eclipse-glsp/sprotty';
16
17
  import { injectable } from 'inversify';
17
- import { Decoration, DecorationPlacer, GChildElement, Point, GModelElement, GRoutableElement, isSizeable } from '@eclipse-glsp/sprotty';
18
18
 
19
19
  @injectable()
20
20
  export class GlspDecorationPlacer extends DecorationPlacer {
@@ -26,8 +26,8 @@ export class GlspDecorationPlacer extends DecorationPlacer {
26
26
  }
27
27
  if (isSizeable(element)) {
28
28
  return {
29
- x: GlspDecorationPlacer.DECORATION_OFFSET.x * element.bounds.width,
30
- y: GlspDecorationPlacer.DECORATION_OFFSET.y * element.bounds.height
29
+ x: -GlspDecorationPlacer.DECORATION_OFFSET.x,
30
+ y: -GlspDecorationPlacer.DECORATION_OFFSET.y
31
31
  };
32
32
  }
33
33
  return Point.ORIGIN;
@@ -0,0 +1,109 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2023 EclipseSource and others.
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the Eclipse Public License v. 2.0 which is available at
6
+ * http://www.eclipse.org/legal/epl-2.0.
7
+ *
8
+ * This Source Code may also be made available under the following Secondary
9
+ * Licenses when the conditions for such availability set forth in the Eclipse
10
+ * Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ * with the GNU Classpath Exception which is available at
12
+ * https://www.gnu.org/software/classpath/license.html.
13
+ *
14
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
+ ********************************************************************************/
16
+
17
+ import {
18
+ Action,
19
+ CommandExecutionContext,
20
+ CommandResult,
21
+ ElementTemplate,
22
+ GChildElement,
23
+ GModelElementSchema,
24
+ TYPES,
25
+ distinctAdd,
26
+ remove
27
+ } from '@eclipse-glsp/sprotty';
28
+ import { inject, injectable } from 'inversify';
29
+ import { GLSPActionDispatcher } from '../../base/action-dispatcher';
30
+ import { FeedbackCommand } from '../../base/feedback/feedback-command';
31
+ import { isNotUndefined } from '../../utils/gmodel-util';
32
+ import { LocalRequestBoundsAction } from '../bounds/local-bounds';
33
+
34
+ export interface AddTemplateElementsAction extends Action {
35
+ kind: typeof AddTemplateElementsAction.KIND;
36
+ templates: ElementTemplate[];
37
+ addClasses?: string[];
38
+ removeClasses?: string[];
39
+ }
40
+
41
+ export namespace AddTemplateElementsAction {
42
+ export const KIND = 'addTemplateElements';
43
+
44
+ export function create(options: Omit<AddTemplateElementsAction, 'kind'>): AddTemplateElementsAction {
45
+ return {
46
+ kind: KIND,
47
+ ...options
48
+ };
49
+ }
50
+ }
51
+
52
+ export function getTemplateElementId(template: ElementTemplate): string {
53
+ return typeof template === 'string' ? `${template}_feedback` : template.id;
54
+ }
55
+
56
+ @injectable()
57
+ export class AddTemplateElementsFeedbackCommand extends FeedbackCommand {
58
+ static readonly KIND = AddTemplateElementsAction.KIND;
59
+
60
+ @inject(TYPES.IActionDispatcher) protected actionDispatcher: GLSPActionDispatcher;
61
+
62
+ constructor(@inject(TYPES.Action) readonly action: AddTemplateElementsAction) {
63
+ super();
64
+ }
65
+
66
+ override execute(context: CommandExecutionContext): CommandResult {
67
+ this.action.templates
68
+ .map(template => templateToSchema(template, context))
69
+ .filter(isNotUndefined)
70
+ .map(schema => context.modelFactory.createElement(schema))
71
+ .map(element => this.applyRootCssClasses(element, this.action.addClasses, this.action.removeClasses))
72
+ .forEach(templateElement => context.root.add(templateElement));
73
+ return LocalRequestBoundsAction.fromCommand(context, this.actionDispatcher, this.action);
74
+ }
75
+
76
+ protected applyRootCssClasses(element: GChildElement, addClasses?: string[], removeClasses?: string[]): GChildElement {
77
+ element.cssClasses = modifyCssClasses(element.cssClasses, addClasses, removeClasses);
78
+ return element;
79
+ }
80
+ }
81
+
82
+ export function templateToSchema(template: ElementTemplate, context: CommandExecutionContext): GModelElementSchema | undefined {
83
+ if (typeof template === 'string') {
84
+ const element = context.root.index.getById(template);
85
+ const schema = element ? context.modelFactory.createSchema(element) : undefined;
86
+ if (schema) {
87
+ adaptSchemaIds(schema);
88
+ }
89
+ return schema;
90
+ }
91
+ return template;
92
+ }
93
+
94
+ function adaptSchemaIds(schema: GModelElementSchema): GModelElementSchema {
95
+ schema.id = getTemplateElementId(schema.id);
96
+ schema.children?.forEach(child => adaptSchemaIds(child));
97
+ return schema;
98
+ }
99
+
100
+ function modifyCssClasses(source?: string[], toAdd?: string[], toRemove?: string[]): string[] {
101
+ const classes = source ?? [];
102
+ if (toAdd) {
103
+ distinctAdd(classes, ...toAdd);
104
+ }
105
+ if (toRemove) {
106
+ remove(classes, ...toRemove);
107
+ }
108
+ return classes;
109
+ }
@@ -0,0 +1,24 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2019-2023 EclipseSource and others.
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the Eclipse Public License v. 2.0 which is available at
6
+ * http://www.eclipse.org/legal/epl-2.0.
7
+ *
8
+ * This Source Code may also be made available under the following Secondary
9
+ * Licenses when the conditions for such availability set forth in the Eclipse
10
+ * Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ * with the GNU Classpath Exception which is available at
12
+ * https://www.gnu.org/software/classpath/license.html.
13
+ *
14
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
+ ********************************************************************************/
16
+ import { FeatureModule, configureCommand } from '@eclipse-glsp/sprotty';
17
+ import { AddTemplateElementsFeedbackCommand } from './add-template-element';
18
+ import { RemoveTemplateElementsFeedbackCommand } from './remove-template-element';
19
+
20
+ export const elementTemplateModule = new FeatureModule((bind, unbind, isBound, rebind) => {
21
+ const context = { bind, unbind, isBound, rebind };
22
+ configureCommand(context, AddTemplateElementsFeedbackCommand);
23
+ configureCommand(context, RemoveTemplateElementsFeedbackCommand);
24
+ });