Skip to content

Commit

Permalink
feat(skeleton): add onDisableWidget & onEnableWidget APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
liujuping authored and JackLian committed Dec 19, 2023
1 parent 4a502f8 commit e79f686
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 21 deletions.
35 changes: 31 additions & 4 deletions docs/docs/api/skeleton.md
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ export default controlPanelWidthPlugin;
* @param listener
* @returns
*/
onShowPanel(listener: (...args: any[]) => void): IPublicTypeDisposable;
onShowPanel(listener: (paneName?: string, panel?: IPublicModelSkeletonItem) => void): IPublicTypeDisposable;
```

相关类型:[IPublicTypeDisposable](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/disposable.ts)
Expand All @@ -403,11 +403,38 @@ onShowPanel(listener: (...args: any[]) => void): IPublicTypeDisposable;
* @param listener
* @returns
*/
onHidePanel(listener: (...args: any[]) => void): IPublicTypeDisposable;
onHidePanel(listener: (paneName?: string, panel?: IPublicModelSkeletonItem) => void): IPublicTypeDisposable;
```

相关类型:[IPublicTypeDisposable](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/disposable.ts)

### onDisableWidget

监听 Widget 实例 Disable 事件

```typescript
/**
* 监听 Widget 实例 Disable 事件
* @param listener
*/
onDisableWidget(listener: (paneName?: string, panel?: IPublicModelSkeletonItem) => void): IPublicTypeDisposable;
```

相关类型:[IPublicTypeDisposable](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/disposable.ts)

### onEnableWidget

监听 Widget 实例 Enable 事件

```typescript
/**
* 监听 Widget 实例 Enable 事件
* @param listener
*/
onEnableWidget(listener: (paneName?: string, panel?: IPublicModelSkeletonItem) => void): IPublicTypeDisposable;
```

相关类型:[IPublicTypeDisposable](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/disposable.ts)

### onShowWidget

Expand All @@ -420,7 +447,7 @@ onHidePanel(listener: (...args: any[]) => void): IPublicTypeDisposable;
* @param listener
* @returns
*/
onShowWidget(listener: (...args: any[]) => void): IPublicTypeDisposable;
onShowWidget(listener: (paneName?: string, panel?: IPublicModelSkeletonItem) => void): IPublicTypeDisposable;
```

相关类型:[IPublicTypeDisposable](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/disposable.ts)
Expand All @@ -436,7 +463,7 @@ onShowWidget(listener: (...args: any[]) => void): IPublicTypeDisposable;
* @param listener
* @returns
*/
onHideWidget(listener: (...args: any[]) => void): IPublicTypeDisposable;
onHideWidget(listener: (paneName?: string, panel?: IPublicModelSkeletonItem) => void): IPublicTypeDisposable;
```

