Skip to content

Commit a7d436a

Browse files
committed
feat: 在 skeleton 增加几个方法和事件
1 parent 770cb26 commit a7d436a

File tree

3 files changed

+91
-10
lines changed

3 files changed

+91
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"typescript": "^4.5.5"
4444
},
4545
"engines": {
46-
"node": ">=14.17.0"
46+
"node": ">=14.17.0 <16"
4747
},
4848
"tnpm": {
4949
"mode": "yarn",

packages/engine/README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,16 @@ https://cdn.jsdelivr.net/npm/@alilc/lowcode-react-simulator-renderer@1.0.0/dist/
114114
#### 方式 3:使用自有 cdn
115115
将源码中 packages/engine/dist 和 packages/(react|rax)-simulator-renderer/dist 下的文件传至你的 cdn 提供商
116116

117-
## 🔗 链接
117+
## 🔗 相关链接
118118

119-
- [官网首页 WIP](http://lowcode-engine.cn/)
120-
- [官方物料 WIP](http://lowcode-engine.cn/)
121-
- [官方设置器(setter)WIP](http://lowcode-engine.cn/)
122-
- [官方插件(plugin)WIP](http://lowcode-engine.cn/)
123-
- [用户文档 WIP](http://lowcode-engine.cn/#/doc)
124-
- [更新日志](http://lowcode-engine.cn/#/doc?url=engine-changelog)
119+
- [官网首页](http://lowcode-engine.cn/)
120+
- [Demo 马上玩](https://alifd.alicdn.com/npm/@alilc/lowcode-demo@1.0.0/build/index.html) | [引擎 Demo 仓库](https://github.com/alibaba/lowcode-demo)
121+
- [官方物料](https://github.com/alibaba/lowcode-materials)
122+
- [官方设置器(setter)](https://github.com/alibaba/lowcode-engine-ext)
123+
- [官方插件(plugin)](https://github.com/alibaba/lowcode-plugins)
124+
- [用户文档](http://lowcode-engine.cn/doc)
125+
- [API WIP](http://lowcode-engine.cn/doc?url=vlmeme)
126+
- [更新日志](http://lowcode-engine.cn/doc?url=engine-changelog)
125127

126128
## 💻 本地调试
127129

@@ -135,9 +137,9 @@ $ npm start
135137

136138
> 📢 npm 访问速度较慢,阿里员工可以使用 tnpm,其他同学建议使用 cnpm 或者指定镜像 registry。
137139
>
138-
> node 版本限制在 14
140+
> 📢 node 版本限制在 14
139141
>
140-
> windows 环境尽量使用 [WSL](https://docs.microsoft.com/zh-cn/windows/wsl/install)
142+
> 📢 windows 环境尽量使用 [WSL](https://docs.microsoft.com/zh-cn/windows/wsl/install)
141143
142144
lowcode-engine 启动后,提供了几个 umd 文件,可以结合 [lowcode-demo](https://github.com/alibaba/lowcode-demo) 项目做调试,文件代理规则参考这里。
143145

packages/shell/src/skeleton.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
Skeleton as InnerSkeleton,
33
IWidgetBaseConfig,
44
IWidgetConfigArea,
5+
SkeletonEvents,
56
} from '@alilc/lowcode-editor-skeleton';
67
import { skeletonSymbol } from './symbols';
78

@@ -58,13 +59,89 @@ export default class Skeleton {
5859
this[skeletonSymbol].getWidget(name)?.show();
5960
}
6061

62+
/**
63+
* enable widget
64+
* @param name
65+
*/
66+
enableWidget(name: string) {
67+
this[skeletonSymbol].getWidget(name)?.enable?.();
68+
}
69+
6170
/**
6271
* 隐藏 widget
6372
* @param name
6473
*/
6574
hideWidget(name: string) {
6675
this[skeletonSymbol].getWidget(name)?.hide();
6776
}
77+
78+
/**
79+
* disable widget,不可点击
80+
* @param name
81+
*/
82+
disableWidget(name: string) {
83+
this[skeletonSymbol].getWidget(name)?.disable?.();
84+
}
85+
86+
/**
87+
* 监听 panel 显示事件
88+
* @param listener
89+
* @returns
90+
*/
91+
onShowPanel(listener: (...args: unknown[]) => void) {
92+
const { editor } = this[skeletonSymbol];
93+
editor.on(SkeletonEvents.PANEL_SHOW, (name: any, panel: any) => {
94+
// 不泄漏 skeleton
95+
const { skeleton, ...restPanel } = panel;
96+
listener(name, restPanel);
97+
});
98+
return () => editor.off(SkeletonEvents.PANEL_SHOW, listener);
99+
}
100+
101+
/**
102+
* 监听 panel 隐藏事件
103+
* @param listener
104+
* @returns
105+
*/
106+
onHidePanel(listener: (...args: unknown[]) => void) {
107+
const { editor } = this[skeletonSymbol];
108+
editor.on(SkeletonEvents.PANEL_HIDE, (name: any, panel: any) => {
109+
// 不泄漏 skeleton
110+
const { skeleton, ...restPanel } = panel;
111+
listener(name, restPanel);
112+
});
113+
return () => editor.off(SkeletonEvents.PANEL_HIDE, listener);
114+
}
115+
116+
/**
117+
* 监听 widget 显示事件
118+
* @param listener
119+
* @returns
120+
*/
121+
onShowWidget(listener: (...args: unknown[]) => void) {
122+
const { editor } = this[skeletonSymbol];
123+
editor.on(SkeletonEvents.WIDGET_SHOW, (name: any, panel: any) => {
124+
// 不泄漏 skeleton
125+
const { skeleton, ...rest } = panel;
126+
listener(name, rest);
127+
});
128+
return () => editor.off(SkeletonEvents.WIDGET_SHOW, listener);
129+
}
130+
131+
/**
132+
* 监听 widget 隐藏事件
133+
* @param listener
134+
* @returns
135+
*/
136+
onHideWidget(listener: (...args: unknown[]) => void) {
137+
const { editor } = this[skeletonSymbol];
138+
editor.on(SkeletonEvents.WIDGET_HIDE, (name: any, panel: any) => {
139+
// 不泄漏 skeleton
140+
const { skeleton, ...rest } = panel;
141+
listener(name, rest);
142+
});
143+
return () => editor.off(SkeletonEvents.WIDGET_HIDE, listener);
144+
}
68145
}
69146

70147
function normalizeArea(area: IWidgetConfigArea | undefined) {
@@ -94,5 +171,7 @@ function normalizeArea(area: IWidgetConfigArea | undefined) {
94171
return 'leftFloatArea';
95172
case 'stages':
96173
return 'stages';
174+
default:
175+
throw new Error(`${area} not supported`);
97176
}
98177
}

0 commit comments

Comments
 (0)