interface IStage {
get: (id: string) => ICompatibleComponent | undefined;
getAll: () => Record<string, ICompatibleComponent | undefined>;
on: (eventName: string, listener: (...args: any[]) => void) => () => void;
emit: (eventName: string, ...args: any[]) => void;
exec: (methodName: string, ...args: any[]) => void;
expose: (methodMap: Record<string, (...args: any[]) => void>) => void;
getComponent: (id: string) => IDatavComponent | undefined | null;
getVariable: (
id: string,
) =>
| {
value: any;
set: (value: any) => void;
onChange: (cb: (current: any, prev: any) => void) => IDisposer;
}
| undefined;
}
type IDisposer = () => void;
/**
* 组件实例通用方法
*/
interface IDatavComponent {
/** 组件绘制 */
render(data: any, options?: { [key: string]: any }): void;
/** 配置更新 */
updateOptions(options: { [key: string]: any }): void;
/** 组件卸载 */
destroy(): void;
/** 宽高尺寸变更 */
resize?(w: number, h: number): void;
/** 开始动画 */
startAnimates?(): void;
/** 清除动画 */
clearAnimates?(): void;
}
interface IMoveConfig {
attr: {
x: number;
y: number;
};
positionType: 'to' | 'by';
}
type ICompatibleComponent = IDatavComponent & {
/* 组件实例 */
instance: any;
/* 组件实际绘制的 dom */
container: HTMLDivElement;
/* 监听组件抛出的事件, 具体回调函数入参请参考组件的文档 */
on: (eventName: string, ...args: any[]) => void;
/* 显示组件 */
show(): void;
/* 隐藏组件 */
hide(): void;
/* 更新组件样式配置 */
updateProps(props: any): void;
/* 设置组件数据 */
setData(key: string): void;
/* 发起组件数据获取流程,可指定数据名 */
fetchData(key?: string): Promise<any>;
/* 监听组件数据变化 */
onDataChange: (key: string, cb: (current: any, prev: any) => void) => IDisposer;
} & {
/* 组件 id */
__id: string;
/* 切换组件显隐 */
toggleVisible(): void;
/* 移动组件 */
move(options: IMoveConfig): void;
}