diff --git a/integration/eclipse/src/startup.ts b/integration/eclipse/src/startup.ts index 2ee6d49d..8fe388e2 100644 --- a/integration/eclipse/src/startup.ts +++ b/integration/eclipse/src/startup.ts @@ -1,4 +1,4 @@ -import { IVY_TYPES, ToolBar } from '@axonivy/process-editor'; +import { IVY_TYPES, ToolBar, JumpOutFeedbackAction } from '@axonivy/process-editor'; import { EnableInscriptionAction } from '@axonivy/process-editor-inscription'; import { EnableViewportAction, SwitchThemeAction, UpdatePaletteItems } from '@axonivy/process-editor-protocol'; import { EnableToolPaletteAction, GLSPActionDispatcher, IDiagramStartup, ShowGridAction, TYPES } from '@eclipse-glsp/client'; @@ -24,11 +24,11 @@ export class EclipseDiagramStartup implements IDiagramStartup { this.actionDispatcher.dispatch(SwitchThemeAction.create({ theme: this.options.theme })); } - async postRequestModel(): Promise { - this.actionDispatcher.dispatch(ShowGridAction.create({ show: this.options.showGrid })); - } + async postRequestModel(): Promise {} async postModelInitialization(): Promise { + this.actionDispatcher.dispatch(JumpOutFeedbackAction.create()); + this.actionDispatcher.dispatch(ShowGridAction.create({ show: this.options.showGrid })); this.actionDispatcher.dispatch(UpdatePaletteItems.create()); this.actionDispatcher.dispatch(EnableInscriptionAction.create({})); } diff --git a/integration/standalone/src/startup.ts b/integration/standalone/src/startup.ts index 099db193..b288f3e6 100644 --- a/integration/standalone/src/startup.ts +++ b/integration/standalone/src/startup.ts @@ -1,3 +1,4 @@ +import { JumpOutFeedbackAction } from '@axonivy/process-editor'; import { EnableInscriptionAction } from '@axonivy/process-editor-inscription'; import { EnableViewportAction, SwitchThemeAction, UpdatePaletteItems } from '@axonivy/process-editor-protocol'; import { @@ -10,7 +11,6 @@ import { } from '@eclipse-glsp/client'; import { ContainerModule, inject, injectable } from 'inversify'; import { IvyDiagramOptions } from './di.config'; - import './index.css'; @injectable() @@ -27,17 +27,16 @@ export class StandaloneDiagramStartup implements IDiagramStartup { this.actionDispatcher.dispatch(SwitchThemeAction.create({ theme: this.options.theme })); } - async postRequestModel(): Promise { - this.actionDispatcher.dispatch(UpdatePaletteItems.create()); - } - async postModelInitialization(): Promise { + this.actionDispatcher.dispatch(UpdatePaletteItems.create()); this.actionDispatcher.dispatch( EnableInscriptionAction.create({ connection: { server: this.options.inscriptionContext.server }, inscriptionContext: this.options.inscriptionContext }) ); + this.actionDispatcher.dispatch(JumpOutFeedbackAction.create()); + if (this.options.select) { const elementIds = this.options.select.split(NavigationTarget.ELEMENT_IDS_SEPARATOR); this.actionDispatcher.dispatch(SelectAction.create({ selectedElementsIDs: elementIds })); diff --git a/integration/viewer/src/startup.ts b/integration/viewer/src/startup.ts index 373fc4b5..cf21da87 100644 --- a/integration/viewer/src/startup.ts +++ b/integration/viewer/src/startup.ts @@ -3,6 +3,7 @@ import { Action, CenterAction, GLSPActionDispatcher, IDiagramStartup, Navigation import { ContainerModule, inject, injectable, interfaces } from 'inversify'; import { IvyDiagramOptions } from './di.config'; import { isInPreviewMode } from './url-helper'; +import { JumpOutFeedbackAction } from '@axonivy/process-editor/'; const ContainerSymbol = Symbol('ContainerSymbol'); @@ -26,6 +27,7 @@ export class ViewerDiagramStartup implements IDiagramStartup { protected async dispatchAfterModelInitialized(): Promise { const actions: Action[] = []; + actions.push(JumpOutFeedbackAction.create()); if (this.isNumeric(this.options.zoom)) { actions.push(SetViewportZoomAction.create({ zoom: +this.options.zoom / 100 })); actions.push(...this.showElement((ids: string[]) => CenterAction.create(ids, { animate: false, retainZoom: true }))); diff --git a/packages/editor/src/index.ts b/packages/editor/src/index.ts index 2c51f334..911e3e2a 100644 --- a/packages/editor/src/index.ts +++ b/packages/editor/src/index.ts @@ -18,6 +18,7 @@ export { ivyChangeBoundsToolModule, ivyExportModule } from './tools/di.config'; /* Features */ export * from './jump/action'; export * from './jump/model'; +export * from './jump/jump-out-ui'; export * from './ui-tools/quick-action/model'; export * from './ui-tools/quick-action/quick-action'; export * from './ui-tools/quick-action/quick-action-ui'; diff --git a/packages/editor/src/jump/di.config.ts b/packages/editor/src/jump/di.config.ts index b3f8c82d..d1ba9940 100644 --- a/packages/editor/src/jump/di.config.ts +++ b/packages/editor/src/jump/di.config.ts @@ -1,16 +1,16 @@ import './jump-out.css'; -import { configureActionHandler, configureCommand, FeatureModule, TYPES } from '@eclipse-glsp/client'; +import { configureActionHandler, FeatureModule, TYPES } from '@eclipse-glsp/client'; import { JumpAction } from '@axonivy/process-editor-protocol'; import { IVY_TYPES } from '../types'; import { JumpActionHandler, JumpQuickActionProvider } from './action'; -import { JumpOutFeedbackCommand, JumpOutUi } from './jump-out-ui'; +import { JumpOutFeedbackAction, JumpOutUi } from './jump-out-ui'; const ivyJumpModule = new FeatureModule((bind, _unbind, isBound) => { bind(JumpOutUi).toSelf().inSingletonScope(); bind(TYPES.IUIExtension).toService(JumpOutUi); - configureCommand({ bind, isBound }, JumpOutFeedbackCommand); + configureActionHandler({ bind, isBound }, JumpOutFeedbackAction.KIND, JumpOutUi); bind(IVY_TYPES.QuickActionProvider).to(JumpQuickActionProvider); configureActionHandler({ bind, isBound }, JumpAction.KIND, JumpActionHandler); }); diff --git a/packages/editor/src/jump/jump-out-ui.test.ts b/packages/editor/src/jump/jump-out-ui.test.ts index fd05b529..44cbd88f 100644 --- a/packages/editor/src/jump/jump-out-ui.test.ts +++ b/packages/editor/src/jump/jump-out-ui.test.ts @@ -1,38 +1,39 @@ /* eslint-disable no-unused-expressions */ import { + Action, ActionDispatcher, ArgsAware, Bounds, - CommandExecutionContext, - CommandReturn, GGraph, GModelFactory, GModelRoot, + IActionHandler, + ICommand, InitializeCanvasBoundsAction, TYPES, - configureCommand, + configureActionHandler, selectModule } from '@eclipse-glsp/client'; import { Container, injectable } from 'inversify'; import { beforeEach, describe, expect, test } from 'vitest'; import { createTestContainer } from '../utils/test-utils'; -import { JumpOutFeedbackAction, JumpOutFeedbackCommand } from './jump-out-ui'; +import { JumpOutFeedbackAction, JumpOutUi } from './jump-out-ui'; let root: GModelRoot & ArgsAware; let jumpOutBtn = false; @injectable() -class JumpOutFeedbackCommandMock extends JumpOutFeedbackCommand { - execute(context: CommandExecutionContext): CommandReturn { - jumpOutBtn = this.showJumpOutBtn(root); - return root; +class JumpOutActionHandlerMock implements IActionHandler { + handle(action: Action): ICommand | Action | void { + const outUi = new JumpOutUi(); + jumpOutBtn = outUi.showJumpOutBtn(root); } } function createContainer(): Container { const container = createTestContainer(selectModule); - configureCommand(container, JumpOutFeedbackCommandMock); + configureActionHandler(container, JumpOutFeedbackAction.KIND, JumpOutActionHandlerMock); return container; } diff --git a/packages/editor/src/jump/jump-out-ui.ts b/packages/editor/src/jump/jump-out-ui.ts index 7a47f99c..5a852fb2 100644 --- a/packages/editor/src/jump/jump-out-ui.ts +++ b/packages/editor/src/jump/jump-out-ui.ts @@ -1,24 +1,22 @@ +import { JumpAction } from '@axonivy/process-editor-protocol'; +import { IvyIcons } from '@axonivy/ui-icons'; import { Action, - CommandExecutionContext, - CommandReturn, EditorContextService, - FeedbackCommand, + GLSPAbstractUIExtension, + GModelRoot, IActionDispatcher, + IActionHandler, IFeedbackActionDispatcher, - SetUIExtensionVisibilityAction, - GModelRoot, - TYPES, SelectionService, - GLSPAbstractUIExtension + SetUIExtensionVisibilityAction, + TYPES } from '@eclipse-glsp/client'; import { inject, injectable, postConstruct } from 'inversify'; -import { IvyIcons } from '@axonivy/ui-icons'; import { createElement, createIcon } from '../utils/ui-utils'; -import { JumpAction } from '@axonivy/process-editor-protocol'; @injectable() -export class JumpOutUi extends GLSPAbstractUIExtension { +export class JumpOutUi extends GLSPAbstractUIExtension implements IActionHandler { static readonly ID = 'jumpOutUi'; @inject(TYPES.IActionDispatcher) protected readonly actionDispatcher: IActionDispatcher; @@ -34,11 +32,6 @@ export class JumpOutUi extends GLSPAbstractUIExtension { return 'jump-out-container'; } - @postConstruct() - protected postConstruct(): void { - this.feedbackDispatcher.registerFeedback(this, [JumpOutFeedbackAction.create()]); - } - protected initializeContents(containerElement: HTMLElement): void { containerElement.style.position = 'absolute'; } @@ -51,36 +44,32 @@ export class JumpOutUi extends GLSPAbstractUIExtension { button.onclick = _ev => this.actionDispatcher.dispatch(JumpAction.create({ elementId: '' })); containerElement.appendChild(button); } + + handle(action: Action): void { + if (action.kind === JumpOutFeedbackAction.KIND) { + this.feedbackDispatcher.registerFeedback(this, [ + SetUIExtensionVisibilityAction.create({ extensionId: JumpOutUi.ID, visible: this.showJumpOutBtn(this.editorContext.modelRoot) }) + ]); + } + } + + showJumpOutBtn(root: GModelRoot): boolean { + return root.id.includes('-'); + } } export interface JumpOutFeedbackAction extends Action { - kind: typeof JumpOutFeedbackCommand.KIND; + kind: typeof JumpOutFeedbackAction.KIND; elementId?: string; } export namespace JumpOutFeedbackAction { + export const KIND = 'jumpOutFeedback'; + export function create(elementId?: string): JumpOutFeedbackAction { return { - kind: JumpOutFeedbackCommand.KIND, + kind: JumpOutFeedbackAction.KIND, elementId }; } } - -@injectable() -export class JumpOutFeedbackCommand extends FeedbackCommand { - static readonly KIND = 'toolPaletteFeedback'; - @inject(TYPES.Action) protected action: JumpOutFeedbackAction; - @inject(TYPES.IActionDispatcher) protected readonly actionDispatcher: IActionDispatcher; - - execute(context: CommandExecutionContext): CommandReturn { - this.actionDispatcher.dispatch( - SetUIExtensionVisibilityAction.create({ extensionId: JumpOutUi.ID, visible: this.showJumpOutBtn(context.root) }) - ); - return context.root; - } - - showJumpOutBtn(root: GModelRoot): boolean { - return root.id.includes('-'); - } -}