相关类型:[IPublicTypeDisposable](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/disposable.ts)
Expand Down
34 changes: 21 additions & 13 deletions packages/shell/src/api/skeleton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,30 @@ export class Skeleton implements IPublicApiSkeleton {
* @param listener
* @returns
*/
onShowPanel(listener: (...args: any[]) => void): IPublicTypeDisposable {
onShowPanel(listener: (paneName: string, panel: IPublicModelSkeletonItem) => void): IPublicTypeDisposable {
const { editor } = this[skeletonSymbol];
editor.eventBus.on(SkeletonEvents.PANEL_SHOW, (name: any, panel: any) => {
// 不泄漏 skeleton
const { skeleton, ...restPanel } = panel;
listener(name, restPanel);
listener(name, new SkeletonItem(panel));
});
return () => editor.eventBus.off(SkeletonEvents.PANEL_SHOW, listener);
}

onDisableWidget(listener: (...args: any[]) => void): IPublicTypeDisposable {
const { editor } = this[skeletonSymbol];
editor.eventBus.on(SkeletonEvents.WIDGET_DISABLE, (name: any, panel: any) => {
listener(name, new SkeletonItem(panel));
});
return () => editor.eventBus.off(SkeletonEvents.WIDGET_DISABLE, listener);
}

onEnableWidget(listener: (...args: any[]) => void): IPublicTypeDisposable {
const { editor } = this[skeletonSymbol];
editor.eventBus.on(SkeletonEvents.WIDGET_ENABLE, (name: any, panel: any) => {
listener(name, new SkeletonItem(panel));
});
return () => editor.eventBus.off(SkeletonEvents.WIDGET_ENABLE, listener);
}

/**
* 监听 panel 隐藏事件
* @param listener
Expand All @@ -172,9 +186,7 @@ export class Skeleton implements IPublicApiSkeleton {
onHidePanel(listener: (...args: any[]) => void): IPublicTypeDisposable {
const { editor } = this[skeletonSymbol];
editor.eventBus.on(SkeletonEvents.PANEL_HIDE, (name: any, panel: any) => {
// 不泄漏 skeleton
const { skeleton, ...restPanel } = panel;
listener(name, restPanel);
listener(name, new SkeletonItem(panel));
});
return () => editor.eventBus.off(SkeletonEvents.PANEL_HIDE, listener);
}
Expand All @@ -187,9 +199,7 @@ export class Skeleton implements IPublicApiSkeleton {
onShowWidget(listener: (...args: any[]) => void): IPublicTypeDisposable {
const { editor } = this[skeletonSymbol];
editor.eventBus.on(SkeletonEvents.WIDGET_SHOW, (name: any, panel: any) => {
// 不泄漏 skeleton
const { skeleton, ...rest } = panel;
listener(name, rest);
listener(name, new SkeletonItem(panel));
});
return () => editor.eventBus.off(SkeletonEvents.WIDGET_SHOW, listener);
}
Expand All @@ -202,9 +212,7 @@ export class Skeleton implements IPublicApiSkeleton {
onHideWidget(listener: (...args: any[]) => void): IPublicTypeDisposable {
const { editor } = this[skeletonSymbol];
editor.eventBus.on(SkeletonEvents.WIDGET_HIDE, (name: any, panel: any) => {
// 不泄漏 skeleton
const { skeleton, ...rest } = panel;
listener(name, rest);
listener(name, new SkeletonItem(panel));
});
return () => editor.eventBus.off(SkeletonEvents.WIDGET_HIDE, listener);
}
Expand Down
20 changes: 16 additions & 4 deletions packages/types/src/shell/api/skeleton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,31 +95,43 @@ export interface IPublicApiSkeleton {
* @param listener
* @returns
*/
onShowPanel(listener: (...args: any[]) => void): IPublicTypeDisposable;
onShowPanel(listener: (paneName?: string, panel?: IPublicModelSkeletonItem) => void): IPublicTypeDisposable;

/**
* 监听 Panel 实例隐藏事件
* set callback for panel hidden event
* @param listener
* @returns
*/
onHidePanel(listener: (...args: any[]) => void): IPublicTypeDisposable;
onHidePanel(listener: (paneName?: string, panel?: IPublicModelSkeletonItem) => void): IPublicTypeDisposable;

/**
* 监听 Widget 实例 Disable 事件
* @param listener
*/
onDisableWidget(listener: (paneName?: string, panel?: IPublicModelSkeletonItem) => void): IPublicTypeDisposable;

/**
* 监听 Widget 实例 Enable 事件
* @param listener
*/
onEnableWidget(listener: (paneName?: string, panel?: IPublicModelSkeletonItem) => void): IPublicTypeDisposable;

/**
* 监听 Widget 显示事件
* set callback for widget shown event
* @param listener
* @returns
*/
onShowWidget(listener: (...args: any[]) => void): IPublicTypeDisposable;
onShowWidget(listener: (paneName?: string, panel?: IPublicModelSkeletonItem) => void): IPublicTypeDisposable;

/**
* 监听 Widget 隐藏事件
* set callback for widget hidden event
* @param listener
* @returns
*/
onHideWidget(listener: (...args: any[]) => void): IPublicTypeDisposable;
onHideWidget(listener: (paneName?: string, panel?: IPublicModelSkeletonItem) => void): IPublicTypeDisposable;

/**
* 注册一个面板的配置转换器(transducer)。
Expand Down

0 comments on commit e79f686

Please sign in to comment.