From f1a42c72cebc65dbeb62c86af4ac86c5b84ac75b Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Tue, 17 Feb 2026 13:03:00 +0400 Subject: [PATCH] Type device event callbacks --- packages/core/src/device_manager/types.ts | 28 +++++++++++++++++++---- packages/core/src/editor/types.ts | 5 +++- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/packages/core/src/device_manager/types.ts b/packages/core/src/device_manager/types.ts index e9d0aa7fb..855bd67ab 100644 --- a/packages/core/src/device_manager/types.ts +++ b/packages/core/src/device_manager/types.ts @@ -1,3 +1,12 @@ +import { + EventCallbackAdd, + EventCallbackAll, + EventCallbackRemove, + EventCallbackRemoveBefore, + SetOptions, +} from '../common'; +import Device, { DeviceProperties } from './model/Device'; + /**{START_EVENTS}*/ export enum DeviceEvents { /** @@ -17,17 +26,17 @@ export enum DeviceEvents { removeBefore = 'device:remove:before', /** - * @event `device:select` A new device is selected. The `Device` is passed as an argument. + * @event `device:select` A new device is selected. Current and previous `Device` are passed as arguments. * @example - * editor.on('device:select', (device) => { ... }); + * editor.on('device:select', (newDevice, prevDevice) => { ... }); */ select = 'device:select', selectBefore = 'device:select:before', /** - * @event `device:update` Device updated. The `Device` and the object containing changes are passed as arguments. + * @event `device:update` Device updated. The `Device`, changed properties, and update options are passed as arguments. * @example - * editor.on('device:update', (device) => { ... }); + * editor.on('device:update', (device, changes, options) => { ... }); */ update = 'device:update', @@ -40,5 +49,16 @@ export enum DeviceEvents { } /**{END_EVENTS}*/ +export type DeviceEvent = `${DeviceEvents}`; + +export interface DevicesEventCallback { + [DeviceEvents.add]: EventCallbackAdd; + [DeviceEvents.remove]: EventCallbackRemove; + [DeviceEvents.removeBefore]: EventCallbackRemoveBefore; + [DeviceEvents.select]: [Device | null | undefined, Device | null | undefined]; + [DeviceEvents.update]: [Device, Partial, SetOptions]; + [DeviceEvents.all]: EventCallbackAll; +} + // This is necessary to prevent the TS documentation generator from breaking. export default DeviceEvents; diff --git a/packages/core/src/editor/types.ts b/packages/core/src/editor/types.ts index 6453c9230..47811ee26 100644 --- a/packages/core/src/editor/types.ts +++ b/packages/core/src/editor/types.ts @@ -4,6 +4,7 @@ import { LiteralUnion } from '../common'; import { CanvasEvent, CanvasEventCallback } from '../canvas/types'; import { CommandEvent, CommandsEventCallback } from '../commands/types'; import { DataSourceEvent, DataSourcesEventCallback } from '../data_sources/types'; +import { DeviceEvent, DevicesEventCallback } from '../device_manager/types'; import { ComponentEvent } from '../dom_components'; import { KeymapEvent } from '../keymaps'; import { ModalEvent } from '../modal_dialog'; @@ -17,6 +18,7 @@ type GeneralEvent = 'canvasScroll' | 'undo' | 'redo' | 'load' | 'update'; type EditorBuiltInEvents = | DataSourceEvent + | DeviceEvent | ComponentEvent | BlockEvent | AssetEvent @@ -41,7 +43,8 @@ export interface EditorEventCallbacks BlocksEventCallback, CanvasEventCallback, CommandsEventCallback, - DataSourcesEventCallback + DataSourcesEventCallback, + DevicesEventCallback { [key: string]: any[]; }