Browse Source

Type device event callbacks

type-event-callbacks
Artur Arseniev 1 month ago
parent
commit
f1a42c72ce
  1. 28
      packages/core/src/device_manager/types.ts
  2. 5
      packages/core/src/editor/types.ts

28
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<Device>;
[DeviceEvents.remove]: EventCallbackRemove<Device>;
[DeviceEvents.removeBefore]: EventCallbackRemoveBefore<Device>;
[DeviceEvents.select]: [Device | null | undefined, Device | null | undefined];
[DeviceEvents.update]: [Device, Partial<DeviceProperties>, SetOptions];
[DeviceEvents.all]: EventCallbackAll<DeviceEvent, Device>;
}
// This is necessary to prevent the TS documentation generator from breaking.
export default DeviceEvents;

5
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[];
}

Loading…
Cancel
Save