feat(toolbar/hokeys): add pub sub events to hotkeys manager class, subscribe toolbar to hotkeys pressed event (#5157)

This commit is contained in:
Ibrahim authored and GitHub committed 2025-06-25 10:43:27 -04:00
1 parent b1ad3787e4
commit 57f07ad9f2
2 files changed
+30 -1

No files matched your search

@@ -2,6 +2,7 @@ import objectHash from 'object-hash';
import { hotkeys as mouseTrapAPI } from '../utils';
import Hotkey from './Hotkey';
import migrateOldHotkeyDefinitions from '../utils/hotkeys/migrateHotkeys';
import pubSubServiceInterface from '../services/_shared/pubSubServiceInterface';
/**
*
@@ -19,6 +20,16 @@ export class HotkeysManager {
public hotkeyDefinitions: Record<string, any> = {};
public hotkeyDefaults: any[] = [];
public static EVENTS: Record<string, string> = {
HOTKEY_PRESSED: 'event::hotkeysManager:hotkeyPressed',
};
public EVENTS: Record<string, string>;
public listeners: Record<string, Array<{ id: string; callback: (data: unknown) => void }> | undefined> = {};
public subscribe: (eventName: string, callback: (data: unknown) => void) => { unsubscribe: () => void };
public _broadcastEvent: (eventName: string, callbackProps: unknown) => void;
public _unsubscribe: (eventName: string, listenerId: string) => void;
public _isValidEvent: (eventName: string) => boolean;
constructor(
commandsManager: AppTypes.CommandsManager,
servicesManager: AppTypes.ServicesManager
@@ -26,6 +37,12 @@ export class HotkeysManager {
this._servicesManager = servicesManager;
this._commandsManager = commandsManager;
this.EVENTS = HotkeysManager.EVENTS;
this.subscribe = pubSubServiceInterface.subscribe.bind(this);
this._broadcastEvent = pubSubServiceInterface._broadcastEvent.bind(this);
this._unsubscribe = pubSubServiceInterface._unsubscribe.bind(this);
this._isValidEvent = pubSubServiceInterface._isValidEvent.bind(this);
// Check for old hotkey definitions format and migrate if needed
migrateOldHotkeyDefinitions({
generateHash: this.generateHash,
@@ -264,6 +281,13 @@ export class HotkeysManager {
evt.preventDefault();
evt.stopPropagation();
this._commandsManager.runCommand(commandName, { evt, ...commandOptions }, context);
this._broadcastEvent(HotkeysManager.EVENTS.HOTKEY_PRESSED, {
commandName,
commandOptions,
keys: combinedKeys,
context,
evt,
});
});
}